Utilities for testing code written with labrea
labrea-test is available for install via pip.
pip install labrea-testAlternatively, you can install the latest development version from GitHub.
pip install git+https://github.com/8451/labrea-test@developDuring testing, you may want to mock a certain dataset (or other Evaluatable) to known value.
This can be done using the labrea_test.Mock context manager, which ensures that at the end
of the block, any mocking is torn down.
import labrea_test
from labrea import dataset
@dataset
def foo() -> str:
return "foo"
def test_foo():
with labrea_test.Mock() as mock:
mock(foo, "bar")
assert foo() == "bar"
assert foo() == "foo"Mock can be used to mock any Evaluatable object, and can take a plain value or another
Evaluatable object as the value to mock to.
@dataset
def bar() -> str:
return "bar"
def test_foo():
with labrea_test.Mock() as mock:
mock(foo, bar)
assert foo() == "bar"
assert foo() == "foo"If you would like to contribute to labrea-test, please read the Contributing Guide.
A summary of recent updates to labrea-test can be found in the Changelog.
| Maintainer | |
|---|---|
| Austin Warner | austin.warner@8451.com |
| Michael Stoepel | michael.stoepel@8451.com |
- Report a bug or request a feature: https://github.com/8451/labrea-test/issues/new/choose
- Documentation: https://8451.github.io/labrea-test