- extend `pytest` with an option to run only the minimum number
of (unit) test cases to just keep the coverage at 100%
- rationale:
+ many of the unit test cases partly overlap with
respect to the lines of source code executed
+ also, integration tests, by definition, do not
contribute to a higher test coverage
- implementation: mark "redundant" test cases as one of:
+ `pytest.mark.integration_test`
=> code usage from the perspective of the end user
+ `pytest.mark.overlapping_test`
=> tests not contributing to the 100% coverage
+ `pytest.mark.sanity_test`
=> tests providing confidence in the test data
- add `tests.conftest` module
=> programatically convert the above markers into
`@pytest.mark.no_cover` and collect the non-"redundant" tests
- add nox session "test-fast" to run only the minimum
number of (unit) test while holding coverage at 100%
- refactor some test modules
+ wrap some test cases in a class
+ move sanity tests to the end of the files
33 lines
808 B
Python
33 lines
808 B
Python
"""Tests for the `lalib.fields.rational.RationalField` only."""
|
|
|
|
import fractions
|
|
|
|
import pytest
|
|
|
|
from lalib import fields
|
|
|
|
|
|
# None of the test cases below contributes towards higher coverage
|
|
pytestmark = pytest.mark.overlapping_test
|
|
|
|
|
|
Q = fields.Q
|
|
|
|
|
|
class TestCastAndValidateFieldElements:
|
|
"""Test specifics for `Q.cast()` and `Q.validate()`."""
|
|
|
|
@pytest.mark.parametrize(
|
|
"value",
|
|
["1", "0", "1/1", "0/1", "+42", "-42", "+42/1", "-42/1"],
|
|
)
|
|
def test_str_is_field_element(self, value):
|
|
"""`fractions.Fraction()` also accepts `str`ings.
|
|
|
|
Source: https://docs.python.org/3/library/fractions.html#fractions.Fraction
|
|
"""
|
|
left = Q.cast(value)
|
|
right = fractions.Fraction(value)
|
|
|
|
assert left == right
|
|
assert Q.validate(value)
|