diff --git a/Makefile b/Makefile index d9ec570f..e654af9b 100644 --- a/Makefile +++ b/Makefile @@ -25,20 +25,25 @@ flake8: format: @$(PYTHON3) -m black hypernetx -## Test +## Tests pre-commit: pre-commit install pre-commit run --all-files + test: + coverage run --source=hypernetx -m pytest + coverage report -m + +test-ci: @$(PYTHON3) -m tox -test-ci: lint-deps lint pre-commit test-deps test +test-ci-stash: lint-deps lint pre-commit test-deps test-ci -test-ci-github: lint-deps lint pre-commit ci-github-deps test-deps test +test-ci-github: lint-deps lint pre-commit ci-github-deps test-deps test-ci -.PHONY: test, test-ci, test-ci-github, pre-commit +.PHONY: pre-commit test test-ci, test-ci-stash, test-ci-github ## Continuous Deployment ## Assumes that scripts are run on a container or test server VM diff --git a/hypernetx/classes/tests/test_entityset_on_dataframe.py b/hypernetx/classes/tests/test_entityset_on_dataframe.py index d49ee408..acd1b2f0 100644 --- a/hypernetx/classes/tests/test_entityset_on_dataframe.py +++ b/hypernetx/classes/tests/test_entityset_on_dataframe.py @@ -3,8 +3,6 @@ import pandas as pd import numpy as np -from pytest_lazyfixture import lazy_fixture - from hypernetx import EntitySet @@ -48,11 +46,6 @@ def test_remove(self, es_from_df): @pytest.mark.parametrize( "props, multidx, expected_props", [ - ( - lazy_fixture("props_dataframe"), - (0, "P"), - {"prop1": "propval1", "prop2": "propval2"}, - ), ( {0: {"P": {"prop1": "propval1", "prop2": "propval2"}}}, (0, "P"), @@ -77,16 +70,6 @@ def test_assign_properties(self, es_from_df, props, multidx, expected_props): @pytest.mark.parametrize( "cell_props, multidx, expected_cell_properties", [ - ( - lazy_fixture("cell_props_dataframe"), - ("P", "A"), - {"prop1": "propval1", "prop2": "propval2"}, - ), - ( - lazy_fixture("cell_props_dataframe_multidx"), - ("P", "A"), - {"prop1": "propval1", "prop2": "propval2"}, - ), ( {"P": {"A": {"prop1": "propval1", "prop2": "propval2"}}}, ("P", "A"), diff --git a/hypernetx/classes/tests/test_entityset_on_dict.py b/hypernetx/classes/tests/test_entityset_on_dict.py index ed589ae1..e1c5c0e0 100644 --- a/hypernetx/classes/tests/test_entityset_on_dict.py +++ b/hypernetx/classes/tests/test_entityset_on_dict.py @@ -1,56 +1,52 @@ import numpy as np import pytest -from pytest_lazyfixture import lazy_fixture - from hypernetx.classes import EntitySet @pytest.mark.parametrize( "entity, data, data_cols, labels", [ - (lazy_fixture("sbs_dict"), None, (0, 1), None), + (("sbs_dict"), None, (0, 1), None), ( - lazy_fixture("sbs_dict"), + ("sbs_dict"), None, (0, 1), - lazy_fixture("sbs_labels"), + ("sbs_labels"), ), # labels are ignored if entity is provided - (lazy_fixture("sbs_dict"), None, ["edges", "nodes"], None), - (lazy_fixture("sbs_dict"), lazy_fixture("sbs_data"), (0, 1), None), - (None, lazy_fixture("sbs_data"), (0, 1), lazy_fixture("sbs_labels")), + ("sbs_dict", None, ["edges", "nodes"], None) ], ) class TestEntitySBSDict: """Tests on different use cases for combination of the following params: entity, data, data_cols, labels""" - def test_size(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_size(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.size() == len(sbs.edgedict) # check all the EntitySet properties - def test_isstatic(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_isstatic(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.isstatic - def test_uid(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_uid(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.uid is None - def test_empty(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_empty(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert not es.empty - def test_uidset(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_uidset(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.uidset == {"I", "R", "S", "P", "O", "L"} - def test_dimsize(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_dimsize(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.dimsize == 2 - def test_elements(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_elements(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert len(es.elements) == 6 expected_elements = { "I": ["K", "T2"], @@ -64,8 +60,8 @@ def test_elements(self, entity, data, data_cols, labels, sbs): assert expected_edge in es.elements assert es.elements[expected_edge].sort() == expected_nodes.sort() - def test_incident_dict(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_incident_dict(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) expected_incident_dict = { "I": ["K", "T2"], "L": ["E", "C"], @@ -81,12 +77,12 @@ def test_incident_dict(self, entity, data, data_cols, labels, sbs): assert "I" in es assert "K" in es - def test_children(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_children(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.children == {"C", "T1", "A", "K", "T2", "V", "E"} - def test_memberships(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_memberships(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.memberships == { "A": ["P", "R", "S"], "C": ["P", "L"], @@ -97,15 +93,15 @@ def test_memberships(self, entity, data, data_cols, labels, sbs): "V": ["S"], } - def test_cell_properties(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_cell_properties(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.cell_properties.shape == ( 15, 1, ) - def test_cell_weights(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_cell_weights(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert es.cell_weights == { ("P", "C"): 1, ("P", "K"): 1, @@ -124,8 +120,8 @@ def test_cell_weights(self, entity, data, data_cols, labels, sbs): ("I", "T2"): 1, } - def test_labels(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_labels(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) # check labeling based on given attributes for EntitySet if data_cols == [ "edges", @@ -145,8 +141,8 @@ def test_labels(self, entity, data, data_cols, labels, sbs): 1: ["A", "C", "E", "K", "T1", "T2", "V"], } - def test_dataframe(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_dataframe(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) # check dataframe # size should be the number of rows times the number of columns, i.e 15 x 3 assert es.dataframe.size == 45 @@ -159,8 +155,8 @@ def test_dataframe(self, entity, data, data_cols, labels, sbs): assert actual_node_row0 in ["A", "C", "K"] assert actual_cell_weight_row0 == 1 - def test_data(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_data(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) actual_data = es.data @@ -189,8 +185,8 @@ def test_data(self, entity, data, data_cols, labels, sbs): np.sort(actual_data, axis=0), np.sort(expected_data, axis=0) ) - def test_properties(self, entity, data, data_cols, labels, sbs): - es = EntitySet(entity=entity, data=data, data_cols=data_cols, labels=labels) + def test_properties(self, entity, data, data_cols, labels, sbs, request): + es = EntitySet(entity=request.getfixturevalue(entity), data=data, data_cols=data_cols, labels=labels) assert ( es.properties.size == 39 ) # Properties has three columns and 13 rows of data (i.e. edges + nodes) @@ -198,7 +194,7 @@ def test_properties(self, entity, data, data_cols, labels, sbs): @pytest.mark.xfail(reason="Deprecated; to be removed in next released") -def test_level(sbs): +def test_level(sbs, request): # at some point we are casting out and back to categorical dtype without # preserving categories ordering from `labels` provided to constructor ent_sbs = EntitySet(data=np.asarray(sbs.data), labels=sbs.labels) diff --git a/tox.ini b/tox.ini index e73113e8..506eae61 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ allowlist_externals = env commands = env python --version - coverage run --source=hypernetx -m pytest + coverage run --source=hypernetx -m pytest --junitxml=pytest.xml coverage report -m [testenv:py38-notebooks]