Skip to content

Commit dd56451

Browse files
authored
Convert test/jsonld/test_util.py to pytest (#1961)
Not the most straight forward conversion, but it simplifies it somewhat. Main reason for doing this is to remove the use of `unittest` `subTest` as we need `pytest-subtest` to process that with `pytest` and that dependency is causing some complications in dependency solving for pip sometimes. Merged with one review as this has no runtime impact.
1 parent a24586a commit dd56451

File tree

1 file changed

+68
-83
lines changed

1 file changed

+68
-83
lines changed

test/jsonld/test_util.py

Lines changed: 68 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,74 @@
1-
import unittest
2-
from typing import NamedTuple
1+
import pytest
32

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

65

7-
class URLTests(unittest.TestCase):
8-
@unittest.expectedFailure
9-
def test_norm_url_xfail(self):
10-
class TestSpec(NamedTuple):
11-
base: str
12-
url: str
13-
result: str
6+
@pytest.mark.parametrize(
7+
["base", "url", "expected_result"],
8+
[
9+
pytest.param(
10+
"git+ssh://example.com:1231/some/thing/",
11+
"a",
12+
"git+ssh://example.com:1231/some/thing/a",
13+
marks=pytest.mark.xfail(
14+
reason="""
15+
URL normalizes to the wrong thing.
1416
15-
tests = [
16-
TestSpec(
17-
"git+ssh://example.com:1231/some/thing/",
18-
"a",
19-
"git+ssh://example.com:1231/some/thing/a",
17+
AssertionError: assert 'git+ssh://example.com:1231/some/thing/a' == 'a'
18+
""",
19+
raises=AssertionError,
2020
),
21-
]
22-
23-
for test in tests:
24-
(base, url, result) = test
25-
with self.subTest(base=base, url=url):
26-
self.assertEqual(norm_url(base, url), result)
27-
28-
def test_norm_url(self):
29-
class TestSpec(NamedTuple):
30-
base: str
31-
url: str
32-
result: str
33-
34-
tests = [
35-
TestSpec("http://example.org/", "/one", "http://example.org/one"),
36-
TestSpec("http://example.org/", "/one#", "http://example.org/one#"),
37-
TestSpec("http://example.org/one", "two", "http://example.org/two"),
38-
TestSpec("http://example.org/one/", "two", "http://example.org/one/two"),
39-
TestSpec(
40-
"http://example.org/",
41-
"http://example.net/one",
42-
"http://example.net/one",
43-
),
44-
TestSpec(
45-
"",
46-
"1 2 3",
47-
"1 2 3",
48-
),
49-
TestSpec(
50-
"http://example.org/",
51-
"http://example.org//one",
52-
"http://example.org//one",
53-
),
54-
TestSpec("", "http://example.org", "http://example.org"),
55-
TestSpec("", "http://example.org/", "http://example.org/"),
56-
TestSpec("", "mailto:[email protected]", "mailto:[email protected]"),
57-
TestSpec(
58-
"http://example.org/",
59-
60-
61-
),
62-
TestSpec("http://example.org/a/b/c", "../../z", "http://example.org/z"),
63-
TestSpec("http://example.org/a/b/c", "../", "http://example.org/a/"),
64-
TestSpec(
65-
"",
66-
"git+ssh://example.com:1231/some/thing",
67-
"git+ssh://example.com:1231/some/thing",
68-
),
69-
TestSpec(
70-
"git+ssh://example.com:1231/some/thing",
71-
"",
72-
"git+ssh://example.com:1231/some/thing",
73-
),
74-
TestSpec(
75-
"http://example.com/RDFLib/rdflib",
76-
"http://example.org",
77-
"http://example.org",
78-
),
79-
TestSpec(
80-
"http://example.com/RDFLib/rdflib",
81-
"http://example.org/",
82-
"http://example.org/",
83-
),
84-
]
85-
86-
for test in tests:
87-
(base, url, result) = test
88-
with self.subTest(base=base, url=url):
89-
self.assertEqual(norm_url(base, url), result)
21+
),
22+
("http://example.org/", "/one", "http://example.org/one"),
23+
("http://example.org/", "/one#", "http://example.org/one#"),
24+
("http://example.org/one", "two", "http://example.org/two"),
25+
("http://example.org/one/", "two", "http://example.org/one/two"),
26+
(
27+
"http://example.org/",
28+
"http://example.net/one",
29+
"http://example.net/one",
30+
),
31+
(
32+
"",
33+
"1 2 3",
34+
"1 2 3",
35+
),
36+
(
37+
"http://example.org/",
38+
"http://example.org//one",
39+
"http://example.org//one",
40+
),
41+
("", "http://example.org", "http://example.org"),
42+
("", "http://example.org/", "http://example.org/"),
43+
("", "mailto:[email protected]", "mailto:[email protected]"),
44+
(
45+
"http://example.org/",
46+
47+
48+
),
49+
("http://example.org/a/b/c", "../../z", "http://example.org/z"),
50+
("http://example.org/a/b/c", "../", "http://example.org/a/"),
51+
(
52+
"",
53+
"git+ssh://example.com:1231/some/thing",
54+
"git+ssh://example.com:1231/some/thing",
55+
),
56+
(
57+
"git+ssh://example.com:1231/some/thing",
58+
"",
59+
"git+ssh://example.com:1231/some/thing",
60+
),
61+
(
62+
"http://example.com/RDFLib/rdflib",
63+
"http://example.org",
64+
"http://example.org",
65+
),
66+
(
67+
"http://example.com/RDFLib/rdflib",
68+
"http://example.org/",
69+
"http://example.org/",
70+
),
71+
],
72+
)
73+
def test_norm_url_xfail(base: str, url: str, expected_result: str) -> None:
74+
assert expected_result == norm_url(base, url)

0 commit comments

Comments
 (0)