Skip to content

Commit 989ad89

Browse files
authored
Use pytest in one more test and update contributing guide (#2919)
* Update to current GitHub search The old URL gave an error "Unrecognised qualifier" because the extension qualifier is no longer used in the code search query. The page suggests using `path:*.py` instead, which I've combined with the existing path into `path:test/**.py`. More information on the search: https://docs.github.com/en/search-github/github-code-search/understanding-github-code-search-syntax#path-qualifier * Help contributors with finding xfail tests Using the same approach as with the suggestion to replace unittest with pytest. * Replace unittest with pytest in another test file Also simplifying by removing support for Python <2.7.
1 parent 1d44438 commit 989ad89

File tree

2 files changed

+40
-47
lines changed

2 files changed

+40
-47
lines changed

docs/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Some ways in which you can contribute to RDFLib are:
1212
[![GitHub issues](https://img.shields.io/github/issues/RDFLib/rdflib)](https://github.com/RDFLib/rdflib/issues)
1313
- Fix
1414
[expected failure](https://docs.pytest.org/en/latest/how-to/skipping.html#xfail-mark-test-functions-as-expected-to-fail)
15-
tests.
15+
tests: [![GitHub search query](https://img.shields.io/badge/GitHub-search-green)](https://github.com/search?q=xfail+repo%3ARDFLib%2Frdflib+path%3Atest%2F**.py&amp%3Btype=code&type=code)
1616
- Add additional
1717
[expected failure](https://docs.pytest.org/en/latest/how-to/skipping.html#xfail-mark-test-functions-as-expected-to-fail)
1818
tests for open issues:
@@ -29,7 +29,7 @@ Some ways in which you can contribute to RDFLib are:
2929
based tests to
3030
[`pytest`](https://docs.pytest.org/en/latest/)
3131
based tests:
32-
[![GitHub search query](https://img.shields.io/badge/GitHub-search-green)](https://github.com/search?q=unittest+repo%3ARDFLib%2Frdflib+extension%3Apy+path%3Atest%2F&type=Code)
32+
[![GitHub search query](https://img.shields.io/badge/GitHub-search-green)](https://github.com/search?q=unittest+repo%3ARDFLib%2Frdflib+path%3Atest%2F**.py&type=code)
3333
- Add, correct or improve docstrings:
3434
[![rtd latest](https://img.shields.io/badge/docs-latest-informational)](https://rdflib.readthedocs.io/en/latest/)
3535
- Update the RDFLib Wikipedia entry:

test/test_issues/test_issue379.py

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,51 @@
1-
import unittest
1+
"""
2+
Tests for GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379
3+
"""
4+
5+
import pytest
26

37
import rdflib
48

5-
prefix_data = """
6-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
7-
@prefix : <http://www.example.com#> .
89

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+
1018

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#> .
1424
15-
<http://www.example.com#base> a rdf:class .
16-
"""
25+
<http://www.example.com#base> a rdf:class .
26+
"""
1727

1828

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()
2832

2933

30-
class TestBaseAllowsHash(TestCase):
34+
def test_parse_successful_prefix_with_hash(graph, prefix_data):
3135
"""
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
3339
"""
40+
graph.parse(data=prefix_data, format="n3")
41+
assert isinstance(next(graph.subjects()), rdflib.URIRef)
3442

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

Comments
 (0)