Skip to content

Commit

Permalink
Use pytest in one more test and update contributing guide (#2919)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ageorgou authored Oct 10, 2024
1 parent 1d44438 commit 989ad89
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Some ways in which you can contribute to RDFLib are:
[![GitHub issues](https://img.shields.io/github/issues/RDFLib/rdflib)](https://github.com/RDFLib/rdflib/issues)
- Fix
[expected failure](https://docs.pytest.org/en/latest/how-to/skipping.html#xfail-mark-test-functions-as-expected-to-fail)
tests.
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)
- Add additional
[expected failure](https://docs.pytest.org/en/latest/how-to/skipping.html#xfail-mark-test-functions-as-expected-to-fail)
tests for open issues:
Expand All @@ -29,7 +29,7 @@ Some ways in which you can contribute to RDFLib are:
based tests to
[`pytest`](https://docs.pytest.org/en/latest/)
based tests:
[![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)
[![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)
- Add, correct or improve docstrings:
[![rtd latest](https://img.shields.io/badge/docs-latest-informational)](https://rdflib.readthedocs.io/en/latest/)
- Update the RDFLib Wikipedia entry:
Expand Down
83 changes: 38 additions & 45 deletions test/test_issues/test_issue379.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
import unittest
"""
Tests for GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379
"""

import pytest

import rdflib

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

<http://www.example.com#prefix> a rdf:class ."""
@pytest.fixture
def prefix_data():
return """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.example.com#> .
<http://www.example.com#prefix> a rdf:class ."""


base_data = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@base <http://www.example.com#> .
@pytest.fixture
def base_data():
return """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@base <http://www.example.com#> .
<http://www.example.com#base> a rdf:class .
"""
<http://www.example.com#base> a rdf:class .
"""


class TestCase(unittest.TestCase):
def assertIsInstance(self, obj, cls, msg=None, *args, **kwargs): # noqa: N802
"""Python < v2.7 compatibility. Assert 'obj' is instance of 'cls'"""
try:
f = super(TestCase, self).assertIsInstance
except AttributeError:
self.assertTrue(isinstance(obj, cls), *args, **kwargs)
else:
f(obj, cls, *args, **kwargs)
@pytest.fixture
def graph():
return rdflib.Graph()


class TestBaseAllowsHash(TestCase):
def test_parse_successful_prefix_with_hash(graph, prefix_data):
"""
GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379
Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is
permitted for an IRIREF:
http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID
"""
graph.parse(data=prefix_data, format="n3")
assert isinstance(next(graph.subjects()), rdflib.URIRef)

def setUp(self):
self.g = rdflib.Graph()

def test_parse_successful_prefix_with_hash(self):
"""
Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is
permitted for an IRIREF:
http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID
"""
self.g.parse(data=prefix_data, format="n3")
self.assertIsInstance(next(self.g.subjects()), rdflib.URIRef)

def test_parse_successful_base_with_hash(self):
"""
Test parse of '@base' namespace directive to allow a trailing hash '#', as is
permitted for an '@prefix' since both allow an IRIREF:
http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base
"""
self.g.parse(data=base_data, format="n3")
self.assertIsInstance(next(self.g.subjects()), rdflib.URIRef)


if __name__ == "__main__":
unittest.main()

def test_parse_successful_base_with_hash(graph, base_data):
"""
Test parse of '@base' namespace directive to allow a trailing hash '#', as is
permitted for an '@prefix' since both allow an IRIREF:
http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base
"""
graph.parse(data=base_data, format="n3")
assert isinstance(next(graph.subjects()), rdflib.URIRef)

0 comments on commit 989ad89

Please sign in to comment.