From d1d699e806d4ebef0bf88f1b13ad4844558ce517 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Sat, 3 Jun 2023 12:18:19 +0200 Subject: [PATCH 1/4] Added doctest --- pyproject.toml | 3 +++ tests/ontopy_tests/test_graph.py | 3 +++ tests/test_basic.py | 1 + tests/test_excelparser/test_excelparser.py | 8 +++++++- tests/tools/test_excel2onto.py | 3 +++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8fc9f738c..5a49cb994 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,3 +10,6 @@ disable = [ [tool.pylint.format] max-line-length = "80" + +[tool.pytest.ini_options] +addopts = "--doctest-modules" diff --git a/tests/ontopy_tests/test_graph.py b/tests/ontopy_tests/test_graph.py index 0be76f9ec..afd9747a9 100644 --- a/tests/ontopy_tests/test_graph.py +++ b/tests/ontopy_tests/test_graph.py @@ -7,6 +7,9 @@ from ontopy.ontology import Ontology +@pytest.mark.filterwarnings( + "ignore:Style not defined for relation hasSpecialRelation:UserWarning" +) def test_graph(testonto: "Ontology", tmpdir: "Path") -> None: """Testing OntoGraph on a small ontology diff --git a/tests/test_basic.py b/tests/test_basic.py index e78846b39..148232338 100755 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -7,6 +7,7 @@ from ontopy.ontology import Ontology +@pytest.mark.filterwarnings("ignore:adding new IRI to ontology:UserWarning") def test_basic(emmo: "Ontology") -> None: from ontopy import get_ontology from ontopy.utils import LabelDefinitionError, EntityClassDefinitionError diff --git a/tests/test_excelparser/test_excelparser.py b/tests/test_excelparser/test_excelparser.py index 9ae141e34..81448c9a2 100644 --- a/tests/test_excelparser/test_excelparser.py +++ b/tests/test_excelparser/test_excelparser.py @@ -1,7 +1,8 @@ """Test the Excel parser module.""" -import pytest from typing import TYPE_CHECKING +import pytest + from ontopy import get_ontology from ontopy.excelparser import create_ontology_from_excel from ontopy.utils import NoSuchLabelError @@ -10,6 +11,11 @@ from pathlib import Path +@pytest.mark.filterwarnings("ignore:Ignoring concept :UserWarning") +@pytest.mark.filterwarnings("ignore:Invalid parents for :UserWarning") +@pytest.mark.filterwarnings( + "ignore:Not able to add the following concepts :UserWarning" +) def test_excelparser(repo_dir: "Path") -> None: """Basic test for creating an ontology from an Excel file.""" ontopath = ( diff --git a/tests/tools/test_excel2onto.py b/tests/tools/test_excel2onto.py index 6c8859c9b..cd81bf325 100644 --- a/tests/tools/test_excel2onto.py +++ b/tests/tools/test_excel2onto.py @@ -1,12 +1,15 @@ """Test the `ontograph` tool.""" from typing import TYPE_CHECKING +import pytest + if TYPE_CHECKING: from pathlib import Path from types import ModuleType from typing import Callable +@pytest.mark.filterwarnings("ignore::UserWarning") def test_run(get_tool: "Callable[[str], ModuleType]", tmpdir: "Path") -> None: """Check that running `excel2onto` works. From d8feef71362ce087208b6d9985fee759d347fe81 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Sat, 3 Jun 2023 12:54:20 +0200 Subject: [PATCH 2/4] Added doctest to ci testing as well... --- .github/workflows/ci_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 1c01b0521..c729d02b5 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -88,7 +88,7 @@ jobs: pip install -U -e .[dev] - name: Test - run: pytest -vvv --cov=ontopy --cov=emmopy --cov-report=xml --cov-report=term + run: pytest -vvv --cov=ontopy --cov=emmopy --cov-report=xml --cov-report=term --doctest-modules - name: Upload coverage to Codecov if: matrix.python-version == '3.7' && github.repository == 'emmo-repo/EMMOntoPy' From 68f146de3e4fcc0eb967861a56ca413de944a36a Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Sat, 3 Jun 2023 14:11:58 +0200 Subject: [PATCH 3/4] Corrected doctest in manchester.py Added folders that we want pytest to ignore --- examples/ontology-from-excel/make_microstructure_onto.py | 6 +++++- ontopy/manchester.py | 2 +- pyproject.toml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/ontology-from-excel/make_microstructure_onto.py b/examples/ontology-from-excel/make_microstructure_onto.py index de0171fe5..9e29fe073 100755 --- a/examples/ontology-from-excel/make_microstructure_onto.py +++ b/examples/ontology-from-excel/make_microstructure_onto.py @@ -1,11 +1,15 @@ """ python example for creating ontology from excel """ +from pathlib import Path + from ontopy.excelparser import create_ontology_from_excel from ontopy.utils import write_catalog + +thisdir = Path(__file__).resolve().parent ontology, catalog, errdict = create_ontology_from_excel( - "tool/microstructure.xlsx" + thisdir / "tool/microstructure.xlsx" ) ontology.save("microstructure_ontology.ttl", format="turtle", overwrite=True) diff --git a/ontopy/manchester.py b/ontopy/manchester.py index 4f7fdc6e9..143196f76 100644 --- a/ontopy/manchester.py +++ b/ontopy/manchester.py @@ -94,7 +94,7 @@ def evaluate(ontology: owlready2.Ontology, expr: str) -> owlready2.Construct: Example: >>> from ontopy.manchester import evaluate >>> from ontopy import get_ontology - >>> emmo = get_ontology.load() + >>> emmo = get_ontology().load() >>> restriction = evaluate(emmo, 'hasPart some Atom') >>> cls = evaluate(emmo, 'Atom') diff --git a/pyproject.toml b/pyproject.toml index 5a49cb994..2a6e73374 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,4 +12,4 @@ disable = [ max-line-length = "80" [tool.pytest.ini_options] -addopts = "--doctest-modules" +addopts = "--doctest-modules --ignore=demo --ignore=docs/demo --ignore=examples --ignore=docs/examples --ignore=site" From 4818e9a4ea8a276bb9d1333916be081d044a9bf2 Mon Sep 17 00:00:00 2001 From: Jesper Friis Date: Tue, 6 Jun 2023 10:29:43 +0200 Subject: [PATCH 4/4] Fixed doctest --- ontopy/patch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ontopy/patch.py b/ontopy/patch.py index 14b467619..05235d9e3 100644 --- a/ontopy/patch.py +++ b/ontopy/patch.py @@ -94,7 +94,7 @@ def _setitem(self, name, value): >>> emmo = get_emmo() >>> emmo.Atom['altLabel'] ['ChemicalElement'] - emmo.Atom['altLabel'] = 'Element' + >>> emmo.Atom['altLabel'] = 'Element' >>> emmo.Atom['altLabel'] ['ChemicalElement', 'Element']