1
- import logging
2
1
import unittest
2
+ from unittest .mock import patch
3
3
4
4
from rdflib import (
5
5
ConjunctiveGraph ,
6
6
Literal ,
7
7
URIRef ,
8
+ plugin
8
9
)
9
- from rdflib import plugin
10
10
from rdflib .store import Store
11
11
12
12
from rdflib_sqlalchemy import registerplugins
13
13
14
14
15
- _logger = logging .getLogger (__name__ )
16
-
17
15
michel = URIRef (u"michel" )
18
- tarek = URIRef (u"tarek" )
19
- bob = URIRef (u"bob" )
20
16
likes = URIRef (u"likes" )
21
- hates = URIRef (u"hates" )
22
17
pizza = URIRef (u"pizza" )
23
- cheese = URIRef (u"cheese" )
24
18
25
19
26
20
class mock_cursor ():
27
21
def execute (x ):
28
22
raise Exception ("Forced exception" )
29
23
30
24
25
+ class ConfigTest (unittest .TestCase ):
26
+ '''
27
+ Test configuration with a dict
28
+ '''
29
+
30
+ def setUp (self ):
31
+ self .store = plugin .get ("SQLAlchemy" , Store )()
32
+ self .graph = ConjunctiveGraph (self .store )
33
+
34
+ def tearDown (self ):
35
+ self .graph .close ()
36
+
37
+ def test_success (self ):
38
+ with patch ('rdflib_sqlalchemy.store.sqlalchemy' ) as p :
39
+ self .graph .open ({'url' : 'sqlite://' , 'random_key' : 'something' }, create = True )
40
+ p .create_engine .assert_called_with ('sqlite://' , random_key = 'something' )
41
+
42
+ def test_no_url (self ):
43
+ with patch ('rdflib_sqlalchemy.store.sqlalchemy' ) as p :
44
+ with self .assertRaisesRegex (Exception , '.*url.*' ):
45
+ self .graph .open ({'random_key' : 'something' }, create = True )
46
+
47
+
31
48
class SQLATestCase (unittest .TestCase ):
32
49
identifier = URIRef ("rdflib_test" )
33
50
dburi = Literal ("sqlite://" )
@@ -46,26 +63,26 @@ def test_registerplugins(self):
46
63
# I doubt this is quite right for a fresh pip installation,
47
64
# this test is mainly here to fill a coverage gap.
48
65
registerplugins ()
49
- self .assert_ (plugin .get ("SQLAlchemy" , Store ) is not None )
66
+ self .assertIsNotNone (plugin .get ("SQLAlchemy" , Store ))
50
67
p = plugin ._plugins
51
- self .assert_ (("SQLAlchemy" , Store ) in p , p )
68
+ self .assertIn (("SQLAlchemy" , Store ), p )
52
69
del p [("SQLAlchemy" , Store )]
53
70
plugin ._plugins = p
54
71
registerplugins ()
55
- self .assert_ (("SQLAlchemy" , Store ) in p , p )
72
+ self .assertIn (("SQLAlchemy" , Store ), p )
56
73
57
74
def test_namespaces (self ):
58
- self .assert_ (list (self .graph .namespaces ()) != [])
75
+ self .assertNotEqual (list (self .graph .namespaces ()), [])
59
76
60
77
def test_contexts_without_triple (self ):
61
- self .assert_ (list (self .graph .contexts ()) == [])
78
+ self .assertEqual (list (self .graph .contexts ()), [])
62
79
63
80
def test_contexts_with_triple (self ):
64
81
statemnt = (michel , likes , pizza )
65
- self .assert_ ( self .graph .contexts (triple = statemnt ) != [])
82
+ self .assertEqual ( list ( self .graph .contexts (triple = statemnt )), [])
66
83
67
84
def test__len (self ):
68
- self .assert_ (self .store .__len__ () == 0 )
85
+ self .assertEqual (self .store .__len__ (), 0 )
69
86
70
87
def test__remove_context (self ):
71
88
self .store ._remove_context (self .identifier )
0 commit comments