Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: convert test/jsonld/test_util.py to pytest #1961

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 34 additions & 49 deletions test/jsonld/test_util.py
Original file line number Original file line Diff line number Diff line change
@@ -1,89 +1,74 @@
import unittest import pytest
from typing import NamedTuple


from rdflib.plugins.shared.jsonld.util import norm_url from rdflib.plugins.shared.jsonld.util import norm_url




class URLTests(unittest.TestCase): @pytest.mark.parametrize(
@unittest.expectedFailure ["base", "url", "expected_result"],
def test_norm_url_xfail(self): [
class TestSpec(NamedTuple): pytest.param(
base: str
url: str
result: str

tests = [
TestSpec(
"git+ssh://example.com:1231/some/thing/", "git+ssh://example.com:1231/some/thing/",
"a", "a",
"git+ssh://example.com:1231/some/thing/a", "git+ssh://example.com:1231/some/thing/a",
), marks=pytest.mark.xfail(
] reason="""

URL normalizes to the wrong thing.
for test in tests:
(base, url, result) = test
with self.subTest(base=base, url=url):
self.assertEqual(norm_url(base, url), result)

def test_norm_url(self):
class TestSpec(NamedTuple):
base: str
url: str
result: str


tests = [ AssertionError: assert 'git+ssh://example.com:1231/some/thing/a' == 'a'
TestSpec("http://example.org/", "/one", "http://example.org/one"), """,
TestSpec("http://example.org/", "/one#", "http://example.org/one#"), raises=AssertionError,
TestSpec("http://example.org/one", "two", "http://example.org/two"), ),
TestSpec("http://example.org/one/", "two", "http://example.org/one/two"), ),
TestSpec( ("http://example.org/", "/one", "http://example.org/one"),
("http://example.org/", "/one#", "http://example.org/one#"),
("http://example.org/one", "two", "http://example.org/two"),
("http://example.org/one/", "two", "http://example.org/one/two"),
(
"http://example.org/", "http://example.org/",
"http://example.net/one", "http://example.net/one",
"http://example.net/one", "http://example.net/one",
), ),
TestSpec( (
"", "",
"1 2 3", "1 2 3",
"1 2 3", "1 2 3",
), ),
TestSpec( (
"http://example.org/", "http://example.org/",
"http://example.org//one", "http://example.org//one",
"http://example.org//one", "http://example.org//one",
), ),
TestSpec("", "http://example.org", "http://example.org"), ("", "http://example.org", "http://example.org"),
TestSpec("", "http://example.org/", "http://example.org/"), ("", "http://example.org/", "http://example.org/"),
TestSpec("", "mailto:name@example.com", "mailto:name@example.com"), ("", "mailto:name@example.com", "mailto:name@example.com"),
TestSpec( (
"http://example.org/", "http://example.org/",
"mailto:name@example.com", "mailto:name@example.com",
"mailto:name@example.com", "mailto:name@example.com",
), ),
TestSpec("http://example.org/a/b/c", "../../z", "http://example.org/z"), ("http://example.org/a/b/c", "../../z", "http://example.org/z"),
TestSpec("http://example.org/a/b/c", "../", "http://example.org/a/"), ("http://example.org/a/b/c", "../", "http://example.org/a/"),
TestSpec( (
"", "",
"git+ssh://example.com:1231/some/thing", "git+ssh://example.com:1231/some/thing",
"git+ssh://example.com:1231/some/thing", "git+ssh://example.com:1231/some/thing",
), ),
TestSpec( (
"git+ssh://example.com:1231/some/thing", "git+ssh://example.com:1231/some/thing",
"", "",
"git+ssh://example.com:1231/some/thing", "git+ssh://example.com:1231/some/thing",
), ),
TestSpec( (
"http://example.com/RDFLib/rdflib", "http://example.com/RDFLib/rdflib",
"http://example.org", "http://example.org",
"http://example.org", "http://example.org",
), ),
TestSpec( (
"http://example.com/RDFLib/rdflib", "http://example.com/RDFLib/rdflib",
"http://example.org/", "http://example.org/",
"http://example.org/", "http://example.org/",
), ),
] ],

)
for test in tests: def test_norm_url_xfail(base: str, url: str, expected_result: str) -> None:
(base, url, result) = test assert expected_result == norm_url(base, url)
with self.subTest(base=base, url=url):
self.assertEqual(norm_url(base, url), result)