11import re
22import socket
3- import unittest
43from http .server import BaseHTTPRequestHandler , HTTPServer
54from test .utils import helper
65from test .utils .httpservermock import (
@@ -55,30 +54,28 @@ def test_graph_modify_fails(
5554 ), f"exception text { msg !r} does not match regex { pattern_str !r} "
5655
5756
58- class SPARQLStoreFakeDBPediaTestCase ( unittest . TestCase ) :
57+ class TestSPARQLStoreFakeDBPedia :
5958 store_name = "SPARQLStore"
6059 path : ClassVar [str ]
6160 httpmock : ClassVar [ServedBaseHTTPServerMock ]
6261
6362 @classmethod
64- def setUpClass (cls ) -> None :
65- super ().setUpClass ()
63+ def setup_class (cls ) -> None :
6664 cls .httpmock = ServedBaseHTTPServerMock ()
6765 cls .path = f"{ cls .httpmock .url } /sparql"
6866
6967 @classmethod
70- def tearDownClass (cls ) -> None :
71- super ().tearDownClass ()
68+ def teardown_class (cls ) -> None :
7269 cls .httpmock .stop ()
7370
74- def setUp (self ):
71+ def setup_method (self ):
7572 self .httpmock .reset ()
7673 self .graph = Graph (store = "SPARQLStore" )
7774 self .graph .open (self .path , create = True )
7875 ns = list (self .graph .namespaces ())
7976 assert len (ns ) > 0 , ns
8077
81- def tearDown (self ):
78+ def teardown_method (self ):
8279 self .graph .close ()
8380
8481 def test_Query (self ):
@@ -121,10 +118,10 @@ def unpacker(query, default_graph=None, named_graph=None):
121118 (mquery , _ , _ ) = unpacker (* args , * kwargs )
122119 for _ , uri in self .graph .namespaces ():
123120 assert mquery .count (f"<{ uri } >" ) == 1
124- self .assertEqual ( self . httpmock .mocks [MethodName .GET ].call_count , 1 )
121+ assert self .httpmock .mocks [MethodName .GET ].call_count == 1
125122 req = self .httpmock .requests [MethodName .GET ].pop (0 )
126- self . assertRegex ( req . path , r"^/sparql" )
127- self . assertIn ( query , req .path_query ["query" ][0 ])
123+ assert re . match ( r"^/sparql" , req . path )
124+ assert query in req .path_query ["query" ][0 ]
128125
129126 def test_initNs (self ):
130127 query = """\
@@ -184,10 +181,10 @@ def test_initNs(self):
184181 for i in res :
185182 assert type (i [0 ]) == Literal , i [0 ].n3 ()
186183
187- self .assertEqual ( self . httpmock .mocks [MethodName .GET ].call_count , 1 )
184+ assert self .httpmock .mocks [MethodName .GET ].call_count == 1
188185 req = self .httpmock .requests [MethodName .GET ].pop (0 )
189- self . assertRegex ( req . path , r"^/sparql" )
190- self . assertIn ( query , req .path_query ["query" ][0 ])
186+ assert re . match ( r"^/sparql" , req . path )
187+ assert query in req .path_query ["query" ][0 ]
191188
192189 def test_noinitNs (self ):
193190 query = """\
@@ -206,12 +203,12 @@ def test_noinitNs(self):
206203 {"Content-Type" : ["text/plain" ]},
207204 )
208205 )
209- with self . assertRaises (ValueError ):
206+ with pytest . raises (ValueError ):
210207 self .graph .query (query )
211- self .assertEqual ( self . httpmock .mocks [MethodName .GET ].call_count , 1 )
208+ assert self .httpmock .mocks [MethodName .GET ].call_count == 1
212209 req = self .httpmock .requests [MethodName .GET ].pop (0 )
213- self . assertRegex ( req . path , r"^/sparql" )
214- self . assertIn ( query , req .path_query ["query" ][0 ])
210+ assert re . match ( r"^/sparql" , req . path )
211+ assert query in req .path_query ["query" ][0 ]
215212
216213 def test_query_with_added_prolog (self ):
217214 prologue = """\
@@ -271,10 +268,10 @@ def test_query_with_added_prolog(self):
271268 res = helper .query_with_retry (self .graph , prologue + query )
272269 for i in res :
273270 assert type (i [0 ]) == Literal , i [0 ].n3 ()
274- self .assertEqual ( self . httpmock .mocks [MethodName .GET ].call_count , 1 )
271+ assert self .httpmock .mocks [MethodName .GET ].call_count == 1
275272 req = self .httpmock .requests [MethodName .GET ].pop (0 )
276- self . assertRegex ( req . path , r"^/sparql" )
277- self . assertIn ( query , req .path_query ["query" ][0 ])
273+ assert re . match ( r"^/sparql" , req . path )
274+ assert query in req .path_query ["query" ][0 ]
278275
279276 def test_query_with_added_rdf_prolog (self ):
280277 prologue = """\
@@ -335,10 +332,10 @@ def test_query_with_added_rdf_prolog(self):
335332 res = helper .query_with_retry (self .graph , prologue + query )
336333 for i in res :
337334 assert type (i [0 ]) == Literal , i [0 ].n3 ()
338- self .assertEqual ( self . httpmock .mocks [MethodName .GET ].call_count , 1 )
335+ assert self .httpmock .mocks [MethodName .GET ].call_count == 1
339336 req = self .httpmock .requests [MethodName .GET ].pop (0 )
340- self . assertRegex ( req . path , r"^/sparql" )
341- self . assertIn ( query , req .path_query ["query" ][0 ])
337+ assert re . match ( r"^/sparql" , req . path )
338+ assert query in req .path_query ["query" ][0 ]
342339
343340 def test_counting_graph_and_store_queries (self ):
344341 query = """
@@ -401,15 +398,15 @@ def test_counting_graph_and_store_queries(self):
401398
402399 assert count == 5 , "SPARQLStore() didn't return 5 records"
403400
404- self .assertEqual ( self . httpmock .mocks [MethodName .GET ].call_count , 2 )
401+ assert self .httpmock .mocks [MethodName .GET ].call_count == 2
405402 for _ in range (2 ):
406403 req = self .httpmock .requests [MethodName .GET ].pop (0 )
407- self . assertRegex ( req . path , r"^/sparql" )
408- self . assertIn ( query , req .path_query ["query" ][0 ])
404+ assert re . match ( r"^/sparql" , req . path )
405+ assert query in req .path_query ["query" ][0 ]
409406
410407
411- class SPARQLStoreUpdateTestCase ( unittest . TestCase ) :
412- def setUp (self ):
408+ class TestSPARQLStoreUpdate :
409+ def setup_method (self ):
413410 port = self .setup_mocked_endpoint ()
414411 self .graph = Graph (store = "SPARQLUpdateStore" , identifier = URIRef ("urn:ex" ))
415412 self .graph .open (
@@ -442,7 +439,7 @@ def setup_mocked_endpoint(self):
442439 )
443440 return port
444441
445- def tearDown (self ):
442+ def teardown_method (self ):
446443 self .graph .close ()
447444
448445 def test_Query (self ):
@@ -497,7 +494,7 @@ def do_GET(self):
497494 return
498495
499496
500- class SPARQLMockTests ( unittest . TestCase ) :
497+ class TestSPARQLMock :
501498 def test_query (self ):
502499 triples = {
503500 (RDFS .Resource , RDF .type , RDFS .Class ),
@@ -538,7 +535,3 @@ def test_query(self):
538535
539536 for _ , uri in graph .namespaces ():
540537 assert query .count (f"<{ uri } >" ) == 1
541-
542-
543- if __name__ == "__main__" :
544- unittest .main ()
0 commit comments