A Python package that simplifies the creation, execution, and analysis of unit tests.
Project description
test-helper-by-delica README
Purpose
This package simplifies the creation, execution, and analysis of unit tests in Python, in order to help programmers more efficiently develop and validate their software.
Installation
This package is available through the Python Package Index (PyPI).
One can easily download the package with the following pip install statement:
pip install test_helper_by_delica
If you are a contributor who needs to test changes from the development branch,
you can install the test version of the library from TestPyPI with the following command:
pip install --index-url https://test.pypi.org/simple/test_helper_by_delica
If you are not a contributor to this project, please only use the production version
that is deployed on PyPI and can be downloaded with pip install test_helper_by_delica.
The production version is the most stable release of the test helper package.
Getting Started
After installation, all we need to start using the package is a function that we want to test.
For a simple example, we can define a boolean function that always returns True.
def always_true():
return True
Now we can call the boolean testing function from the package to check whether always_true returns the expected result.
import test_helper_by_delica
test_helper_by_delica.test_bool_func(always_true, true_inputs=[()], test_desc="always true function")
This function call generates the following output:
TESTING ALWAYS TRUE FUNCTION
Test #1 of 1
Testing always_true function for input ()
SUCCESS: input=() -> output=True
ALL 1 TESTS COMPLETED FOR ALWAYS TRUE FUNCTION
Similarly, we can test a function that always returns False.
def always_false():
return False
test_helper_by_delica.test_bool_func(always_false, false_inputs=[()], test_desc="always false function")
We then have the following output:
TESTING ALWAYS FALSE FUNCTION
Test #1 of 1
Testing always_false function for input ()
SUCCESS: input=() -> output=False
ALL 1 TESTS COMPLETED FOR ALWAYS FALSE FUNCTION
To see what happens if a test fails, we can try using the always_false function in our always_true test.
test_helper_by_delica.test_bool_func(test_obj, always_false, true_inputs=[()], test_desc="always true function")
This call prints the following stdout output to inform the user that the test has failed:
TESTING ALWAYS TRUE FUNCTION
Test #1 of 1
Testing always_false function for input ()
FAILURE: ALWAYS_FALSE FUNCTION FOR INPUT () FAILED WITH INPUT = () EXPECTED_OUTPUT = True, ACTUAL_OUTPUT = False
ALL 1 TESTS COMPLETED FOR ALWAYS TRUE FUNCTION
Now suppose we want to test a boolean function that takes an input parameter. For example, let's use the is_int
function below, which returns True if the input parameter is an integer and False if it is not.
def is_int(val):
return isinstance(val, int)
For this function, we need to specify values that should yield True and values that should yield False. The test helper package expects the input parameters for each individual test (e.g, testing whether the number 2 yields True) to be provided in the form of a tuple. If your input or output tuple has only one element, you can pass the object on its own without adding parentheses (e.g., can pass 1 instead of (1,) for an input tuple), because the test helper package will take care of converting your single input or return parameter to a tuple format.
test_helper_by_delica.test_bool_func(is_int, true_inputs=[1,2], false_inputs=[1.0,"2"], test_desc="is_int function")
If we have a function with two parameters, such as the sum function below, we need to pass the inputs as tuples (e.g., (1, 2), (0, 0), (3, 2), etc.). If we do not include the parentheses, the test helper function cannot accurately determine the number of input parameters that the test function should receive.
def calc_sum(int1, int2):
return int1 + int2
test_helper_by_delica.run_func_tests(calc_sum, [IOPair((1, 2), 3), IOPair((0, 0), 0), IOPair((3, 2), 5)],
test_desc="sum calculator function")
In the above example, we use run_func_tests from the test helper package instead of test_bool_func because the sum function does not return a boolean value. The more general run_func_tests function can test whether any type of return value is correct based on user-provided criteria. If a user wants to verify whether their test function raises an exception, they simply need to set the expected test output to the correct exception type (e.g., TypeError, ValueError, etc.), as demonstrated below.
def is_int_error_if_false(val):
is_int_val = isinstance(val, int)
if not is_int_val:
raise TypeError("val is not an integer")
return is_int_val
test_helper_by_delica.run_func_tests(is_int_error_if_false, [IOPair(1, True), IOPair(1.0, TypeError), IOPair((3, 2), 5)],
test_desc="is integer error if false function")
The main difference between run_func_tests and test_bool_func, besides the types of functions that they can validate, is that run_func_tests requires a list of IOPair objects to specify the expected input-output pairs for the tests. For example, if our input numbers are 1 and 2 and we expect the sum value to be 3, we will pass this information to run_func_tests in the form IOPair((1, 2), 3). If we instead test a function that returns two numbers which equal an input parameter when added together, we could have a test with IOPair(3, (1, 2)). The test_bool_func function does not require IOPair objects to define expected outputs, because there are only two possible outcomes for boolean functions. The test helper package class includes the IOPair class to facilitate cases in which we need to test a wide range of possible output types.
The Usage section below provides additional examples of how you can test your own functions with the test helper package.
Usage
This package supports three different methods for testing Python code. If you only need to run one test, use the run_single_test function, as demonstrated below with a test function that returns the sum of two numbers.
def calc_sum(int1, int2):
return int1 + int2
test_helper_by_delica.run_single_test(calc_sum, test_input=(1, 2), expected_output=3, test_desc="Sum Test 1")
If you need to run multiple tests, use run_func_tests to check how your function responds to multiple input scenarios. For each test case, provide an IOPair object that contains the input for the test and the expected output. The code segment below provides an example of how to format these IOPair objects for our sum calculator function.
test_helper_by_delica.run_func_tests(calc_sum, [IOPair((1, 2), 3), IOPair((2, 2), 4)], test_desc="Sum Test Suite")
Although the above example only uses integers, the IOPair class accepts any data types for test inputs and outputs. The package currently does not support file-based output checking (e.g., checking if a function creates a file or that the contents of an output file are correct). However, file IO will be included in a future version.
If your function returns a boolean output (True or False), you can skip the creation of IOPair objects by using the test_bool_func function in this package.
def is_pos(num):
return num > 0
test_helper_by_delica.test_bool_func(is_pos, true_inputs=[1, 2, 0.1, 100], false_inputs=[-1, -0.1, -100, -1203],
test_desc="Bool Function Tests")
Each of the three aforementioned functions (run_single_test, run_func_tests, and test_bool_func) can also verify that your functions throw errors in the correct circumstances. For example, suppose that we want our boolean function to throw a ValueError if the input is zero or negative.
def is_pos_with_error(num)
result = num > 0
if not result:
raise ValueError()
return result
test_helper_by_delica.test_bool_func(is_pos, true_inputs=[1, 2, 0.1, 100], false_inputs=[-1, -0.1, -100, -1203],
test_desc="Bool Function Tests With Value Error", error_if_false=True, error_type=ValueError)
For additional information on how this package can accommodate your testing needs, please see the full documentation at https://delicalm.github.io/test_helper_by_delica/.
Citation
To reference this Python package, please use the following citation.
APA Format
Leboe-McGowan, D. S. (2026). Test helper by delica (Version 1.0.2) [Source code]. GitHub. https://github.com/DelicaLM/test_helper_by_delica
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file test_helper_by_delica-1.0.3.tar.gz.
File metadata
- Download URL: test_helper_by_delica-1.0.3.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8da0492c306a36074507eadd3e658d0e7ea3f7858c55aa5fcd6c91d392d5bb15
|
|
| MD5 |
74a8c704fcca3d5514ed29447fcdd15a
|
|
| BLAKE2b-256 |
20331ad94802665b6544a5787d56824fd85e13812024bb421c127c0c97cb8690
|
Provenance
The following attestation bundles were made for test_helper_by_delica-1.0.3.tar.gz:
Publisher:
pypi_deploy.yml on DelicaLM/test_helper_by_delica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
test_helper_by_delica-1.0.3.tar.gz -
Subject digest:
8da0492c306a36074507eadd3e658d0e7ea3f7858c55aa5fcd6c91d392d5bb15 - Sigstore transparency entry: 2222709435
- Sigstore integration time:
-
Permalink:
DelicaLM/test_helper_by_delica@b2a9b81fa5eca2667e349d076e295b7bf25cdd2c -
Branch / Tag:
refs/tags/1.0.3 - Owner: https://github.com/DelicaLM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_deploy.yml@b2a9b81fa5eca2667e349d076e295b7bf25cdd2c -
Trigger Event:
release
-
Statement type:
File details
Details for the file test_helper_by_delica-1.0.3-py3-none-any.whl.
File metadata
- Download URL: test_helper_by_delica-1.0.3-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a12b268763da7552255a37d58b7d606e30bf3377575fce1b917c02ba6079b9be
|
|
| MD5 |
5b817c9cb99dcffff5dec6bef800ae77
|
|
| BLAKE2b-256 |
fd3c3730e62682d59a2d202d746ff21693caba5093acc4aac39261a287e4f1af
|
Provenance
The following attestation bundles were made for test_helper_by_delica-1.0.3-py3-none-any.whl:
Publisher:
pypi_deploy.yml on DelicaLM/test_helper_by_delica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
test_helper_by_delica-1.0.3-py3-none-any.whl -
Subject digest:
a12b268763da7552255a37d58b7d606e30bf3377575fce1b917c02ba6079b9be - Sigstore transparency entry: 2222709879
- Sigstore integration time:
-
Permalink:
DelicaLM/test_helper_by_delica@b2a9b81fa5eca2667e349d076e295b7bf25cdd2c -
Branch / Tag:
refs/tags/1.0.3 - Owner: https://github.com/DelicaLM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_deploy.yml@b2a9b81fa5eca2667e349d076e295b7bf25cdd2c -
Trigger Event:
release
-
Statement type: