civiqhub_selene.testing¶
Contract kit: prove in ten lines that an estimator honours the contract.
Write a pytest class with three methods; it inherits seven tests:
from civiqhub_selene.testing import EstimatorContract
class TestMean(EstimatorContract):
def make_estimator(self):
return Mean()
def make_data(self):
return Numbers((1.0, 2.0)) # an input on which a value exists
def make_empty_data(self):
return Numbers(()) # an input with no answer, or None if there is none
A test of the kit that fails raises ContractError,
whose message names the estimator and the rule it breaks. The kit runs under pytest
but the package does not depend on it: pytest is imported only when a test needs it.
- class civiqhub_selene.testing.EstimatorContract[source]¶
Bases:
objectBase class of a pytest class that checks one estimator against the contract.
Write
make_estimator(),make_data()andmake_empty_data(); the seventest_*methods are inherited. Name the subclassTest...so that pytest collects it.- make_empty_data()[source]¶
Return an input with no possible answer, or
Noneif the method always answers.- Return type:
Any
- test_identity_is_declared()[source]¶
The class declares its name, its version and a reference.
- Return type:
None
- test_estimator_is_a_frozen_value()[source]¶
The estimator is a frozen dataclass, equal to a copy of itself, and hashable.
- Return type:
None
- test_returns_a_result()[source]¶
estimatereturns an availableResulton the data ofmake_data.- Return type:
None
- test_deterministic()[source]¶
Two calls with the same seed give the same fingerprints.
- Return type:
None
- test_provenance_is_complete()[source]¶
The provenance names the engine, the input, the settings and the packages.
- Return type:
None
- civiqhub_selene.testing.fingerprint_of(value)[source]¶
Return a stable fingerprint of a value: 16 hexadecimal characters.
value.fingerprint()when the object has one, otherwise the SHA-256 of its canonical JSON.- Raises:
ValueError – If the value holds NaN or an infinity, which have no canonical form.
- Parameters:
value (object)
- Return type:
str