Skip to content

Commit

Permalink
Merge pull request #189 from mcflugen/mcflugen/rename-tests
Browse files Browse the repository at this point in the history
Rename test files with _test suffix and add pytest fixtures
  • Loading branch information
mcflugen authored Dec 17, 2024
2 parents d69f475 + ccebacd commit 574153c
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 35 deletions.
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
32 changes: 25 additions & 7 deletions tests/test_io.py → tests/io_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 0 additions & 28 deletions tests/utilities.py

This file was deleted.

File renamed without changes.

0 comments on commit 574153c

Please sign in to comment.