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 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 92% rename from tests/test_io.py rename to tests/io_test.py index 44ed3a5a..3688b83c 100644 --- a/tests/test_io.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(): 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/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 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