Skip to content

Commit 6f47b5c

Browse files
Implement Daily and Unit Tests
1 parent 22dc7d0 commit 6f47b5c

File tree

96 files changed

+3272
-974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3272
-974
lines changed

.github/workflows/tests-daily.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test - Daily
2+
3+
on:
4+
workflow_dispatch:
5+
repository_dispatch:
6+
types:
7+
- manual-daily-text
8+
schedule:
9+
- cron: "0 9 * * *"
10+
11+
jobs:
12+
daily-tests:
13+
name: Daily Tests
14+
# Only run this job if we're in the main repo, not a fork.
15+
if: github.repository == 'deepgram/deepgram-python-sdk'
16+
runs-on: ubuntu-latest
17+
permissions:
18+
pull-requests: write
19+
timeout-minutes: 30
20+
steps:
21+
22+
- name: Checkout code by commit
23+
uses: actions/checkout@v4
24+
25+
- uses: actions/setup-python@v4
26+
with:
27+
python-version: '3.10'
28+
29+
- name: Config git
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
shell: bash
33+
run: |
34+
git config --global user.name "github-actions[bot]"
35+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
36+
git config --global init.defaultBranch main
37+
git config --global pull.rebase true
38+
git config --global url."https://git:[email protected]".insteadOf "https://github.com"
39+
40+
- name: Get dependencies
41+
shell: bash
42+
run: |
43+
make ensure-deps
44+
45+
- name: Install Dependencies
46+
run: |
47+
pip install --upgrade pip
48+
pip install -r requirements.txt
49+
pip install -r requirements-dev.txt
50+
pip install -e .
51+
52+
- name: Run all checks
53+
shell: bash
54+
env:
55+
DEEPGRAM_API_KEY: ${{ secrets.GH_ASR_TESTS_API_KEY_PUBLIC_R }}
56+
run: |
57+
make daily-test
58+
59+
- name: Get dependencies
60+
shell: bash
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
BRANCH_NAME="response-shape-${{ github.run_id }}"
65+
git checkout -b "$BRANCH_NAME"
66+
67+
# create a PR
68+
git add ./tests/response_data
69+
git commit -s -m "auto-generated - update Response Shapes"
70+
git push origin "$BRANCH_NAME"
71+
gh pr create --title "auto-generated - update Response Shapes" --body "auto-generated - update Response Shapes" --base "main" --head "$BRANCH_NAME"
72+
sleep 10
73+
gh pr merge "$BRANCH_NAME" --delete-branch --squash --admin

.github/workflows/tests-daily.yaml.DISABLE

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/tests-unit.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test - Unit
2+
3+
on:
4+
pull_request:
5+
types:
6+
- assigned
7+
- opened
8+
- synchronize
9+
- reopened
10+
jobs:
11+
build:
12+
name: Unit Tests
13+
# Only run this job if we're in the main repo, not a fork.
14+
if: github.repository == 'deepgram/deepgram-python-sdk'
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 5
17+
steps:
18+
19+
- name: Checkout code by commit
20+
uses: actions/checkout@v4
21+
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.10'
25+
26+
- name: Install Dependencies
27+
run: |
28+
pip install --upgrade pip
29+
pip install -r requirements.txt
30+
pip install -r requirements-dev.txt
31+
pip install -e .
32+
33+
- name: Run all checks
34+
shell: bash
35+
env:
36+
DEEPGRAM_API_KEY: ${{ secrets.GH_ASR_TESTS_API_KEY_PUBLIC_R }}
37+
run: |
38+
make unit-test

.github/workflows/tests-unit.yaml.DISABLE

Lines changed: 0 additions & 47 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ venv.bak/
1212
__pycache__
1313
*.egg-info
1414
dist/
15+
.mypy_cache/
16+
.pytest_cache/
1517

1618
# build
1719
build/

Makefile

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ version: #### display version of components
3434
@echo 'GOARCH: $(GOARCH)'
3535
@echo 'go version: $(shell go version)'
3636

37-
.PHONY: check lint pylint format black blackformat lint_files lint_diff static mypy mdlint shellcheck actionlint yamllint ### Performs all of the checks, lint'ing, etc available
37+
.PHONY: check lint pylint format black blackformat lint-files lint-diff static mypy mdlint shellcheck actionlint yamllint ### Performs all of the checks, lint'ing, etc available
3838
check: lint static mdlint shellcheck actionlint yamllint
3939

4040
.PHONY: ensure-deps
@@ -44,22 +44,21 @@ ensure-deps: #### Ensure that all required dependency utilities are downloaded o
4444
GO_MODULES=$(shell find . -path "*/go.mod" | xargs -I _ dirname _)
4545

4646
PYTHON_FILES=.
47-
lint_files: PYTHON_FILES=deepgram/ examples/
48-
lint_diff: PYTHON_FILES=$(shell git diff --name-only --diff-filter=d main | grep -E '\.py$$')
47+
lint-files: PYTHON_FILES=deepgram/ examples/
48+
lint-diff: PYTHON_FILES=$(shell git diff --name-only --diff-filter=d main | grep -E '\.py$$')
4949

50-
lint_files lint_diff: #### Performs Python formatting
50+
lint-files lint-diff: #### Performs Python formatting
5151
black --target-version py310 $(PYTHON_FILES)
5252

53-
black blackformat format: lint_files
53+
black blackformat format: lint-files
5454

55-
pylint: lint_files #### Performs Python linting
55+
pylint: lint-files #### Performs Python linting
5656
pylint --disable=W0622 --disable=W0404 --disable=W0611 --rcfile .pylintrc deepgram
5757

5858
lint: pylint #### Performs Golang programming lint
5959

60-
static_files: PYTHON_FILES=deepgram/
6160
static mypy: #### Performs static analysis
62-
mypy --config-file mypy.ini --python-version 3.10 --exclude examples --exclude tests/edge_cases --exclude tests/expected_failures $(PYTHON_FILES)
61+
mypy --config-file mypy.ini --python-version 3.10 --exclude tests --exclude examples $(PYTHON_FILES)
6362

6463
mdlint: #### Performs Markdown lint
6564
# mdlint rules with common errors and possible fixes can be found here:
@@ -75,3 +74,19 @@ yamllint: #### Performs yaml lint
7574
actionlint: #### Performs GitHub Actions lint
7675
actionlint
7776
##### LINTING TARGETS
77+
78+
##### TESTING TARGETS
79+
80+
.PHONY: test daily-test unit-test
81+
test: #### Run ALL tests
82+
@echo "Running ALL tests"
83+
python -m pytest
84+
85+
daily-test: #### Run daily tests
86+
@echo "Running daily tests"
87+
python -m pytest -k daily_test
88+
89+
unit-test: #### Run unit tests
90+
@echo "Running unit tests"
91+
python -m pytest -k unit_test
92+
##### TESTING TARGETS

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,32 @@ pip install -r requirements.txt
254254
pip install -e .
255255
```
256256

257-
### Testing
257+
### Daily and Unit Tests
258258

259-
If you are looking to contribute or modify pytest code, then you need to install the following dependencies:
259+
If you are looking to use, run, contribute or modify to the daily/unit tests, then you need to install the following dependencies:
260260

261261
```bash
262262
pip install -r requirements-dev.txt
263263
```
264264

265+
#### Daily Tests
266+
267+
The daily tests invoke a series of checks against the actual/real API endpoint and save the results in the `tests/response_data` folder. This response data is updated nightly to reflect the latest response from the server. Running the daily tests does require a `DEEPGRAM_API_KEY` set in your environment variables.
268+
269+
To run the Daily Tests:
270+
271+
```bash
272+
make daily-test
273+
```
274+
275+
#### Unit Tests
276+
277+
The unit tests invoke a series of checks against mock endpoints using the responses saved in `tests/response_data` from the daily tests. These tests are meant to simulate running against the endpoint without actually reaching out to the endpoint; running the unit tests does require a `DEEPGRAM_API_KEY` set in your environment variables, but you will not actually reach out to the server.
278+
279+
```bash
280+
make unit-test
281+
```
282+
265283
## Getting Help
266284

267285
We love to hear from you so if you have questions, comments or find a bug in the

deepgram/clients/abstract_async_client.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ async def _handle_request(
217217
timeout = httpx.Timeout(30.0, connect=10.0)
218218

219219
try:
220-
async with httpx.AsyncClient(timeout=timeout) as client:
220+
transport = kwargs.get("transport")
221+
async with httpx.AsyncClient(
222+
timeout=timeout, transport=transport
223+
) as client:
224+
if transport:
225+
kwargs.pop("transport")
221226
response = await client.request(
222227
method, _url, headers=_headers, **kwargs
223228
)
@@ -269,7 +274,12 @@ async def _handle_request_memory(
269274
timeout = httpx.Timeout(30.0, connect=10.0)
270275

271276
try:
272-
async with httpx.AsyncClient(timeout=timeout) as client:
277+
transport = kwargs.get("transport")
278+
async with httpx.AsyncClient(
279+
timeout=timeout, transport=transport
280+
) as client:
281+
if transport:
282+
kwargs.pop("transport")
273283
response = await client.request(
274284
method, _url, headers=_headers, **kwargs
275285
)
@@ -334,7 +344,11 @@ async def _handle_request_raw(
334344
timeout = httpx.Timeout(30.0, connect=10.0)
335345

336346
try:
337-
client = httpx.AsyncClient(timeout=timeout)
347+
transport = kwargs.get("transport")
348+
client = httpx.AsyncClient(timeout=timeout, transport=transport)
349+
if transport:
350+
kwargs.pop("transport")
351+
kwargs.pop("transport")
338352
req = client.build_request(method, _url, headers=_headers, **kwargs)
339353
return await client.send(req, stream=True)
340354

deepgram/clients/abstract_sync_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ def _handle_request(
217217
timeout = httpx.Timeout(30.0, connect=10.0)
218218

219219
try:
220-
with httpx.Client(timeout=timeout) as client:
220+
transport = kwargs.get("transport")
221+
with httpx.Client(timeout=timeout, transport=transport) as client:
222+
if transport:
223+
kwargs.pop("transport")
221224
response = client.request(method, _url, headers=_headers, **kwargs)
222225
response.raise_for_status()
223226
return response.text
@@ -267,7 +270,10 @@ def _handle_request_memory(
267270
timeout = httpx.Timeout(30.0, connect=10.0)
268271

269272
try:
270-
with httpx.Client(timeout=timeout) as client:
273+
transport = kwargs.get("transport")
274+
with httpx.Client(timeout=timeout, transport=transport) as client:
275+
if transport:
276+
kwargs.pop("transport")
271277
response = client.request(method, _url, headers=_headers, **kwargs)
272278
response.raise_for_status()
273279

@@ -330,7 +336,10 @@ def _handle_request_raw(
330336
timeout = httpx.Timeout(30.0, connect=10.0)
331337

332338
try:
333-
client = httpx.Client(timeout=timeout)
339+
transport = kwargs.get("transport")
340+
with httpx.Client(timeout=timeout, transport=transport) as client:
341+
if transport:
342+
kwargs.pop("transport")
334343
req = client.build_request(method, _url, headers=_headers, **kwargs)
335344
return client.send(req, stream=True)
336345

0 commit comments

Comments
 (0)