Skip to content

Commit

Permalink
Merge pull request #614 from emmo-repo/doctest
Browse files Browse the repository at this point in the history
Added doctest
  • Loading branch information
jesper-friis committed Jun 6, 2023
2 parents 64b8e4e + 4818e9a commit 4487cc7
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion examples/ontology-from-excel/make_microstructure_onto.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ontopy/manchester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion ontopy/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ disable = [

[tool.pylint.format]
max-line-length = "80"

[tool.pytest.ini_options]
addopts = "--doctest-modules --ignore=demo --ignore=docs/demo --ignore=examples --ignore=docs/examples --ignore=site"
3 changes: 3 additions & 0 deletions tests/ontopy_tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/test_excelparser/test_excelparser.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = (
Expand Down
3 changes: 3 additions & 0 deletions tests/tools/test_excel2onto.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 4487cc7

Please sign in to comment.