Skip to content

Commit 7d016ed

Browse files
authored
Add unit testing and example (#29)
* push initial unit testing workflow * config example unit testing
1 parent 32c9490 commit 7d016ed

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Python Package using Conda
2+
3+
on: [push]
4+
5+
jobs:
6+
build-linux:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
max-parallel: 5
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python 3.10
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: '3.10'
17+
- name: Add conda to system path
18+
run: |
19+
# $CONDA is an environment variable pointing to the root of the miniconda directory
20+
echo $CONDA/bin >> $GITHUB_PATH
21+
- name: Install current library and dependencies
22+
run: |
23+
pip install -e .
24+
# - name: Lint with flake8
25+
# run: |
26+
# conda install flake8
27+
# # stop the build if there are Python syntax errors or undefined names
28+
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
29+
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
30+
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
31+
- name: Test with pytest
32+
run: |
33+
conda install pytest
34+
pytest

pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# content of pytest.ini
2+
[pytest]
3+
python_files = *_test.py
4+
python_classes = *Test
5+
python_functions = test_* *_test
6+
testpaths = tests

tests/compartment_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import pathlib
3+
import sys
4+
5+
# NOTE: VN: Since we have installed using `pip install -e .` in the workflow file, we
6+
# might not need to manually add to the path
7+
sys.path.append(str(pathlib.Path(__file__).parent.parent))
8+
9+
# import ngcsimlib
10+
11+
class CompartmentTest:
12+
13+
def test_import(self):
14+
success = False
15+
try:
16+
from ngcsimlib.compartment import Compartment
17+
success = True
18+
except:
19+
success = False
20+
assert success, "Import failed!"
21+
22+

0 commit comments

Comments
 (0)