-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconftest.py
More file actions
69 lines (51 loc) · 1.88 KB
/
conftest.py
File metadata and controls
69 lines (51 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Pytest configuration for phasecurvefit tests."""
from collections.abc import Callable, Iterable, Sequence
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE
import jax
import pytest
from jaxtyping import PRNGKeyArray
from sybil import Document, Region, Sybil
from sybil.parsers import myst, rest
from optional_dependencies import OptionalDependencyEnum, auto
optionflags = ELLIPSIS | NORMALIZE_WHITESPACE
# Shared parsers for both markdown and Python
markdown_parsers: Sequence[Callable[[Document], Iterable[Region]]] = [
myst.DocTestDirectiveParser(optionflags=optionflags),
myst.PythonCodeBlockParser(doctest_optionflags=optionflags),
myst.SkipParser(),
]
# Markdown documentation tests
docs = Sybil(parsers=markdown_parsers, patterns=["*.md"])
# Python source code tests (includes markdown parsers + rest parsers)
python = Sybil(
parsers=[
*markdown_parsers,
rest.PythonCodeBlockParser(),
rest.DocTestParser(optionflags=optionflags),
rest.SkipParser(),
],
patterns=["*.py"],
)
# Combine both for pytest collection
pytest_collect_file = (docs + python).pytest()
class OptDeps(OptionalDependencyEnum): # pylint: disable=invalid-enum-extension
"""Optional dependencies for phasecurvefit."""
UNXT = auto()
KDTREE = auto()
MATPLOTLIB = auto()
collect_ignore_glob = []
if not OptDeps.UNXT.installed:
collect_ignore_glob.append("tests/test_interop_unxt.py")
if not OptDeps.MATPLOTLIB.installed:
collect_ignore_glob.append("tests/usage/test_epitrochoid.py")
if not OptDeps.KDTREE.installed:
collect_ignore_glob.append("tests/test_kdtree.py")
def pytest_configure(config):
"""Configure pytest."""
# Suppress JAX warning about no GPU
import os
os.environ.setdefault("JAX_PLATFORMS", "cpu")
@pytest.fixture
def rng_key() -> PRNGKeyArray:
"""Provide a JAX random key for tests."""
return jax.random.key(37)