File: configdb.py

package info (click to toggle)
python-mysqldb 1.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 512 kB
  • sloc: python: 3,295; ansic: 2,467; makefile: 6
file content (24 lines) | stat: -rw-r--r-- 580 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Configure database connection for tests."""

from os import environ, path

tests_path = path.dirname(__file__)
conf_file = environ.get('TESTDB', 'default.cnf')
conf_path = path.join(tests_path, conf_file)
connect_kwargs = dict(
    read_default_file = conf_path,
    read_default_group = "MySQLdb-tests",
)


def connection_kwargs(kwargs):
    db_kwargs = connect_kwargs.copy()
    db_kwargs.update(kwargs)
    return db_kwargs


def connection_factory(**kwargs):
    import MySQLdb
    db_kwargs = connection_kwargs(kwargs)
    db = MySQLdb.connect(**db_kwargs)
    return db