Skip to main content

Utilities for building and maintaining EHR utilities.

Project description

Utilities for developing EHR utilities

Even utilities need utilities!

Functions

  • fake_files - provides test doubles for tsv files
  • fake_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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ehr_utils_utils-0.2.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ehr_utils_utils-0.2.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file ehr_utils_utils-0.2.0.tar.gz.

File metadata

  • Download URL: ehr_utils_utils-0.2.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for ehr_utils_utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a937ab694187483a6e1b208fe2f35cb2b0d9f7415b8bb7394265d2db9416123
MD5 e74ad00ed6401976575ff851a0878203
BLAKE2b-256 738585d13e13beda9c2359a4ba8e82d14fdf5c66255265c09060bb47a74165b1

See more details on using hashes here.

File details

Details for the file ehr_utils_utils-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ehr_utils_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf6255026e2e70bf07c64f1a004809bbd3c7933c96f7ed8a1232e0c55ba8d8a9
MD5 94223da45be6c01c962eddf971b04051
BLAKE2b-256 97c03dbe43ed81b0f303d764c70a566309b662a36da970fc777695bc8b09d9d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page