|
1 |
| -import unittest |
| 1 | +""" |
| 2 | +Tests for GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379 |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
2 | 6 |
|
3 | 7 | import rdflib
|
4 | 8 |
|
5 |
| -prefix_data = """ |
6 |
| - @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
7 |
| - @prefix : <http://www.example.com#> . |
8 | 9 |
|
9 |
| - <http://www.example.com#prefix> a rdf:class .""" |
| 10 | +@pytest.fixture |
| 11 | +def prefix_data(): |
| 12 | + return """ |
| 13 | + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
| 14 | + @prefix : <http://www.example.com#> . |
| 15 | +
|
| 16 | + <http://www.example.com#prefix> a rdf:class .""" |
| 17 | + |
10 | 18 |
|
11 |
| -base_data = """ |
12 |
| - @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
13 |
| - @base <http://www.example.com#> . |
| 19 | +@pytest.fixture |
| 20 | +def base_data(): |
| 21 | + return """ |
| 22 | + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
| 23 | + @base <http://www.example.com#> . |
14 | 24 |
|
15 |
| - <http://www.example.com#base> a rdf:class . |
16 |
| - """ |
| 25 | + <http://www.example.com#base> a rdf:class . |
| 26 | + """ |
17 | 27 |
|
18 | 28 |
|
19 |
| -class TestCase(unittest.TestCase): |
20 |
| - def assertIsInstance(self, obj, cls, msg=None, *args, **kwargs): # noqa: N802 |
21 |
| - """Python < v2.7 compatibility. Assert 'obj' is instance of 'cls'""" |
22 |
| - try: |
23 |
| - f = super(TestCase, self).assertIsInstance |
24 |
| - except AttributeError: |
25 |
| - self.assertTrue(isinstance(obj, cls), *args, **kwargs) |
26 |
| - else: |
27 |
| - f(obj, cls, *args, **kwargs) |
| 29 | +@pytest.fixture |
| 30 | +def graph(): |
| 31 | + return rdflib.Graph() |
28 | 32 |
|
29 | 33 |
|
30 |
| -class TestBaseAllowsHash(TestCase): |
| 34 | +def test_parse_successful_prefix_with_hash(graph, prefix_data): |
31 | 35 | """
|
32 |
| - GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379 |
| 36 | + Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is |
| 37 | + permitted for an IRIREF: |
| 38 | + http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID |
33 | 39 | """
|
| 40 | + graph.parse(data=prefix_data, format="n3") |
| 41 | + assert isinstance(next(graph.subjects()), rdflib.URIRef) |
34 | 42 |
|
35 |
| - def setUp(self): |
36 |
| - self.g = rdflib.Graph() |
37 |
| - |
38 |
| - def test_parse_successful_prefix_with_hash(self): |
39 |
| - """ |
40 |
| - Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is |
41 |
| - permitted for an IRIREF: |
42 |
| - http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID |
43 |
| - """ |
44 |
| - self.g.parse(data=prefix_data, format="n3") |
45 |
| - self.assertIsInstance(next(self.g.subjects()), rdflib.URIRef) |
46 |
| - |
47 |
| - def test_parse_successful_base_with_hash(self): |
48 |
| - """ |
49 |
| - Test parse of '@base' namespace directive to allow a trailing hash '#', as is |
50 |
| - permitted for an '@prefix' since both allow an IRIREF: |
51 |
| - http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base |
52 |
| - """ |
53 |
| - self.g.parse(data=base_data, format="n3") |
54 |
| - self.assertIsInstance(next(self.g.subjects()), rdflib.URIRef) |
55 |
| - |
56 |
| - |
57 |
| -if __name__ == "__main__": |
58 |
| - unittest.main() |
| 43 | + |
| 44 | +def test_parse_successful_base_with_hash(graph, base_data): |
| 45 | + """ |
| 46 | + Test parse of '@base' namespace directive to allow a trailing hash '#', as is |
| 47 | + permitted for an '@prefix' since both allow an IRIREF: |
| 48 | + http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base |
| 49 | + """ |
| 50 | + graph.parse(data=base_data, format="n3") |
| 51 | + assert isinstance(next(graph.subjects()), rdflib.URIRef) |
0 commit comments