From 6661254da58aa203fa9b72f03a2f86b33092d4df Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 10 Dec 2024 12:54:01 -0700 Subject: [PATCH 1/4] rename tests with _test suffix --- tests/{test_cube.py => cube_test.py} | 0 tests/{test_io.py => io_test.py} | 0 tests/{test_mask.py => mask_test.py} | 0 tests/{test_mobility.py => mobility_test.py} | 0 tests/{test_plan.py => plan_test.py} | 0 tests/{test_plot.py => plot_test.py} | 0 tests/{test_section.py => section_test.py} | 0 tests/{test_strat.py => strat_test.py} | 0 tests/{test_utils.py => utils_test.py} | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename tests/{test_cube.py => cube_test.py} (100%) rename tests/{test_io.py => io_test.py} (100%) rename tests/{test_mask.py => mask_test.py} (100%) rename tests/{test_mobility.py => mobility_test.py} (100%) rename tests/{test_plan.py => plan_test.py} (100%) rename tests/{test_plot.py => plot_test.py} (100%) rename tests/{test_section.py => section_test.py} (100%) rename tests/{test_strat.py => strat_test.py} (100%) rename tests/{test_utils.py => utils_test.py} (100%) diff --git a/tests/test_cube.py b/tests/cube_test.py similarity index 100% rename from tests/test_cube.py rename to tests/cube_test.py diff --git a/tests/test_io.py b/tests/io_test.py similarity index 100% rename from tests/test_io.py rename to tests/io_test.py diff --git a/tests/test_mask.py b/tests/mask_test.py similarity index 100% rename from tests/test_mask.py rename to tests/mask_test.py diff --git a/tests/test_mobility.py b/tests/mobility_test.py similarity index 100% rename from tests/test_mobility.py rename to tests/mobility_test.py diff --git a/tests/test_plan.py b/tests/plan_test.py similarity index 100% rename from tests/test_plan.py rename to tests/plan_test.py diff --git a/tests/test_plot.py b/tests/plot_test.py similarity index 100% rename from tests/test_plot.py rename to tests/plot_test.py diff --git a/tests/test_section.py b/tests/section_test.py similarity index 100% rename from tests/test_section.py rename to tests/section_test.py diff --git a/tests/test_strat.py b/tests/strat_test.py similarity index 100% rename from tests/test_strat.py rename to tests/strat_test.py diff --git a/tests/test_utils.py b/tests/utils_test.py similarity index 100% rename from tests/test_utils.py rename to tests/utils_test.py From 512b39de2941fb0b540f286998cc70a1f784e657 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Wed, 11 Dec 2024 10:06:28 -0700 Subject: [PATCH 2/4] remove the testing utilities module --- tests/utilities.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 tests/utilities.py diff --git a/tests/utilities.py b/tests/utilities.py deleted file mode 100644 index 4059427b..00000000 --- a/tests/utilities.py +++ /dev/null @@ -1,28 +0,0 @@ -import netCDF4 - - -def create_dummy_netcdf(tmp_path): - """Create blank NetCDF4 file.""" - d = tmp_path / 'netcdf_files' - try: - d.mkdir() - except Exception: - pass - p = d / 'dummy.nc' - f = netCDF4.Dataset(p, "w", format="NETCDF4") - f.createVariable('test', 'f4') - f.close() - return p - - -def create_dummy_txt_file(tmp_path): - """Create a dummy text file.""" - d = tmp_path / 'txt_files' - try: - d.mkdir() - except Exception: - pass - p = d / 'dummy.txt' - _fobj = open(p, 'x') - _fobj.close() - return p From de6a6666f97554c736916ab9a56164fce5d0de7f Mon Sep 17 00:00:00 2001 From: mcflugen Date: Wed, 11 Dec 2024 10:06:52 -0700 Subject: [PATCH 3/4] rewrite the testing utilities as pytest fixtures --- tests/io_test.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/io_test.py b/tests/io_test.py index 44ed3a5a..3688b83c 100644 --- a/tests/io_test.py +++ b/tests/io_test.py @@ -1,8 +1,8 @@ import sys +import netCDF4 import numpy as np import pytest -import utilities import xarray as xr from deltametrics.io import DictionaryIO @@ -17,6 +17,24 @@ hdf_path = _get_landsat_path() +@pytest.fixture +def empty_netcdf_file(tmp_path): + """Create blank NetCDF4 file.""" + p = tmp_path / "dummy.nc" + f = netCDF4.Dataset(p, "w", format="NETCDF4") + f.createVariable("test", "f4") + f.close() + return p + + +@pytest.fixture +def empty_txt_file(tmp_path): + """Create a dummy text file.""" + p = tmp_path / "dummy.txt" + p.touch() + return p + + def test_netcdf_io_init(): netcdf_io = NetCDFIO(golf_path, 'netcdf') assert netcdf_io.io_type == 'netcdf' @@ -115,16 +133,16 @@ def test_nofile(): NetCDFIO('badpath', 'netcdf') -def test_empty_file(tmp_path): - p = utilities.create_dummy_netcdf(tmp_path) +def test_empty_file(empty_netcdf_file): + assert empty_netcdf_file.is_file() with pytest.raises(NotImplementedError): - NetCDFIO(p, 'netcdf') + NetCDFIO(empty_netcdf_file, 'netcdf') -def test_invalid_file(tmp_path): - p = utilities.create_dummy_txt_file(tmp_path) +def test_invalid_file(empty_txt_file): + assert empty_txt_file.is_file() with pytest.raises(TypeError): - NetCDFIO(p, 'netcdf') + NetCDFIO(empty_txt_file, 'netcdf') def test_readvar_intomemory(): From ccebacd7cd5711f5a89ab9840a545031a7bb4298 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 17 Dec 2024 11:58:21 -0700 Subject: [PATCH 4/4] turn on name-tests-test --- noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/noxfile.py b/noxfile.py index 9d320064..c26fed44 100644 --- a/noxfile.py +++ b/noxfile.py @@ -62,6 +62,7 @@ def lint(session: nox.Session) -> None: session.run("pre-commit", "run", "--all-files", "end-of-file-fixer") session.run("pre-commit", "run", "--all-files", "pyupgrade") session.run("pre-commit", "run", "--all-files", "flake8") + session.run("pre-commit", "run", "--all-files", "name-tests-test") @nox.session