Debian Codegraph @

test/test_sqlalchemy_mysql.py

raw symbols SCIP
1 import logging
2 import os
3 import unittest
4
5 import pytest
6 from rdflib import Literal
7 from rdflib.graph import ConjunctiveGraph as Graph
8 from rdflib.store import NO_STORE, VALID_STORE
9 from rdflib.term import URIRef
10
11 from . import context_case
12 from . import graph_case
13
14
15 try:
16 import MySQLdb
17 assert MySQLdb
18 dialect = "mysqldb"
19 except ImportError:
20 pytest.skip("MySQLdb not found, skipping MySQL tests",
21 allow_module_level=True)
22
23
24 if os.environ.get("DB") != "mysql":
25 pytest.skip("MySQL not under test",
26 allow_module_level=True)
27
28 _logger = logging.getLogger(__name__)
29
30
31 sqlalchemy_url = Literal(os.environ.get(
32 "DBURI",
33 "mysql+%s://[email protected]:3306/test?charset=utf8" % dialect))
34
35
36 class SQLAMySQLGraphTestCase(graph_case.GraphTestCase):
37 storetest = True
38 storename = "SQLAlchemy"
39 uri = sqlalchemy_url
40 create = True
41
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
48
49 class SQLAMySQLContextTestCase(context_case.ContextTestCase):
50 storetest = True
51 storename = "SQLAlchemy"
52 uri = sqlalchemy_url
53 create = True
54
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
62 def testLenInMultipleContexts(self):
63 pytest.skip("Known issue.")
64
65
66 class SQLAMySQLIssueTestCase(unittest.TestCase):
67 storetest = True
68 storename = "SQLAlchemy"
69 uri = sqlalchemy_url
70
71 def test_issue_4(self):
72 ident = URIRef("rdflib_test")
73 g = Graph(store="SQLAlchemy", identifier=ident)
74 rt = g.open(self.uri, create=True)
75 if rt == NO_STORE:
76 g.open(self.uri, create=True)
77 else:
78 assert rt == VALID_STORE, "The underlying store is not valid: State: %s" % rt
79 g.destroy(self.uri)
80
81
82 if __name__ == "__main__":
83 unittest.main()