testing
Testing Utilities for PlantDBLink
Provides a collection of helper classes and unittest mix‑ins that simplify writing tests for PlantDB databases. By offering temporary database clones and ready‑made test cases, it enables developers to create isolated, repeatable test environments without affecting the original data.
Key FeaturesLink
- TemporaryCloneDB: Creates a temporary copy of an existing PlantDB on disk, ensuring tests run against an isolated sandbox that is automatically cleaned up.
- DummyDBTestCase: A unittest.TestCase subclass that builds a lightweight dummy database containing a sample scan, fileset, and file, with convenience methods to retrieve them.
- FSDBTestCase: A unittest.TestCase subclass for real‑world datasets; it handles connecting, authenticating, and cleaning up a temporary FSDB instance.
- Helper methods (
get_test_db,get_test_scan,get_test_fileset,get_test_image_file,get_task_fileset, etc.) to quickly access common test objects and locate task‑specific filesets.
Usage ExamplesLink
>>> from plantdb.commons.testing import DummyDBTestCase
>>> class MyTest(DummyDBTestCase):
>>> def test_scan_properties(self):
>>> db = self.get_test_db()
>>> scan = self.get_test_scan()
>>> # Perform assertions on the scan object
>>> self.assertEqual(scan.name, "myscan_001")
DummyDBTestCase
Link
Bases: TestCase
A dummy test database.
Attributes:
| Name | Type | Description |
|---|---|---|
db |
FSDB
|
The temporary directory. |
tmpclone |
TemporaryCloneDB
|
A local temporary copy of a dummy test database. |
get_test_db
Link
get_test_db(db_path=None)
Return the test FSDB database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
If |
None
|
Returns:
| Type | Description |
|---|---|
FSDB
|
The database to test. |
Source code in plantdb/commons/testing.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
get_test_fileset
Link
get_test_fileset()
Return the default test Fileset object named 'fileset_001'.
Returns:
| Type | Description |
|---|---|
Scan
|
The default fileset instance to test. |
Source code in plantdb/commons/testing.py
151 152 153 154 155 156 157 158 159 160 161 | |
get_test_image_file
Link
get_test_image_file()
Return the default test File object named 'test_image'.
Returns:
| Type | Description |
|---|---|
File
|
The default image file instance to test. |
Source code in plantdb/commons/testing.py
163 164 165 166 167 168 169 170 171 172 173 | |
get_test_scan
Link
get_test_scan()
Return the default test Scan object named 'myscan_001'.
Returns:
| Type | Description |
|---|---|
Scan
|
The default scan instance to test. |
Source code in plantdb/commons/testing.py
139 140 141 142 143 144 145 146 147 148 149 | |
setUp
Link
setUp()
Set up a dummy database with fake scan, fileset & files.
Source code in plantdb/commons/testing.py
105 106 107 108 | |
tearDown
Link
tearDown()
Clean up after test.
Source code in plantdb/commons/testing.py
110 111 112 113 114 115 116 117 | |
FSDBTestCase
Link
Bases: TestCase
A local FSDB test database.
Attributes:
| Name | Type | Description |
|---|---|---|
db |
FSDB
|
The temporary test database with the 'real_plant_analyzed' dataset. |
get_task_fileset
Link
get_task_fileset(task_name)
Return the fileset for the corresponding task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the task to get the fileset for. |
required |
Returns:
| Type | Description |
|---|---|
Fileset
|
The |
Source code in plantdb/commons/testing.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
get_task_fileset_id
Link
get_task_fileset_id(task_name)
Return the fileset id for the corresponding task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the task to get the fileset for. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |
Source code in plantdb/commons/testing.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
get_test_db
Link
get_test_db()
Return the test FSDB database.
Source code in plantdb/commons/testing.py
198 199 200 201 202 | |
get_test_fileset
Link
get_test_fileset(fs_id)
Return the default test Fileset object named 'fileset_001'.
Returns:
| Type | Description |
|---|---|
Scan
|
The default fileset instance to test. |
Source code in plantdb/commons/testing.py
216 217 218 219 220 221 222 223 224 225 226 | |
get_test_scan
Link
get_test_scan()
Return the default test Scan object named 'real_plant_analyzed'.
Returns:
| Type | Description |
|---|---|
Scan
|
The default |
Source code in plantdb/commons/testing.py
204 205 206 207 208 209 210 211 212 213 214 | |
setUp
Link
setUp()
Set up a test database with the 'real_plant_analyzed' dataset.
Source code in plantdb/commons/testing.py
185 186 187 | |
tearDown
Link
tearDown()
Clean up after test.
Source code in plantdb/commons/testing.py
189 190 191 192 193 194 195 196 | |
TemporaryCloneDB
Link
TemporaryCloneDB(db_location)
Bases: object
Class for doing tests on a copy of a local DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Location of the source database to clone in the temporary folder. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
tmpdir |
TemporaryDirectory
|
The temporary directory. |
Source code in plantdb/commons/testing.py
83 84 85 | |