Metadata-Version: 2.3
Name: aibs-informatics-test-resources
Version: 0.0.4
Summary: unit test resources for AIBS informatics packages
Project-URL: Documentation, https://.github.io/aibs-informatics-test-resources/
Project-URL: Homepage, https://github.com/AllenInstitute/aibs-informatics-test-resources/
Project-URL: Issues, https://github.com/AllenInstitute/aibs-informatics-test-resources/issues
Project-URL: Repository, https://github.com/AllenInstitute/aibs-informatics-test-resources/
Author: AIBS Informatics Group
Maintainer-email: AIBS Informatics Group <marmot@alleninstitute.onmicrosoft.com>
License: Allen Institute Software License – This software license is the 2-clause BSD 
        license plus a third clause that prohibits redistribution and use for 
        commercial purposes without further permission. 
        
        Copyright © 2024. Allen Institute.  All rights reserved.
        
        Redistribution and use in source and binary forms, with or without 
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this 
        list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice, 
        this list of conditions and the following disclaimer in the documentation 
        and/or other materials provided with the distribution.
        
        3. Redistributions and use for commercial purposes are not permitted without 
        the Allen Institute’s written permission. For purposes of this license, 
        commercial purposes are the incorporation of the Allen Institute's software 
        into anything for which you will charge fees or other compensation or use of 
        the software to perform a commercial service for a third party. Contact 
        terms@alleninstitute.org for commercial licensing opportunities.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
        ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
        WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Requires-Python: >=3.9
Requires-Dist: black==23.11.0
Requires-Dist: coverage[toml]~=7.3
Requires-Dist: flake8~=6.1.0
Requires-Dist: isort~=5.10
Requires-Dist: mypy~=1.6
Requires-Dist: pytest-cov
Requires-Dist: pytest~=7.4
Provides-Extra: release
Requires-Dist: build; extra == 'release'
Requires-Dist: bump-my-version; extra == 'release'
Requires-Dist: twine; extra == 'release'
Requires-Dist: wheel; extra == 'release'
Description-Content-Type: text/markdown

# AIBS Informatics Test Resources

[![Build Status](https://github.com/AllenInstitute/aibs-informatics-test-resources/actions/workflows/build.yml/badge.svg)](https://github.com/AllenInstitute/aibs-informatics-test-resources/actions/workflows/build.yml)

---

## 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`](./src/aibs_informatics_test_resources/base.py) 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`](./src/aibs_informatics_test_resources/utils.py): 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:

```python
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](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](https://alleninstitute.org/terms-of-use/).