Skip to main content

unit test resources for AIBS informatics packages

Project description

AIBS Informatics Test Resources

Build Status codecov

Overview

This package provides a collection of utilities and resources to facilitate testing in various AIBS Informatics projects. It includes base test classes, mock utilities, and other helpful tools.

Available Modules

Base Test Class

The BaseTest class provides a base class for creating unit tests with common setup and teardown functionality. It includes the following features:

  • Environment Management:

    • set_env_vars(*key_values_pairs: Tuple[str, Optional[str]]): Set environment variables for the duration of the test.
    • reset_environ: Class variable to reset environment variables after each test.
  • Temporary Files and Directories:

    • tmp_path(basename: Optional[str] = None) -> Path: Create a temporary directory.
    • tmp_file(basename: Optional[str] = None, dirname: Optional[str] = None, content: Optional[str] = None) -> Path: Create a temporary file with optional content.
  • Assertions:

    • assertStringPattern(pattern: str, actual: str): Assert that a string matches a given regex pattern.
    • assertJsonEqual(first: Union[dict, str, int, list], second: Union[dict, str, int, list]): Assert that two JSON objects are equal.
    • assertListEqual(list1: List[Any], list2: List[Any], msg: Any = None, presort: bool = False, **presort_kwargs) -> None: Assert that two lists are equal, with an option to sort them before comparison.
  • Mocking:

    • create_patch(name: str, **kwargs) -> MagicMock: Create a patch for a given name and add it to the cleanup list.
  • Context Managers:

    • chdir(destination: Union[str, Path]): Context manager to change the current working directory temporarily.

Mock Utilities

  • does_not_raise: A context manager for assertions that no exceptions are raised.
  • reset_environ_after_test: A decorator to reset environment variables after a test.

Example Usage

Here is an example of how to use the BaseTest class in your tests:

from aibs_informatics_test_resources import BaseTest

class MyTest(BaseTest):
    def test_example(self):
        self.assertEqual(1 + 1, 2)
    
    def test_use_temp_file(self):
        with self.tmp_file(content="Hello, World!") as tmp_file:
            self.assertTrue(tmp_file.exists())
            self.assertEqual(tmp_file.read_text(), "Hello, World!")

Contributing

Any and all PRs are welcome. Please see CONTRIBUTING.md for more information.

Licensing

This software is licensed under the Allen Institute Software License, which is the 2-clause BSD license plus a third clause that prohibits redistribution and use for commercial purposes without further permission. For more information, please visit Allen Institute Terms of Use.

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

aibs_informatics_test_resources-0.1.1.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file aibs_informatics_test_resources-0.1.1.tar.gz.

File metadata

File hashes

Hashes for aibs_informatics_test_resources-0.1.1.tar.gz
Algorithm Hash digest
SHA256 38ed39e1fa9644133903c6cd3e24a26ab193a44d4d47fb21aa18635dc53f6205
MD5 28c0872964c95061d336922d1c0512a6
BLAKE2b-256 53701dc8b0707e457f2005a5a68f0aadeff64a48582b6084ae07b5a34ca67b59

See more details on using hashes here.

Provenance

The following attestation bundles were made for aibs_informatics_test_resources-0.1.1.tar.gz:

Publisher: release.yml on AllenInstitute/aibs-informatics-test-resources

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aibs_informatics_test_resources-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aibs_informatics_test_resources-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5b69ac3e51c36123297627c63edfac13828128033868c56d4bb06747724bfc2
MD5 3ec1012761142e61c153f567ed86070b
BLAKE2b-256 edb8f9773b5ba17c0f94267abfdc35a97f5236ed89b8763923d7ae9ce5ca95b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for aibs_informatics_test_resources-0.1.1-py3-none-any.whl:

Publisher: release.yml on AllenInstitute/aibs-informatics-test-resources

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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