- add `lalib.fields.base.Field`, a blueprint for all concrete fields, providing a unified interface to be used outside of the `lalib.fields` sub-package - implement `lalib.fields.complex_.ComplexField`, or `C` for short, the field over the complex numbers (modeled as `complex` numbers) - implement `lalib.fields.galois.GaloisField2`, or `GF2` for short, the (finite) field over the two elements `one` and `zero` + adapt `lalib.elements.galois.GF2Element.__eq__()` to return `NotImplemented` instead of `False` for non-castable `other`s => this fixes a minor issue with `pytest.approx()` - implement `lalib.fields.rational.RationalField`, or `Q` for short, the field over the rational numbers (modeled as `fractions.Fraction`s) - implement `lalib.fields.real.RealField`, or `R` for short, the field over the real numbers (modeled as `float`s) - organize top-level imports for `lalib.fields`, making `Q`, `R`, `C`, and `GF2` importable with `from lalib.fields import *` - provide extensive unit and integration tests for the new objects: + test generic and common behavior in `tests.fields.test_base` + test specific behavior is other modules + test the well-known math axioms for all fields (integration tests) + test the new objects' docstrings + add "pytest-repeat" to run randomized tests many times
31 lines
771 B
Python
31 lines
771 B
Python
"""Integrate `xdoctest` into the test suite.
|
|
|
|
Ensure all code snippets in docstrings are valid and functioning code.
|
|
|
|
Important: All modules with docstrings containing code snippets
|
|
must be put on the parameter list below by hand!
|
|
"""
|
|
|
|
import pytest
|
|
import xdoctest
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"module",
|
|
[
|
|
"lalib",
|
|
"lalib.elements",
|
|
"lalib.elements.galois",
|
|
"lalib.fields",
|
|
"lalib.fields.base",
|
|
"lalib.fields.complex_",
|
|
"lalib.fields.galois",
|
|
"lalib.fields.rational",
|
|
"lalib.fields.real",
|
|
],
|
|
)
|
|
def test_docstrings(module):
|
|
"""Test code snippets within the package with `xdoctest`."""
|
|
result = xdoctest.doctest_module(module, "all")
|
|
|
|
assert result["n_failed"] == 0
|