Skip to content

Commit d43fbb9

Browse files
committed
Align setUp and tearDown type signatures with unitest and rdflib.plugin
The references below indicate the type requirements' sources. When reviewing subclasses of `GraphTestCase`, `setUp` and `tearDown` did no further work than the parent class `GraphTestCase` once the signatures were aligned with `typeshed.stdlib`, so the methods were removed. This patch was driven by the following command after activating type review on `setUp` and `tearDown` (adding `-> None`): ```bash mypy test/test_sqlalchemy_sqlite.py ``` This patch was then tested with the following command after identifying sibling ("cousin?") classes of the SQLite test. This command raised no errors after deactivating type review (adding `# type: ignore`) on a package that does not currently provide type signatures: ```bash mypy \ test/test_sqlalchemy_mysql.py \ test/test_sqlalchemy_postgresql.py \ test/test_sqlalchemy_postgresql_pg8000.py \ test/test_sqlalchemy_sqlite.py ``` Disclaimer: Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose. References: * https://github.com/RDFLib/rdflib/blob/7.1.1/rdflib/plugin.py#L128 * https://github.com/python/typeshed/blob/b40eb642e00c538e29fb037992eb4b21d9ff108c/stdlib/unittest/case.pyi#L119-L120 Signed-off-by: Alex Nelson <[email protected]>
1 parent 99f4689 commit d43fbb9

5 files changed

+10
-69
lines changed

test/graph_case.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class GraphTestCase(unittest.TestCase):
1111
storetest = True
1212
identifier = URIRef("rdflib_test")
1313

14+
# storename is expected to be assigned in subclasses.
15+
storename: str
16+
uri: str = "sqlite://"
17+
1418
michel = URIRef(u"michel")
1519
tarek = URIRef(u"tarek")
1620
bob = URIRef(u"bob")
@@ -23,13 +27,13 @@ class GraphTestCase(unittest.TestCase):
2327
namespace_dct = "http://purl.org/dc/terms/"
2428
namespace_saws = "http://purl.org/saws/ontology#"
2529

26-
def setUp(self, uri="sqlite://", storename=None):
27-
store = plugin.get(storename, Store)(identifier=self.identifier)
30+
def setUp(self) -> None:
31+
store = plugin.get(self.storename, Store)(identifier=self.identifier)
2832
self.graph = Graph(store, identifier=self.identifier)
29-
self.graph.open(uri, create=True)
33+
self.graph.open(self.uri, create=True)
3034

31-
def tearDown(self, uri="sqlite://"):
32-
self.graph.destroy(uri)
35+
def tearDown(self) -> None:
36+
self.graph.destroy(self.uri)
3337
self.graph.close()
3438

3539
def addStuff(self):

test/test_sqlalchemy_mysql.py

-13
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,13 @@ class SQLAMySQLGraphTestCase(graph_case.GraphTestCase):
3939
uri = sqlalchemy_url
4040
create = True
4141

42-
def setUp(self):
43-
super(SQLAMySQLGraphTestCase, self).setUp(uri=self.uri, storename=self.storename)
44-
45-
def tearDown(self):
46-
super(SQLAMySQLGraphTestCase, self).tearDown(uri=self.uri)
47-
4842

4943
class SQLAMySQLContextTestCase(context_case.ContextTestCase):
5044
storetest = True
5145
storename = "SQLAlchemy"
5246
uri = sqlalchemy_url
5347
create = True
5448

55-
def setUp(self):
56-
super(SQLAMySQLContextTestCase, self).setUp(
57-
uri=self.uri, storename=self.storename)
58-
59-
def tearDown(self):
60-
super(SQLAMySQLContextTestCase, self).tearDown(uri=self.uri)
61-
6249
def testLenInMultipleContexts(self):
6350
pytest.skip("Known issue.")
6451

test/test_sqlalchemy_postgresql.py

-18
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,13 @@ class SQLAPgSQLGraphTestCase(graph_case.GraphTestCase):
3030
uri = sqlalchemy_url
3131
create = True
3232

33-
def setUp(self):
34-
super(SQLAPgSQLGraphTestCase, self).setUp(
35-
uri=self.uri,
36-
storename=self.storename,
37-
)
38-
39-
def tearDown(self):
40-
super(SQLAPgSQLGraphTestCase, self).tearDown(uri=self.uri)
41-
4233

4334
class SQLAPgSQLContextTestCase(context_case.ContextTestCase):
4435
storetest = True
4536
storename = "SQLAlchemy"
4637
uri = sqlalchemy_url
4738
create = True
4839

49-
def setUp(self):
50-
super(SQLAPgSQLContextTestCase, self).setUp(
51-
uri=self.uri,
52-
storename=self.storename,
53-
)
54-
55-
def tearDown(self):
56-
super(SQLAPgSQLContextTestCase, self).tearDown(uri=self.uri)
57-
5840
def testLenInMultipleContexts(self):
5941
pytest.skip("Known issue.")
6042

test/test_sqlalchemy_postgresql_pg8000.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77
try:
8-
import pg8000
8+
import pg8000 # type: ignore
99
assert pg8000 is not None
1010
except ImportError:
1111
pytest.skip("pg8000 not installed, skipping PgSQL tests",
@@ -33,15 +33,6 @@ class SQLAPgSQLGraphTestCase(graph_case.GraphTestCase):
3333
uri = sqlalchemy_url
3434
create = True
3535

36-
def setUp(self):
37-
"""Setup."""
38-
super(SQLAPgSQLGraphTestCase, self).setUp(
39-
uri=self.uri, storename=self.storename)
40-
41-
def tearDown(self):
42-
"""Teardown."""
43-
super(SQLAPgSQLGraphTestCase, self).tearDown(uri=self.uri)
44-
4536

4637
class SQLAPgSQLContextTestCase(context_case.ContextTestCase):
4738
"""Context test case."""
@@ -51,15 +42,6 @@ class SQLAPgSQLContextTestCase(context_case.ContextTestCase):
5142
uri = sqlalchemy_url
5243
create = True
5344

54-
def setUp(self):
55-
"""Setup."""
56-
super(SQLAPgSQLContextTestCase, self).setUp(
57-
uri=self.uri, storename=self.storename)
58-
59-
def tearDown(self):
60-
"""Teardown."""
61-
super(SQLAPgSQLContextTestCase, self).tearDown(uri=self.uri)
62-
6345
def testLenInMultipleContexts(self):
6446
"""Test lin in multiple contexts, known issue."""
6547
pytest.skip("Known issue.")

test/test_sqlalchemy_sqlite.py

-14
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,12 @@ class SQLASQLiteGraphTestCase(graph_case.GraphTestCase):
2222
storename = "SQLAlchemy"
2323
uri = sqlalchemy_url
2424

25-
def setUp(self):
26-
super(SQLASQLiteGraphTestCase, self).setUp(
27-
uri=self.uri, storename=self.storename)
28-
29-
def tearDown(self):
30-
super(SQLASQLiteGraphTestCase, self).tearDown(uri=self.uri)
31-
3225

3326
class SQLASQLiteContextTestCase(context_case.ContextTestCase):
3427
storetest = True
3528
storename = "SQLAlchemy"
3629
uri = sqlalchemy_url
3730

38-
def setUp(self):
39-
super(SQLASQLiteContextTestCase, self).setUp(
40-
uri=self.uri, storename=self.storename)
41-
42-
def tearDown(self):
43-
super(SQLASQLiteContextTestCase, self).tearDown(uri=self.uri)
44-
4531
def testLenInMultipleContexts(self):
4632
pytest.skip("Known issue.")
4733

0 commit comments

Comments
 (0)