From 93fac0e5eca45da093380978ee2769dfa31a8af3 Mon Sep 17 00:00:00 2001 From: MatthewPyle-NOAA <48285220+MatthewPyle-NOAA@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:15:14 -0400 Subject: [PATCH] Adds #478 changes from dev-sci (#479) but have a question about the location of the .toml file. --- .github/workflows/pytest_flake8.yml | 7 +++++-- pyproject.toml | 5 +++++ tests/ush/python_utils/test_misc.py | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml create mode 100644 tests/ush/python_utils/test_misc.py diff --git a/.github/workflows/pytest_flake8.yml b/.github/workflows/pytest_flake8.yml index 5d6636dfb..d754f7a4d 100644 --- a/.github/workflows/pytest_flake8.yml +++ b/.github/workflows/pytest_flake8.yml @@ -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 --show-source --statistics + 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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..296c45fa3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[tool.pytest.ini_options] +addopts = "-ra --cov" +testpaths = ['tests'] +pythonpath = ['.'] + diff --git a/tests/ush/python_utils/test_misc.py b/tests/ush/python_utils/test_misc.py new file mode 100644 index 000000000..338a3df0b --- /dev/null +++ b/tests/ush/python_utils/test_misc.py @@ -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") +