Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Daily and Unit Tests #443

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/tests-daily.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Test - Daily

on:
workflow_dispatch:
repository_dispatch:
types:
- manual-daily-text
schedule:
- cron: "0 9 * * *"

jobs:
daily-tests:
name: Daily Tests
# Only run this job if we're in the main repo, not a fork.
if: github.repository == 'deepgram/deepgram-python-sdk'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
timeout-minutes: 30
steps:

- name: Checkout code by commit
uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Config git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global url."https://git:[email protected]".insteadOf "https://github.com"

- name: Get dependencies
shell: bash
run: |
make ensure-deps

- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .

- name: Run all checks
shell: bash
env:
DEEPGRAM_API_KEY: ${{ secrets.GH_ASR_TESTS_API_KEY_PUBLIC_R }}
run: |
make daily-test

- name: Get dependencies
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="response-shape-${{ github.run_id }}"
git checkout -b "$BRANCH_NAME"

# create a PR
git add ./tests/response_data
git commit -s -m "auto-generated - update Response Shapes"
git push origin "$BRANCH_NAME"
gh pr create --title "auto-generated - update Response Shapes" --body "auto-generated - update Response Shapes" --base "main" --head "$BRANCH_NAME"
sleep 10
gh pr merge "$BRANCH_NAME" --delete-branch --squash --admin
57 changes: 0 additions & 57 deletions .github/workflows/tests-daily.yaml.DISABLE

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/tests-unit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test - Unit

on:
pull_request:
types:
- assigned
- opened
- synchronize
- reopened
jobs:
build:
name: Unit Tests
# Only run this job if we're in the main repo, not a fork.
if: github.repository == 'deepgram/deepgram-python-sdk'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:

- name: Checkout code by commit
uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .

- name: Run all checks
shell: bash
env:
DEEPGRAM_API_KEY: ${{ secrets.GH_ASR_TESTS_API_KEY_PUBLIC_R }}
run: |
make unit-test
47 changes: 0 additions & 47 deletions .github/workflows/tests-unit.yaml.DISABLE

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ venv.bak/
__pycache__
*.egg-info
dist/
.mypy_cache/
.pytest_cache/

# build
build/
Expand Down
31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ version: #### display version of components
@echo 'GOARCH: $(GOARCH)'
@echo 'go version: $(shell go version)'

.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
.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
check: lint static mdlint shellcheck actionlint yamllint

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

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

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

black blackformat format: lint_files
black blackformat format: lint-files

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

lint: pylint #### Performs Golang programming lint

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

mdlint: #### Performs Markdown lint
# mdlint rules with common errors and possible fixes can be found here:
Expand All @@ -75,3 +74,19 @@ yamllint: #### Performs yaml lint
actionlint: #### Performs GitHub Actions lint
actionlint
##### LINTING TARGETS

##### TESTING TARGETS

.PHONY: test daily-test unit-test
test: #### Run ALL tests
@echo "Running ALL tests"
python -m pytest

daily-test: #### Run daily tests
@echo "Running daily tests"
python -m pytest -k daily_test

unit-test: #### Run unit tests
@echo "Running unit tests"
python -m pytest -k unit_test
##### TESTING TARGETS
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,32 @@ pip install -r requirements.txt
pip install -e .
```

### Testing
### Daily and Unit Tests

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

```bash
pip install -r requirements-dev.txt
```

#### Daily Tests

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.

To run the Daily Tests:

```bash
make daily-test
```

#### Unit Tests

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.

```bash
make unit-test
```

## Getting Help

We love to hear from you so if you have questions, comments or find a bug in the
Expand Down
20 changes: 17 additions & 3 deletions deepgram/clients/abstract_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ async def _handle_request(
timeout = httpx.Timeout(30.0, connect=10.0)

try:
async with httpx.AsyncClient(timeout=timeout) as client:
transport = kwargs.get("transport")
async with httpx.AsyncClient(
timeout=timeout, transport=transport
) as client:
if transport:
kwargs.pop("transport")
response = await client.request(
method, _url, headers=_headers, **kwargs
)
Expand Down Expand Up @@ -269,7 +274,12 @@ async def _handle_request_memory(
timeout = httpx.Timeout(30.0, connect=10.0)

try:
async with httpx.AsyncClient(timeout=timeout) as client:
transport = kwargs.get("transport")
async with httpx.AsyncClient(
timeout=timeout, transport=transport
) as client:
if transport:
kwargs.pop("transport")
response = await client.request(
method, _url, headers=_headers, **kwargs
)
Expand Down Expand Up @@ -334,7 +344,11 @@ async def _handle_request_raw(
timeout = httpx.Timeout(30.0, connect=10.0)

try:
client = httpx.AsyncClient(timeout=timeout)
transport = kwargs.get("transport")
client = httpx.AsyncClient(timeout=timeout, transport=transport)
if transport:
kwargs.pop("transport")
kwargs.pop("transport")
req = client.build_request(method, _url, headers=_headers, **kwargs)
return await client.send(req, stream=True)

Expand Down
15 changes: 12 additions & 3 deletions deepgram/clients/abstract_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ def _handle_request(
timeout = httpx.Timeout(30.0, connect=10.0)

try:
with httpx.Client(timeout=timeout) as client:
transport = kwargs.get("transport")
with httpx.Client(timeout=timeout, transport=transport) as client:
if transport:
kwargs.pop("transport")
response = client.request(method, _url, headers=_headers, **kwargs)
response.raise_for_status()
return response.text
Expand Down Expand Up @@ -267,7 +270,10 @@ def _handle_request_memory(
timeout = httpx.Timeout(30.0, connect=10.0)

try:
with httpx.Client(timeout=timeout) as client:
transport = kwargs.get("transport")
with httpx.Client(timeout=timeout, transport=transport) as client:
if transport:
kwargs.pop("transport")
response = client.request(method, _url, headers=_headers, **kwargs)
response.raise_for_status()

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

try:
client = httpx.Client(timeout=timeout)
transport = kwargs.get("transport")
with httpx.Client(timeout=timeout, transport=transport) as client:
if transport:
kwargs.pop("transport")
req = client.build_request(method, _url, headers=_headers, **kwargs)
return client.send(req, stream=True)

Expand Down
Loading
Loading