Skip to content

Commit

Permalink
first python test! (#478)
Browse files Browse the repository at this point in the history
* running pytest
* adding test_misc.py
* adding jinja2
* adding pyproject.toml file
  • Loading branch information
edwardhartnett authored Sep 10, 2024
1 parent c71f21a commit c32d9f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/pytest_flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov coverage numpy netCDF4
pip install flake8 pytest pytest-cov coverage numpy netCDF4 jinja2
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors
flake8 . --count --select=E9,F63,F7 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
#flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: pytest
run: |
pytest
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.pytest.ini_options]
addopts = "-ra --cov"
testpaths = ['tests']
pythonpath = ['.']

25 changes: 25 additions & 0 deletions tests/ush/python_utils/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

from ush.python_utils.misc import *

class TestMisc:
"""Test the misc.py functions."""

def test_uc(self):
"""Test the uppercase() function."""
assert uppercase('s') == 'S'

def test_lc(self):
"""Test the lowercase() function."""
assert lowercase('S') == 's'

def test_find_pattern_in_str(self):
"""Test the find_pattern_in_str() function."""
assert not find_pattern_in_str('.', 's')

def test_find_pattern_in_fike(self):
"""Test the find_pattern_in_file() function."""
f = open("test_misc.txt", "w")
f.write("Hello World from " + f.name)
f.close()
assert not find_pattern_in_file('H', "test_misc.txt")

0 comments on commit c32d9f8

Please sign in to comment.