Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e326572
Started to prepare for Python 3.13
jesper-friis Nov 23, 2024
758c803
Merge branch 'master' into support-python3.13
jesper-friis Nov 23, 2024
c6257e7
Added Python 3.13 to supported languages
jesper-friis Nov 23, 2024
edb558a
Only test the tests
jesper-friis Nov 23, 2024
31ad643
Trying to readd pytest coverage
jesper-friis Nov 23, 2024
a98723f
Also test for Python 3.13
jesper-friis Nov 23, 2024
2fa3f6c
Do not require DLite (yet) for Python 3.13
jesper-friis Nov 23, 2024
1e0761b
Merge branch 'master' into support-python3.13
jesper-friis Dec 10, 2024
4f92f7b
Tests fails for Python 3.13 due to pub in pylint
jesper-friis Dec 10, 2024
86727e6
Merge branch 'support-python3.13' of github.com:EMMC-ASBL/tripper int…
jesper-friis Dec 10, 2024
2dd4975
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 10, 2024
48a9291
Disabled some new pylint issues
jesper-friis Dec 10, 2024
25b527a
Merge branch 'support-python3.13' of github.com:EMMC-ASBL/tripper int…
jesper-friis Dec 10, 2024
64d46d7
Merge branch 'master' into support-python3.13
jesper-friis Dec 10, 2024
6265637
Updated test to latest version of EMMO
jesper-friis Dec 13, 2024
d61995c
Ignore doctest of the tripper.tripper module
jesper-friis Dec 13, 2024
3769816
Updated tutorial to latest version of EMMO
jesper-friis Dec 13, 2024
4a4e97a
Do not ignore tripper when running doctest (again)
jesper-friis Dec 13, 2024
11320f6
Adding some more less strict doctest options
jesper-friis Dec 13, 2024
6efdacb
Ignore "Too Many Requests" errors in test_sparqlwrapper
jesper-friis Dec 13, 2024
9ff8a2c
Fail on doctest errors
jesper-friis Dec 13, 2024
15f1388
Cleanup
jesper-friis Dec 13, 2024
33d4772
Updated dependency on dlite
jesper-friis Dec 14, 2024
2e6602a
Updated dependencies
jesper-friis Dec 14, 2024
6d64fd4
Updated dependency on DLite for Python 3.13
jesper-friis Dec 15, 2024
0dc4bd9
Corrected requirements on numpy
jesper-friis Dec 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout tripper
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- name: Checkout tripper
Expand Down
3 changes: 0 additions & 3 deletions docs/api_reference/testutils.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Note:
... ?unit rdfs:subClassOf <{EMMO.LengthUnit}> .
... ?unit rdfs:subClassOf ?r .
... ?r rdf:type owl:Restriction .
... ?r owl:onProperty <{EMMO.hasSymbolValue}> .
... ?r owl:onProperty <{EMMO.unitSymbolValue}> .
... ?r owl:hasValue ?symbol .
... }}
... """
Expand Down
63 changes: 24 additions & 39 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Environment :: Plugins",
"Natural Language :: English",
"Operating System :: OS Independent",
Expand All @@ -29,11 +30,19 @@ requires-python = ">=3.7"
dynamic = ["version"]

dependencies = [
"typing-extensions>=4.7.0,<4.7.1; python_version<'3.8'",
"pint>=0.16.1,<0.25",
"typing-extensions>=4.7.0,<4.7.1; python_version<'3.9'",
]

[project.optional-dependencies]
mappings = [
"pint>=0.16.1,<0.25",
"rdflib>=6.3.0,<7.0.0",
]
dataset = [
"tripper[mappings]",
"PyYaml>=3.0.0,<6.0.3", # todo: check lower version
"requests>=2.0.0,<3.4.1", # todo: check lower version
]
pre-commit = [
"pre-commit==4.0.1",
"pylint==2.15.5",
Expand All @@ -43,25 +52,17 @@ testing-core = [
"pytest-cov==4.1.0",
]
testing = [
# Consistent with: dependencies (is this needed?)
"pint>=0.16.1,<0.24",
# Consistent with: testing-core
"pytest==7.4.4",
"pytest-cov==4.1.0",
# testing
"EMMOntoPy>=0.5.0,<0.7.1",
"rdflib>=6.3.0,<7.0.0",
"SPARQLWrapper>=2.0.0,<2.0.1",
"DLite-Python>=0.5.1,<0.5.17",
"tripper[testing-core,mappings,dataset]",
"dlite-python>=0.5.23,<0.5.27; python_version>='3.8' and python_version<'3.13'",
"dlite-python>=0.5.25,<0.5.27; python_version>='3.13'",
"emmontopy>=0.5.0,<0.7.1; python_version<'3.13'",
"graphviz>=0.20.1,<0.20.2",
"numpy<2.1.0; python_version>='3.13'",
"rdflib>=6.3.0,<7.0.0",
"sparqlwrapper>=2.0.0,<2.0.1",
]
docs = [
# Consistent with: testing
"EMMOntoPy>=0.5.0,<0.7.1",
"rdflib>=6.3.0,<7.0.0",
"SPARQLWrapper>=2.0.0,<2.0.1",
"DLite-Python>=0.5.1,<0.5.17",
# docs
"tripper[testing]",
"mike==2.1.2",
"mkdocs==1.5.3",
"mkdocs-autorefs==0.4.1",
Expand All @@ -71,26 +72,7 @@ docs = [
"mkdocstrings-python-legacy==0.2.3",
]
dev = [
# Consistent with: pre-commit
"pre-commit==2.21.0",
"pylint==2.15.5",
# Consistent with: testing-core
"pytest==7.4.4",
"pytest-cov==4.1.0",
# Consistent with testing
"EMMOntoPy>=0.5.0,<0.7.1",
"rdflib>=6.3.0,<7.0.0",
"SPARQLWrapper>=2.0.0,<2.0.1",
"DLite-Python>=0.5.1,<0.5.17",
"graphviz>=0.20.1,<0.20.2",
# Consistent with: docs
"mike==2.1.2",
"mkdocs==1.5.3",
"mkdocs-autorefs==0.4.1",
"mkdocs-awesome-pages-plugin==2.9.2",
"mkdocs-material==9.5.17",
"mkdocstrings==0.22.0",
"mkdocstrings-python-legacy==0.2.3",
"tripper[pre-commit,docs]",
]

[project.urls]
Expand Down Expand Up @@ -122,6 +104,7 @@ max-public-methods = 25
max-locals = 20
disable = [
"fixme",
"too-many-positional-arguments",
]
good-names = [
# Default
Expand All @@ -132,11 +115,13 @@ good-names = [
"s", "p", "o",
# Namespaces
"EX",
# dict, value, file, ...
"d", "v", "f",
]

[tool.pytest.ini_options]
minversion = "7.0"
addopts = "-rs --cov=tripper --cov-report=term --doctest-modules"
addopts = "-rs --cov=tripper --cov-report=term --doctest-modules --doctest-ignore-import-errors"
filterwarnings = [
"ignore:.*imp module.*:DeprecationWarning",
"ignore:::tripper.literal:243", # Ignore warning in doctest
Expand Down
10 changes: 9 additions & 1 deletion tests/backends/test_sparqlwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def test_sparqlwrapper_backend():
import pytest

pytest.importorskip("SPARQLWrapper")
requests = pytest.importorskip("requests")

from tripper import Triplestore

Expand All @@ -25,5 +26,12 @@ def test_sparqlwrapper_backend():

endpoint_url = "https://query.wikidata.org/sparql"
ts = Triplestore(backend="sparqlwrapper", base_iri=endpoint_url)
res = ts.query(sparql_query)

# Ignore failures due to too many requests
try:
res = ts.query(sparql_query)
except requests.HTTPError as exc:
if "Too Many Requests" not in str(exc):
raise

assert res == [("http://www.wikidata.org/entity/Q20", "Norway")]
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def expected_function_triplestore(
A Turtle-serialized output that would be expected from the Triplestore.

"""
# pylint: disable=line-too-long

from tripper.utils import function_id

fid = function_id(example_function)
Expand Down
41 changes: 22 additions & 19 deletions tests/mappings/test_cost.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
"""Test cost."""

import pytest

pytest.importorskip("rdflib")
def test_cost():
"""Test cost"""
# pylint: disable=invalid-name

# pylint: disable=wrong-import-position
from tripper import Triplestore
import pytest

ts = Triplestore(backend="rdflib")
pytest.importorskip("rdflib")

# Define some prefixed namespaces
CHEM = ts.bind("chem", "http://onto-ns.com/onto/chemistry#")
MOL = ts.bind("mol", "http://onto-ns.com/meta/0.1/Molecule#")
SUB = ts.bind("sub", "http://onto-ns.com/meta/0.1/Substance#")
# pylint: disable=wrong-import-position
from tripper import Triplestore

ts = Triplestore(backend="rdflib")

def formula_cost(ts, input_iris, output_iri):
"""Returns a cost."""
# pylint: disable=unused-argument
return 2.72
# Define some prefixed namespaces
CHEM = ts.bind("chem", "http://onto-ns.com/onto/chemistry#")
MOL = ts.bind("mol", "http://onto-ns.com/meta/0.1/Molecule#")
SUB = ts.bind("sub", "http://onto-ns.com/meta/0.1/Substance#")

def formula_cost(ts, input_iris, output_iri):
"""Returns a cost."""
# pylint: disable=unused-argument
return 2.72

# Add mappings from data models to ontology
ts.map(MOL.name, CHEM.Identifier, cost=3.14)
ts.map(SUB.formula, CHEM.Formula, cost=formula_cost)
# Add mappings from data models to ontology
ts.map(MOL.name, CHEM.Identifier, cost=3.14)
ts.map(SUB.formula, CHEM.Formula, cost=formula_cost)

# pylint: disable=protected-access
assert ts._get_cost(CHEM.Identifier) == 3.14
assert ts._get_cost(CHEM.Formula) == 2.72
# pylint: disable=protected-access
assert ts._get_cost(CHEM.Identifier) == 3.14
assert ts._get_cost(CHEM.Formula) == 2.72
2 changes: 2 additions & 0 deletions tests/output/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.ttl
*.png
*.tiff
6 changes: 1 addition & 5 deletions tripper/testutils.py → tests/paths.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
"""Motule primarly intended to be imported by tests.

It defines some directories and some utility functions that can be used
with or without conftest.
"""
"""Test paths"""

from pathlib import Path

Expand Down
2 changes: 1 addition & 1 deletion tests/test_add_function.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test Triplestore.add_function()"""

# pylint: disable=invalid-name
# pylint: disable=invalid-name,import-outside-toplevel


def test_add_function():
Expand Down
23 changes: 14 additions & 9 deletions tests/test_custom_backend.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Test custom plugin."""
"""Test custom backend."""

from tripper import Triplestore
# pylint: disable=import-outside-toplevel

# Test relative import
ts = Triplestore(backend="backends.dummy", package="backends")
assert list(ts.triples()) == [
("a", "b", "c"),
("d", "e", "f"),
("g", "h", "i"),
]

def test_custom_backend():
"""Test custom backend."""
from tripper import Triplestore

# Test relative import
ts = Triplestore(backend="backends.dummy", package="backends")
assert list(ts.triples()) == [
("a", "b", "c"),
("d", "e", "f"),
("g", "h", "i"),
]
102 changes: 52 additions & 50 deletions tests/test_eval_function.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
"""Test Triplestore.eval_function()"""

# pylint: disable=import-outside-toplevel

import pytest

from tripper import Triplestore

pytest.importorskip("rdflib")


def func(a, b):
"""Returns the sum of `a` and `b`."""
# pylint: disable=invalid-name
return a + b


ts = Triplestore(backend="rdflib")
EX = ts.bind("ex", "http://example.com/ex#")

# Test to add function in current scope
iri = ts.add_function(
func,
expects=[EX.arg1, EX.arg2],
returns=EX.sum,
standard="emmo",
)
assert ts.eval_function(func_iri=iri, args=(2, 3)) == 5


# Test to add a function from the standard library. The hashlib module
# is not expected to be imported in the current scope
iri2 = ts.add_function(
EX.shake256,
expects=[EX.Bytes],
returns=EX.ShakeVar,
func_name="shake_256",
module_name="hashlib",
)
shakevar = ts.eval_function(iri2, (b"a",))
assert shakevar.hexdigest(4) == "867e2cb0"


# Test to add a function from a pypi package.
iri3 = ts.add_function(
EX.UFloat,
expects=[EX.Uncertainty],
returns=EX.UUID,
func_name="ufloat",
module_name="uncertainties",
# package_name="uncertainties",
pypi_package_name="uncertainties==3.1.7",
)
val = ts.eval_function(iri3, args=(1, 0.1))
assert val.n == 1
assert val.s == 0.1

def eval_function():
"""Test Triplestore.eval_function()"""

from tripper import Triplestore

pytest.importorskip("rdflib")

def func(a, b):
"""Returns the sum of `a` and `b`."""
# pylint: disable=invalid-name
return a + b

ts = Triplestore(backend="rdflib")
EX = ts.bind("ex", "http://example.com/ex#")

# Test to add function in current scope
iri = ts.add_function(
func,
expects=[EX.arg1, EX.arg2],
returns=EX.sum,
standard="emmo",
)
assert ts.eval_function(func_iri=iri, args=(2, 3)) == 5

# Test to add a function from the standard library. The hashlib module
# is not expected to be imported in the current scope
iri2 = ts.add_function(
EX.shake256,
expects=[EX.Bytes],
returns=EX.ShakeVar,
func_name="shake_256",
module_name="hashlib",
)
shakevar = ts.eval_function(iri2, (b"a",))
assert shakevar.hexdigest(4) == "867e2cb0"

# Test to add a function from a pypi package.
iri3 = ts.add_function(
EX.UFloat,
expects=[EX.Uncertainty],
returns=EX.UUID,
func_name="ufloat",
module_name="uncertainties",
# package_name="uncertainties",
pypi_package_name="uncertainties==3.1.7",
)
val = ts.eval_function(iri3, args=(1, 0.1))
assert val.n == 1
assert val.s == 0.1
2 changes: 1 addition & 1 deletion tests/test_get_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test Triplestore.get_data() and related methods."""

# pylint: disable=unused-argument,invalid-name
# pylint: disable=unused-argument,invalid-name,import-outside-toplevel


def test_get_data():
Expand Down
Loading
Loading