-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from emmo-repo/cwa/close-220-tidy-up-tests
Ensure all produced files from tests are in a temp dir. Add pytest fixtures for loading EMMO, as this is done in several tests. Add fixture for location to repo_dir, instantiating it only once per pytest session. Add a yield-fixture for creating a temporary directory that lives for the lifetime of the test function. This removes the possibility to check through the generated files from the tests, keeping the unit tests being just that: unit tests. However, I guess the generated files should be tested more now? In short, the unit tests here should never rely on human inspection, hence, they shouldn't produce any permanent files. If examples are the motive for the tests (as it is explicitly stated for one of them) it should be added to the examples/ folder and be part of the documentation.
- Loading branch information
Showing
14 changed files
with
213 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,6 @@ __pycache__ | |
MANIFEST | ||
dist | ||
build | ||
old | ||
test_graph2 | ||
|
||
*.xml | ||
|
||
# Documentation | ||
site/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Pytest fixtures and setup functions.""" | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
if TYPE_CHECKING: | ||
from ontopy.ontology import Ontology | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def repo_dir() -> Path: | ||
"""Absolute path to the repository directory.""" | ||
return Path(__file__).parent.parent.resolve() | ||
|
||
|
||
@pytest.fixture | ||
def emmo() -> "Ontology": | ||
"""Load and return EMMO.""" | ||
from emmopy import get_emmo | ||
|
||
emmo = get_emmo() | ||
|
||
return emmo | ||
|
||
|
||
@pytest.fixture | ||
def tmpdir() -> Path: | ||
"""Create a temporary directory that lasts the runtime of the test.""" | ||
from tempfile import TemporaryDirectory | ||
|
||
res = TemporaryDirectory() | ||
yield Path(res.name) | ||
res.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
def test_graph() -> None: | ||
import sys | ||
import os | ||
from typing import TYPE_CHECKING | ||
|
||
# Add emmo to sys path | ||
thisdir = os.path.abspath(os.path.dirname(__file__)) | ||
sys.path.insert(1, os.path.abspath(os.path.join(thisdir, '..'))) | ||
from ontopy import get_ontology # noqa: E402, F401 | ||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
from ontopy.ontology import Ontology | ||
|
||
emmo = get_ontology() | ||
emmo.load() | ||
def test_graph(emmo: "Ontology", tmpdir: "Path") -> None: | ||
graph = emmo.get_dot_graph(relations='is_a') | ||
graph.write_svg(tmpdir / 'taxonomy.svg') | ||
graph.write_pdf(tmpdir / 'taxonomy.pdf') | ||
|
||
graph = emmo.get_dot_graph(relations='is_a') | ||
graph.write_svg('taxonomy.svg') | ||
graph.write_pdf('taxonomy.pdf') | ||
entity_graph = emmo.get_dot_graph('EMMO') | ||
entity_graph.write_svg(tmpdir / 'taxonomy2.svg') | ||
|
||
entity_graph = emmo.get_dot_graph('EMMO') | ||
entity_graph.write_svg('taxonomy2.svg') | ||
substrate_graph = emmo.get_dot_graph('Item', relations=True, | ||
leafs=('Physical'), parents='Item', | ||
style='uml') | ||
substrate_graph.write_svg(tmpdir / 'merotopology_graph.svg') | ||
|
||
substrate_graph = emmo.get_dot_graph('Item', relations=True, | ||
leafs=('Physical'), parents='Item', | ||
style='uml') | ||
substrate_graph.write_svg('merotopology_graph.svg') | ||
property_graph = emmo.get_dot_graph('Property') | ||
property_graph.write_svg(tmpdir / 'property_graph.svg') | ||
|
||
property_graph = emmo.get_dot_graph('Property') | ||
property_graph.write_svg('property_graph.svg') | ||
# Update the default style | ||
emmo._default_style['graph']['rankdir'] = 'BT' | ||
|
||
|
||
# Update the default style | ||
emmo._default_style['graph']['rankdir'] = 'BT' | ||
|
||
relations_graph = emmo.get_dot_graph('EMMORelation') | ||
relations_graph.write_pdf('relation_graph.pdf') | ||
relations_graph.write_png('relation_graph.png') | ||
relations_graph = emmo.get_dot_graph('EMMORelation') | ||
relations_graph.write_pdf(tmpdir / 'relation_graph.pdf') | ||
relations_graph.write_png(tmpdir / 'relation_graph.png') |
Oops, something went wrong.