Skip to content

Commit

Permalink
Merge pull request #125 from palewire/pytest
Browse files Browse the repository at this point in the history
Switch to using `pytest` for unit testing
  • Loading branch information
palewire authored Sep 1, 2024
2 parents 5c7226f + f7788be commit 0ddf601
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 271 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ jobs:

- id: install-python-dependencies
name: Install Python dependencies
run: pip install requests click python-dateutil pandas
run: pip install requests click python-dateutil pandas pytest pytest-cov pytest-xdist

- id: download-data
name: Download data
run: python -c 'import cpi'

- id: tests
name: Run tests
run: python tests.py
run: pytest -n auto --cov=cpi --cov-report term-missing tests

- id: update
name: Update data
Expand All @@ -96,15 +96,15 @@ jobs:
name: Install Python dependencies
run: |
$CONDA/bin/conda create -n cpi python=${{ matrix.python }}
$CONDA/bin/conda install -n cpi requests click python-dateutil pandas
$CONDA/bin/conda install -n cpi requests click python-dateutil pandas pytest pytest-cov pytest-xdist
- id: download-data
name: Download data
run: $CONDA/bin/conda run -n cpi python -c 'import cpi'

- id: tests
name: Run tests
run: $CONDA/bin/conda run -n cpi python tests.py
run: $CONDA/bin/conda run -n cpi pytest -n auto --cov=cpi --cov-report term-missing tests

- id: update
name: Update data
Expand All @@ -113,7 +113,7 @@ jobs:
test-build:
name: Build Python package
runs-on: ubuntu-latest
needs: [test-python, test-conda]
needs: [test-python, test-conda, lint-python, mypy-python]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -123,28 +123,28 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pipenv'

- name: Install pipenv
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python

- id: install-python-dependencies
name: Install Python dependencies
run: pipenv install --dev --python `which python`
run: pip install requests click python-dateutil pandas twine setuptools-scm wheel
shell: bash

- id: create-db
name: Create database
run: python -c 'import cpi'
shell: bash

- id: build
name: Build release
run: |
pipenv run python -c 'import cpi'
pipenv run python setup.py sdist
pipenv run python setup.py bdist_wheel
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
shell: bash

- id: check
name: Check release
run: pipenv run twine check dist/*
run: twine check dist/*
shell: bash

- id: save
Expand Down
4 changes: 4 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ requests = "*"
click = "*"
python-dateutil = "*"
pandas = "*"
numpy = "*"

[dev-packages]
jupyterlab = "*"
Expand All @@ -20,6 +21,9 @@ sphinx = "*"
sphinx-autobuild = "*"
sphinx-palewire-theme = "*"
myst-parser = "*"
pytest = "*"
pytest-cov = "*"
pytest-xdist = "*"

[requires]
python_version = "3.11"
137 changes: 135 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cpi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def query(sql: str, params: list | tuple | None = None) -> list[dict]:
return result_list


def queryone(sql: str, params: list | tuple) -> dict:
def queryone(sql: str, params: list | tuple | None = None) -> dict:
"""Query the cpi.db database and return a single result.
Args:
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
Loading

0 comments on commit 0ddf601

Please sign in to comment.