MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / PyMySQLTestCase

Class PyMySQLTestCase

pymysql/tests/base.py:10–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class PyMySQLTestCase(unittest.TestCase):
11 # You can specify your test environment creating a file named
12 # "databases.json" or editing the `databases` variable below.
13 fname = os.path.join(os.path.dirname(__file__), "databases.json")
14 if os.path.exists(fname):
15 with open(fname) as f:
16 databases = json.load(f)
17 else:
18 databases = [
19 {
20 "host": "localhost",
21 "user": "root",
22 "passwd": "",
23 "database": "test1",
24 "use_unicode": True,
25 "local_infile": True,
26 },
27 {"host": "localhost", "user": "root", "passwd": "", "database": "test2"},
28 ]
29
30 def mysql_server_is(self, conn, version_tuple):
31 """Return True if the given connection is on the version given or
32 greater.
33
34 This only checks the server version string provided when the
35 connection is established, therefore any check for a version tuple
36 greater than (5, 5, 5) will always fail on MariaDB, as it always
37 starts with 5.5.5, e.g. 5.5.5-10.7.1-MariaDB-1:10.7.1+maria~focal.
38
39 e.g.::
40
41 if self.mysql_server_is(conn, (5, 6, 4)):
42 # do something for MySQL 5.6.4 and above
43 """
44 server_version = conn.get_server_info()
45 server_version_tuple = tuple(
46 (int(dig) if dig is not None else 0)
47 for dig in re.match(r"(\d+)\.(\d+)\.(\d+)", server_version).group(1, 2, 3)
48 )
49 return server_version_tuple >= version_tuple
50
51 def get_mysql_vendor(self, conn):
52 server_version = conn.get_server_info()
53
54 if "MariaDB" in server_version:
55 return "mariadb"
56
57 return "mysql"
58
59 _connections = None
60
61 @property
62 def connections(self):
63 if self._connections is None:
64 self._connections = []
65 for params in self.databases:
66 self._connections.append(pymysql.connect(**params))
67 self.addCleanup(self._teardown_connections)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected