Skip to content

Commit

Permalink
move good and bad files to separate folders
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed Oct 3, 2024
1 parent e69edd4 commit 30de33e
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 64 deletions.
37 changes: 17 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
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.
40 changes: 40 additions & 0 deletions tests/test_non-compliant_files_against_schema.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 30de33e

Please sign in to comment.