Utilities for developing EHR utilities
Even utilities need utilities!
Functions
fake_files- provides test doubles for tsv filesfake_tables- provides test doubles for SQLite tables
Installation
pip install ehr-utils-utils
Usage
fake_files
The fake_files context manager takes tables (list[list[str]]), produces temporary tsv files from them, and yields the filenames. The temporary files will be deleted when the context is exited.
Example usage:
from ehr_utils_utils import fake_files
def test_my_parse_fcn():
table = [["a", "b"], ["1", "2"]]
with fake_files(table) as filenames:
my_parse_fcn(filenames[0])
...
fake_tables
The fake_tables context manager takes a dictionary mapping table names to their contents (dict[str, list[list[Any]]]), produces an in-memory SQLite database, and yields the connection. When the context is exited, connection will be closed, and the memory will be recycled.
Example usage:
from ehr_utils_utils import fake_tables
def test_my_sql_query():
test_table = [["a", "b"], ["1", "2"], ["3", "4"]]
with fake_tables({"my_table": test_table}) as connection:
result = connection.execute("SELECT a FROM my_table WHERE b = '2'").fetchone()
assert result == ("1",)
Alternatively, you can also use dynamic keyword arguments to specify the table name(s):
from ehr_utils_utils import fake_tables
def test_my_sql_query():
test_table = [["a", "b"], ["1", "2"], ["3", "4"]]
with fake_tables(my_table=test_table) as connection:
result = connection.execute("SELECT a FROM my_table WHERE b = '2'").fetchone()
assert result == ("1",)
Development
We welcome contributions! Before opening a pull request, please confirm that existing regression tests pass:
python -m pytest tests/
Deployment
Metadata
Release files for ehr-utils-utils 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ehr_utils_utils-0.2.0.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ehr_utils_utils-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.7 kB
Release files / ehr_utils_utils-0.2.0.tar.gz
| Download URL | ehr_utils_utils-0.2.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a937ab694187483a6e1b208fe2f35cb2b0d9f7415b8bb7394265d2db9416123
|
|
BLAKE2b-256 checksum How to use checksums |
738585d13e13beda9c2359a4ba8e82d14fdf5c66255265c09060bb47a74165b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Release files / ehr_utils_utils-0.2.0-py3-none-any.whl
| Download URL | ehr_utils_utils-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf6255026e2e70bf07c64f1a004809bbd3c7933c96f7ed8a1232e0c55ba8d8a9
|
|
BLAKE2b-256 checksum How to use checksums |
97c03dbe43ed81b0f303d764c70a566309b662a36da970fc777695bc8b09d9d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|