unittestdb
ensembl.utils.database.unittestdb
¶
Unit testing database handler.
This module provides the main class to create and drop testing databases, populating them from preexisting dumps (if supplied).
Examples:
>>> from ensembl.utils.database import UnitTestDB
>>> # For more safety use the context manager (automatically drops the database even if things go wrong):
>>> with UnitTestDB("mysql://user:passwd@mysql-server:4242/", "path/to/dumps", "my_db") as test_db:
>>> dbc = test_db.dbc
>>> # If you know what you are doing you can also control when the test_db is dropped:
>>> test_db = UnitTestDB("mysql://user:passwd@mysql-server:4242/", "path/to/dumps", "my_db")
>>> # You can access the database via test_db.dbc, for instance:
>>> dbc = test_db.dbc
>>> # At the end do not forget to drop the database
>>> test_db.drop()
TEST_USERNAME = os.environ.get('USER', 'pytestuser')
module-attribute
¶
UnitTestDB
¶
Creates and connects to a new test database, applying the schema and importing the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_url
|
StrURL
|
URL of the server hosting the database. |
required |
metadata
|
MetaData | None
|
Use this metadata to create the schema instead of using an SQL schema file. |
None
|
dump_dir
|
StrPath | None
|
Directory path with the database schema in |
None
|
name
|
str | None
|
Name to give to the new database. If not provided, the last directory name of |
None
|
tmp_path
|
StrPath | None
|
Temp dir where the test db is created if using SQLite (otherwise use current dir). |
None
|
Attributes:
Name | Type | Description |
---|---|---|
dbc |
Database connection handler. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If |
Source code in src/ensembl/utils/database/unittestdb.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
dbc = DBConnection(db_url, connect_args=connect_args, reflect=False)
instance-attribute
¶
drop()
¶
Drops the database.
Source code in src/ensembl/utils/database/unittestdb.py
151 152 153 154 155 |
|