diff --git a/tests/conftest.py b/tests/conftest.py index d7de402..0183279 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,8 @@ import pytest schema = "schemas/hif_schema_v0.1.0.json" -json_dir = "tests/test_files" +bad_json_dir = "tests/test_files/HIF-non-compliant" +good_json_dir = "tests/test_files/HIF-compliant" # validator @@ -14,92 +15,88 @@ def validator(): ### Examples which should break ### - - # test empty fields @pytest.fixture def empty(): - return json.load(open(f"{json_dir}/empty.json", "r")) + return json.load(open(f"{bad_json_dir}/empty.json", "r")) # test top-level @pytest.fixture def bad_top_level_field(): - return json.load(open(f"{json_dir}/bad_top_level_field.json", "r")) + return json.load(open(f"{bad_json_dir}/bad_top_level_field.json", "r")) @pytest.fixture def bad_network_type(): - return json.load(open(f"{json_dir}/bad_network_type.json", "r")) + return json.load(open(f"{bad_json_dir}/bad_network_type.json", "r")) # test metadata @pytest.fixture def metadata_as_list(): - return json.load(open(f"{json_dir}/metadata_as_list.json", "r")) + return json.load(open(f"{bad_json_dir}/metadata_as_list.json", "r")) # test nodes @pytest.fixture def bad_node_without_id(): - return json.load(open(f"{json_dir}/bad_node_without_id.json", "r")) + return json.load(open(f"{bad_json_dir}/bad_node_without_id.json", "r")) # test incidences @pytest.fixture def bad_incidence_field(): - return json.load(open(f"{json_dir}/bad_incidence_field.json", "r")) + return json.load(open(f"{bad_json_dir}/bad_incidence_field.json", "r")) @pytest.fixture def single_incidence_with_weight_as_string(): return json.load( - open(f"{json_dir}/single_incidence_with_weight_as_string.json", "r") + open(f"{bad_json_dir}/single_incidence_with_weight_as_string.json", "r") ) ### Examples which should work - - # empty @pytest.fixture def empty_hypergraph(): - return json.load(open(f"{json_dir}/empty_hypergraph.json", "r")) + return json.load(open(f"{good_json_dir}/empty_hypergraph.json", "r")) # test nodes @pytest.fixture def single_node(): - return json.load(open(f"{json_dir}/single_node.json", "r")) + return json.load(open(f"{good_json_dir}/single_node.json", "r")) @pytest.fixture def single_node_with_attrs(): - return json.load(open(f"{json_dir}/single_node_with_attrs.json", "r")) + return json.load(open(f"{good_json_dir}/single_node_with_attrs.json", "r")) # test edges @pytest.fixture def single_edge(): - return json.load(open(f"{json_dir}/single_edge.json", "r")) + return json.load(open(f"{good_json_dir}/single_edge.json", "r")) @pytest.fixture def single_edge_with_attrs(): - return json.load(open(f"{json_dir}/single_edge_with_attrs.json", "r")) + return json.load(open(f"{good_json_dir}/single_edge_with_attrs.json", "r")) # test incidences @pytest.fixture def single_incidence(): - return json.load(open(f"{json_dir}/single_incidence.json", "r")) + return json.load(open(f"{good_json_dir}/single_incidence.json", "r")) @pytest.fixture def single_incidence_with_weights(): - return json.load(open(f"{json_dir}/single_incidence_with_weights.json", "r")) + return json.load(open(f"{good_json_dir}/single_incidence_with_weights.json", "r")) @pytest.fixture def single_incidence_with_attrs(): - return json.load(open(f"{json_dir}/single_incidence_with_attrs.json", "r")) + return json.load(open(f"{good_json_dir}/single_incidence_with_attrs.json", "r")) diff --git a/tests/test_schema.py b/tests/test_compliant_files_against_schema.py similarity index 53% rename from tests/test_schema.py rename to tests/test_compliant_files_against_schema.py index 9b42293..db6b119 100644 --- a/tests/test_schema.py +++ b/tests/test_compliant_files_against_schema.py @@ -1,7 +1,6 @@ +### Tests which check HIF non-compliant files to make sure the schema catches them ### import pytest -### Tests which check bad formats ### - # test empty def test_empty(validator, empty): @@ -43,45 +42,3 @@ def test_single_incidence_with_weight_as_string( ): with pytest.raises(ValueError): validator(single_incidence_with_weight_as_string) - - -### Tests which check valid formats - - -# test empty -def test_empty_hypergraph(validator, empty_hypergraph): - validator(empty_hypergraph) - - -# test metadata - - -# test nodes -def test_single_node(validator, single_node): - validator(single_node) - - -def test_single_node_with_attrs(validator, single_node_with_attrs): - validator(single_node_with_attrs) - - -# test edges -def test_single_edge(validator, single_edge): - validator(single_edge) - - -def test_single_edge_with_attrs(validator, single_edge_with_attrs): - validator(single_edge_with_attrs) - - -# test incidences -def test_single_incidence(validator, single_incidence): - validator(single_incidence) - - -def test_single_incidence_with_weights(validator, single_incidence_with_weights): - validator(single_incidence_with_weights) - - -def test_single_incidence_with_attrs(validator, single_incidence_with_attrs): - validator(single_incidence_with_attrs) diff --git a/tests/test_files/empty_hypergraph.json b/tests/test_files/HIF-compliant/empty_hypergraph.json similarity index 100% rename from tests/test_files/empty_hypergraph.json rename to tests/test_files/HIF-compliant/empty_hypergraph.json diff --git a/tests/test_files/single_edge.json b/tests/test_files/HIF-compliant/single_edge.json similarity index 100% rename from tests/test_files/single_edge.json rename to tests/test_files/HIF-compliant/single_edge.json diff --git a/tests/test_files/single_edge_with_attrs.json b/tests/test_files/HIF-compliant/single_edge_with_attrs.json similarity index 100% rename from tests/test_files/single_edge_with_attrs.json rename to tests/test_files/HIF-compliant/single_edge_with_attrs.json diff --git a/tests/test_files/single_incidence.json b/tests/test_files/HIF-compliant/single_incidence.json similarity index 100% rename from tests/test_files/single_incidence.json rename to tests/test_files/HIF-compliant/single_incidence.json diff --git a/tests/test_files/single_incidence_with_attrs.json b/tests/test_files/HIF-compliant/single_incidence_with_attrs.json similarity index 100% rename from tests/test_files/single_incidence_with_attrs.json rename to tests/test_files/HIF-compliant/single_incidence_with_attrs.json diff --git a/tests/test_files/single_incidence_with_weights.json b/tests/test_files/HIF-compliant/single_incidence_with_weights.json similarity index 100% rename from tests/test_files/single_incidence_with_weights.json rename to tests/test_files/HIF-compliant/single_incidence_with_weights.json diff --git a/tests/test_files/single_node.json b/tests/test_files/HIF-compliant/single_node.json similarity index 100% rename from tests/test_files/single_node.json rename to tests/test_files/HIF-compliant/single_node.json diff --git a/tests/test_files/single_node_with_attrs.json b/tests/test_files/HIF-compliant/single_node_with_attrs.json similarity index 100% rename from tests/test_files/single_node_with_attrs.json rename to tests/test_files/HIF-compliant/single_node_with_attrs.json diff --git a/tests/test_files/bad_incidence_field.json b/tests/test_files/HIF-non-compliant/bad_incidence_field.json similarity index 100% rename from tests/test_files/bad_incidence_field.json rename to tests/test_files/HIF-non-compliant/bad_incidence_field.json diff --git a/tests/test_files/bad_network_type.json b/tests/test_files/HIF-non-compliant/bad_network_type.json similarity index 100% rename from tests/test_files/bad_network_type.json rename to tests/test_files/HIF-non-compliant/bad_network_type.json diff --git a/tests/test_files/bad_node_without_id.json b/tests/test_files/HIF-non-compliant/bad_node_without_id.json similarity index 100% rename from tests/test_files/bad_node_without_id.json rename to tests/test_files/HIF-non-compliant/bad_node_without_id.json diff --git a/tests/test_files/bad_top_level_field.json b/tests/test_files/HIF-non-compliant/bad_top_level_field.json similarity index 100% rename from tests/test_files/bad_top_level_field.json rename to tests/test_files/HIF-non-compliant/bad_top_level_field.json diff --git a/tests/test_files/empty.json b/tests/test_files/HIF-non-compliant/empty.json similarity index 100% rename from tests/test_files/empty.json rename to tests/test_files/HIF-non-compliant/empty.json diff --git a/tests/test_files/metadata_as_list.json b/tests/test_files/HIF-non-compliant/metadata_as_list.json similarity index 100% rename from tests/test_files/metadata_as_list.json rename to tests/test_files/HIF-non-compliant/metadata_as_list.json diff --git a/tests/test_files/single_incidence_with_weight_as_string.json b/tests/test_files/HIF-non-compliant/single_incidence_with_weight_as_string.json similarity index 100% rename from tests/test_files/single_incidence_with_weight_as_string.json rename to tests/test_files/HIF-non-compliant/single_incidence_with_weight_as_string.json diff --git a/tests/test_non-compliant_files_against_schema.py b/tests/test_non-compliant_files_against_schema.py new file mode 100644 index 0000000..4a53367 --- /dev/null +++ b/tests/test_non-compliant_files_against_schema.py @@ -0,0 +1,40 @@ +### Tests which check HIF-compliant files formats to make sure the schema validates them ### + + +# test empty +def test_empty_hypergraph(validator, empty_hypergraph): + validator(empty_hypergraph) + + +# test metadata + + +# test nodes +def test_single_node(validator, single_node): + validator(single_node) + + +def test_single_node_with_attrs(validator, single_node_with_attrs): + validator(single_node_with_attrs) + + +# test edges +def test_single_edge(validator, single_edge): + validator(single_edge) + + +def test_single_edge_with_attrs(validator, single_edge_with_attrs): + validator(single_edge_with_attrs) + + +# test incidences +def test_single_incidence(validator, single_incidence): + validator(single_incidence) + + +def test_single_incidence_with_weights(validator, single_incidence_with_weights): + validator(single_incidence_with_weights) + + +def test_single_incidence_with_attrs(validator, single_incidence_with_attrs): + validator(single_incidence_with_attrs)