Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion modflow_devtools/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def use_pandas(request):
raise ValueError(f"Unsupported value for --pandas: {pandas}")


@pytest.fixture
def tabular(request):
tab = request.config.option.TABULAR
if tab not in ["raw", "recarray", "dataframe"]:
raise ValueError(f"Unsupported value for --tabular: {tab}")
return tab


# configuration hooks


Expand Down Expand Up @@ -163,7 +171,16 @@ def pytest_addoption(parser):
action="store",
default="yes",
dest="PANDAS",
help="Package input data can be provided as either pandas dataframes or numpy recarrays. By default, pandas dataframes are used. To test with numpy recarrays, use 'no'. To randomize selection (per test), use 'random'.",
help="Indicates whether to use pandas, where multiple approaches are available. Select 'yes', 'no', or 'random'.",
)

parser.addoption(
"-T",
"--tabular",
action="store",
default="raw",
dest="TABULAR",
help="Configure tabular data representation for model input. Select 'raw', 'recarray', or 'dataframe'.",
)


Expand Down
31 changes: 31 additions & 0 deletions modflow_devtools/test/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,34 @@ def test_pandas(pandas, arg, function_tmpdir):
assert "True" in res
elif pandas == "no":
assert "False" in res


test_tabular_fname = "tabular.txt"


@pytest.mark.meta("test_tabular")
def test_tabular_inner(function_tmpdir, tabular):
with open(function_tmpdir / test_tabular_fname, "w") as f:
f.write(str(tabular))


@pytest.mark.parametrize("tabular", ["raw", "recarray", "dataframe"])
@pytest.mark.parametrize("arg", ["--tabular", "-T"])
def test_tabular(tabular, arg, function_tmpdir):
inner_fn = test_tabular_inner.__name__
args = [
__file__,
"-v",
"-s",
"-k",
inner_fn,
arg,
tabular,
"--keep",
function_tmpdir,
"-M",
"test_tabular",
]
assert pytest.main(args) == ExitCode.OK
res = open(next(function_tmpdir.rglob(test_tabular_fname))).readlines()[0]
assert tabular == res