Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ upgrade-submodules:
git submodule update --remote --init --recursive

# TODO: Expand to lib/ and tests/ as linting issues are resolved.
RUFF_TARGET = lib/pyld/context_resolver.py lib/pyld/identifier_issuer.py lib/pyld/iri_resolver.py lib/pyld/nquads.py lib/pyld/resolved_context.py tests/test_document_loader.py
RUFF_TARGET = lib/pyld/context_resolver.py lib/pyld/identifier_issuer.py lib/pyld/iri_resolver.py lib/pyld/nquads.py lib/pyld/resolved_context.py tests/*.py

lint:
ruff check $(RUFF_TARGET)
Expand Down
46 changes: 32 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import unittest
from contextlib import suppress

import pytest

# Import the existing test runner module so we can reuse Manifest/Test
Expand All @@ -10,10 +12,23 @@
def pytest_addoption(parser):
# Do only long options for pytest integration; pytest reserves
# lowercase single-letter short options for its own CLI flags.
parser.addoption('--tests', nargs='*', default=[], help='A manifest or directory to test')
parser.addoption('--earl', dest='earl', help='The filename to write an EARL report to')
parser.addoption('--loader', dest='loader', default='requests', help='The remote URL document loader: requests, aiohttp')
parser.addoption('--number', dest='number', help='Limit tests to those containing the specified test identifier')
parser.addoption(
'--tests', nargs='*', default=[], help='A manifest or directory to test'
)
parser.addoption(
'--earl', dest='earl', help='The filename to write an EARL report to'
)
parser.addoption(
'--loader',
dest='loader',
default='requests',
help='The remote URL document loader: requests, aiohttp',
)
parser.addoption(
'--number',
dest='number',
help='Limit tests to those containing the specified test identifier',
)


def pytest_configure(config):
Expand All @@ -26,9 +41,13 @@ def pytest_configure(config):
# existing `runtests` helpers behave the same as the CLI runner.
loader = config.getoption('loader')
if loader == 'requests':
runtests.jsonld._default_document_loader = runtests.jsonld.requests_document_loader()
runtests.jsonld._default_document_loader = (
runtests.jsonld.requests_document_loader()
)
elif loader == 'aiohttp':
runtests.jsonld._default_document_loader = runtests.jsonld.aiohttp_document_loader()
runtests.jsonld._default_document_loader = (
runtests.jsonld.aiohttp_document_loader()
)

number = config.getoption('number')
if number:
Expand Down Expand Up @@ -85,7 +104,7 @@ def pytest_generate_tests(metafunc):
'description': 'Top level PyLD test manifest',
'name': 'PyLD',
'sequence': [],
'filename': '/'
'filename': '/',
}

for test in test_targets:
Expand All @@ -99,7 +118,7 @@ def pytest_generate_tests(metafunc):
filename = os.path.join(test, 'manifest.jsonld')
if os.path.exists(filename):
root_manifest['sequence'].append(os.path.abspath(filename))

# Use the existing Manifest loader to create a TestSuite and flatten it
suite = runtests.Manifest(root_manifest, root_manifest['filename']).load()
tests = list(_flatten_suite(suite))
Expand All @@ -114,7 +133,7 @@ def pytest_runtest_makereport(item):
# Hookwrapper gives us the final test report via `outcome.get_result()`.
outcome = yield
rep = outcome.get_result()

# We only handle the main call phase to match
# the behaviour of the original runner which only reported passes
# and failures/errors.
Expand All @@ -139,12 +158,11 @@ def pytest_runtest_makereport(item):
if rep.outcome == 'skipped':
return

success = (rep.outcome == 'passed')
try:
success = rep.outcome == 'passed'

# Don't let EARL bookkeeping break test execution; be quiet on error.
with suppress(Exception):
earl_report.add_assertion(manifest_test, success)
except Exception:
# Don't let EARL bookkeeping break test execution; be quiet on error.
pass


def pytest_sessionfinish(session, exitstatus):
Expand Down
Loading