Skip to content

Commit

Permalink
Clean up test data folders (#399)
Browse files Browse the repository at this point in the history
* Clean up test data folders

* Make ruff

* Rename IO folder to lowercase

* Update tests
  • Loading branch information
phackstock authored Sep 24, 2024
1 parent d2b0cb7 commit 9314fef
Show file tree
Hide file tree
Showing 114 changed files with 179 additions and 118 deletions.
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@

@pytest.fixture(scope="session")
def simple_definition():
yield DataStructureDefinition(TEST_DATA_DIR / "validation_nc")
yield DataStructureDefinition(
TEST_DATA_DIR / "data_structure_definition" / "validation_nc"
)


@pytest.fixture(scope="session")
def extras_definition():
yield DataStructureDefinition(TEST_DATA_DIR / "extras_nc")
yield DataStructureDefinition(
TEST_DATA_DIR / "data_structure_definition" / "extras_nc"
)


@pytest.fixture(scope="function")
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 44 additions & 19 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from conftest import TEST_DATA_DIR

MODULE_TEST_DATA_DIR = TEST_DATA_DIR / "cli"

runner = CliRunner()


Expand Down Expand Up @@ -54,20 +56,24 @@ def test_cli_valid_yaml():
"""Check that CLI runs through, when all yaml files in `path`
can be parsed without errors"""
result_valid = runner.invoke(
cli, ["validate-yaml", str(TEST_DATA_DIR / "duplicate_code_raises")]
cli,
[
"validate-yaml",
str(TEST_DATA_DIR / "codelist" / "duplicate_code_raises"),
],
)
assert result_valid.exit_code == 0


def test_cli_valid_yaml_fails():
"""Check that CLI raises expected error when parsing an invalid yaml"""
result_invalid = runner.invoke(
cli, ["validate-yaml", str(TEST_DATA_DIR / "invalid_yaml")]
cli, ["validate-yaml", str(MODULE_TEST_DATA_DIR / "invalid_yaml")]
)
assert result_invalid.exit_code == 1
match = "Parsing the yaml files failed. Please check the log for details."
with pytest.raises(AssertionError, match=match):
assert_valid_yaml(TEST_DATA_DIR / "invalid_yaml")
assert_valid_yaml(MODULE_TEST_DATA_DIR / "invalid_yaml")


def test_cli_valid_project_path():
Expand All @@ -81,15 +87,25 @@ def test_cli_valid_project():
"""Check that CLI runs through with existing "definitions" and "mappings"
directory"""
result_valid = runner.invoke(
cli, ["validate-project", str(TEST_DATA_DIR / "structure_validation")]
cli,
[
"validate-project",
str(
MODULE_TEST_DATA_DIR / "structure_validation",
),
],
)
assert result_valid.exit_code == 0


def test_cli_invalid_region():
"""Test that errors are correctly propagated"""
obs = runner.invoke(
cli, ["validate-project", str(TEST_DATA_DIR / "structure_validation_fails")]
cli,
[
"validate-project",
str(MODULE_TEST_DATA_DIR / "structure_validation_fails"),
],
)
assert obs.exit_code == 1
assert isinstance(obs.exception, pydantic.ValidationError)
Expand All @@ -100,7 +116,7 @@ def test_cli_valid_project_fails():
"""Check that CLI expected error when "definitions" directory doesn't exist"""
path = TEST_DATA_DIR / "invalid_yaml" / "definitions"
result_invalid = runner.invoke(
cli, ["validate-project", str(TEST_DATA_DIR / "invalid_yaml")]
cli, ["validate-project", str(MODULE_TEST_DATA_DIR / "invalid_yaml")]
)
assert result_invalid.exit_code == 1

Expand All @@ -109,7 +125,7 @@ def print_helper(_path):

with pytest.raises(NotADirectoryError, match=print_helper(path)):
assert_valid_structure(
TEST_DATA_DIR / "invalid_yaml", "mappings", "definitions"
MODULE_TEST_DATA_DIR / "invalid_yaml", "mappings", "definitions"
)


Expand All @@ -120,7 +136,7 @@ def test_cli_non_default_folders():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "non-default_folders"),
str(MODULE_TEST_DATA_DIR / "non-default_folders"),
"--definitions",
"def",
"--mappings",
Expand All @@ -134,7 +150,13 @@ def test_cli_non_default_folders_fails():
"""Check that CLI raises expected error when non-default "definitions" and
"mappings" directory names are not given"""
result_valid = runner.invoke(
cli, ["validate-project", str(TEST_DATA_DIR / "non-default_folders")]
cli,
[
"validate-project",
str(
MODULE_TEST_DATA_DIR / "non-default_folders",
),
],
)
assert result_valid.exit_code == 1

Expand All @@ -146,7 +168,7 @@ def test_cli_wrong_definitions_name():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "structure_validation"),
str(MODULE_TEST_DATA_DIR / "structure_validation"),
"--definitions",
"def",
],
Expand All @@ -161,7 +183,7 @@ def test_cli_custom_dimensions_runs():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "non-default_dimensions"),
str(MODULE_TEST_DATA_DIR / "non-default_dimensions"),
"--dimension",
"variable",
"--dimension",
Expand All @@ -181,7 +203,7 @@ def test_cli_custom_dimensions_fails():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "non-default_dimensions"),
str(MODULE_TEST_DATA_DIR / "non-default_dimensions"),
"--dimension",
"foo",
],
Expand All @@ -199,7 +221,7 @@ def test_cli_empty_dimensions_run():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "non-default_dimensions_one_empty"),
str(MODULE_TEST_DATA_DIR / "non-default_dimensions_one_empty"),
"--dimension",
"variable",
"--dimension",
Expand All @@ -214,7 +236,10 @@ def test_cli_empty_dimensions_fails():

result_invalid = runner.invoke(
cli,
["validate-project", str(TEST_DATA_DIR / "non-default_dimensions_one_empty")],
[
"validate-project",
str(MODULE_TEST_DATA_DIR / "non-default_dimensions_one_empty"),
],
)
assert result_invalid.exit_code == 1
assert isinstance(result_invalid.exception, ValueError)
Expand All @@ -230,7 +255,7 @@ def test_cli_missing_mappings_runs():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "structure_validation_no_mappings"),
str(MODULE_TEST_DATA_DIR / "structure_validation_no_mappings"),
],
).exit_code
== 0
Expand All @@ -244,7 +269,7 @@ def test_cli_missing_mappings_fails():
cli,
[
"validate-project",
str(TEST_DATA_DIR / "structure_validation_no_mappings"),
str(MODULE_TEST_DATA_DIR / "structure_validation_no_mappings"),
"--mappings",
"mappings",
],
Expand Down Expand Up @@ -276,7 +301,7 @@ def test_cli_empty_definitions_dir():

cli_result = runner.invoke(
cli,
["validate-project", str(TEST_DATA_DIR / "empty_definitions_dir")],
["validate-project", str(MODULE_TEST_DATA_DIR / "empty_definitions_dir")],
)

assert cli_result.exit_code == 1
Expand Down Expand Up @@ -343,7 +368,7 @@ def test_cli_export_to_excel(tmpdir):
cli,
[
"export-definitions",
str(TEST_DATA_DIR / "general-config"),
str(TEST_DATA_DIR / "config" / "general-config"),
str(file),
],
).exit_code
Expand All @@ -363,7 +388,7 @@ def test_cli_add_missing_variables(simple_definition, tmp_path):
cli,
[
"list-missing-variables",
str(TEST_DATA_DIR / "add-missing-variables" / "data.xlsx"),
str(MODULE_TEST_DATA_DIR / "add-missing-variables" / "data.xlsx"),
"--workflow-directory",
str(tmp_path),
"--target-file",
Expand Down
Loading

0 comments on commit 9314fef

Please sign in to comment.