Skip to content

Commit 58e4660

Browse files
DX: define tests with pytest-describe (#227)
MAINT: upgrade lock files
1 parent a365756 commit 58e4660

19 files changed

Lines changed: 2909 additions & 2371 deletions

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ repos:
4848
metadata.vscode
4949
5050
- repo: https://github.com/ComPWA/nbhooks
51-
rev: 0.0.1
51+
rev: 0.0.2
5252
hooks:
5353
- id: colab-toc-visible
5454
- id: fix-nbformat-version
@@ -57,7 +57,7 @@ repos:
5757
- id: strip-nb-whitespace
5858

5959
- repo: https://github.com/astral-sh/ruff-pre-commit
60-
rev: v0.16.1
60+
rev: v0.16.6
6161
hooks:
6262
- id: ruff-check
6363
args: [--fix]
@@ -81,7 +81,7 @@ repos:
8181
- id: trailing-whitespace
8282

8383
- repo: https://github.com/tombi-toml/tombi-pre-commit
84-
rev: v1.2.5
84+
rev: v1.5.4
8585
hooks:
8686
- id: tombi-format
8787
- id: tombi-lint
@@ -93,12 +93,12 @@ repos:
9393
- id: prettier
9494

9595
- repo: https://github.com/streetsidesoftware/cspell-cli
96-
rev: v10.0.1
96+
rev: v10.2.0
9797
hooks:
9898
- id: cspell
9999

100100
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
101-
rev: 3.6.1
101+
rev: 3.11.1
102102
hooks:
103103
- id: editorconfig-checker
104104
name: editorconfig
@@ -109,12 +109,12 @@ repos:
109109
)$
110110
111111
- repo: https://github.com/astral-sh/ty-pre-commit
112-
rev: v0.0.65
112+
rev: v0.0.79
113113
hooks:
114114
- id: ty
115115
args: [--group=types, --no-default-groups]
116116

117117
- repo: https://github.com/astral-sh/uv-pre-commit
118-
rev: 0.12.0
118+
rev: 0.12.11
119119
hooks:
120120
- id: uv-lock

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"8.1.1": "8.1.2",
2323
"8.1.7": "8.1.5",
2424
"8.1.8": "8.1.5",
25+
"8.1.9": "8.1.5",
2526
},
2627
"matplotlib": {"3.9.1.post1": "3.9.1"},
2728
"mpl-interactions": {"0.24.1": "0.24.0"},

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ style = [
9696
test = [
9797
"pytest",
9898
"pytest-cov",
99+
"pytest-describe",
99100
"pytest-xdist",
100101
]
101102
types = [
@@ -419,14 +420,16 @@ known-first-party = ["ampform_dpd"]
419420
split-on-trailing-comma = false
420421

421422
[tool.ruff.lint.pep8-naming]
422-
ignore-names = [
423+
extend-ignore-names = [
423424
"A",
424425
"H",
425426
"L",
426427
"R",
427428
"R_dec",
428429
"R_prod",
429430
"S",
431+
"describe_*",
432+
"test_*",
430433
"Γ*",
431434
"λ*",
432435
]
@@ -480,12 +483,14 @@ ignore-names = [
480483
"T20",
481484
"assert",
482485
"boolean-type-hint-positional-argument",
486+
"complex-structure",
483487
"float-equality-comparison",
484488
"implicit-namespace-package",
485489
"import-private-name",
486490
"magic-value-comparison",
487491
"no-self-use",
488492
"private-member-access",
493+
"too-many-statements",
489494
]
490495

491496
[tool.ruff.lint.pydocstyle]

src/ampform_dpd/io/serialization/amplitude.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
import sympy as sp
77
from ampform.sympy import PoolSum, unevaluated
8-
from sympy.functions.special.tensor_functions import (
9-
KroneckerDelta as δ, # ruff: ignore[camelcase-imported-as-lowercase, non-ascii-import-name]
10-
)
8+
from sympy.functions.special.tensor_functions import KroneckerDelta as δ # ruff: ignore[camelcase-imported-as-lowercase, non-ascii-import-name]
119
from sympy.physics.quantum.cg import CG
1210
from sympy.physics.quantum.spin import Rotation as Wigner
1311

tests/adapter/test_qrules.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -117,42 +117,42 @@ def test_get_equal_final_state_ids(
117117
assert equal_ids == expected
118118

119119

120-
def test_normalize_state_ids_reaction(jpsi2pksigma_reaction: ReactionInfo):
121-
reaction012 = jpsi2pksigma_reaction
122-
reaction123 = normalize_state_ids(reaction012)
123-
assert set(reaction123.initial_state) == {0}
124-
assert set(reaction123.final_state) == {1, 2, 3}
125-
126-
transitions123 = normalize_state_ids(reaction012.transitions)
127-
for transition012, transition123 in zip(
128-
reaction012.transitions, transitions123, strict=True
129-
):
130-
assert set(transition123.initial_states) == {0}
131-
assert set(transition123.final_states) == {1, 2, 3}
132-
assert set(transition123.intermediate_states) == {4}
133-
134-
topology123 = normalize_state_ids(transition123.topology)
135-
assert topology123.incoming_edge_ids == {0}
136-
assert topology123.outgoing_edge_ids == {1, 2, 3}
137-
assert topology123.intermediate_edge_ids == {4}
138-
139-
for i in transition012.states:
140-
assert transition012.states[i] == transition123.states[i + 1]
141-
142-
143-
def test_normalize_state_ids_problem_set():
144-
stm = StateTransitionManager(
145-
initial_state=[("J/psi(1S)", [-1, +1])],
146-
final_state=["K0", "Sigma+", "p~"],
147-
allowed_intermediate_particles=["N(1700)", "Sigma(1750)"],
148-
formalism="helicity",
149-
mass_conservation_factor=0,
150-
)
151-
stm.set_allowed_interaction_types([InteractionType.STRONG, InteractionType.EM])
152-
problem_sets = stm.create_problem_sets()
153-
some_problem_set = normalize_state_ids(problem_sets[3600.0][0])
154-
assert set(some_problem_set.initial_facts.initial_states) == {0}
155-
assert set(some_problem_set.initial_facts.final_states) == {1, 2, 3}
120+
def describe_normalize_state_ids():
121+
def it_normalizes_a_reaction(jpsi2pksigma_reaction: ReactionInfo):
122+
reaction012 = jpsi2pksigma_reaction
123+
reaction123 = normalize_state_ids(reaction012)
124+
assert set(reaction123.initial_state) == {0}
125+
assert set(reaction123.final_state) == {1, 2, 3}
126+
127+
transitions123 = normalize_state_ids(reaction012.transitions)
128+
for transition012, transition123 in zip(
129+
reaction012.transitions, transitions123, strict=True
130+
):
131+
assert set(transition123.initial_states) == {0}
132+
assert set(transition123.final_states) == {1, 2, 3}
133+
assert set(transition123.intermediate_states) == {4}
134+
135+
topology123 = normalize_state_ids(transition123.topology)
136+
assert topology123.incoming_edge_ids == {0}
137+
assert topology123.outgoing_edge_ids == {1, 2, 3}
138+
assert topology123.intermediate_edge_ids == {4}
139+
140+
for i in transition012.states:
141+
assert transition012.states[i] == transition123.states[i + 1]
142+
143+
def it_normalizes_a_problem_set():
144+
stm = StateTransitionManager(
145+
initial_state=[("J/psi(1S)", [-1, +1])],
146+
final_state=["K0", "Sigma+", "p~"],
147+
allowed_intermediate_particles=["N(1700)", "Sigma(1750)"],
148+
formalism="helicity",
149+
mass_conservation_factor=0,
150+
)
151+
stm.set_allowed_interaction_types([InteractionType.STRONG, InteractionType.EM])
152+
problem_sets = stm.create_problem_sets()
153+
some_problem_set = normalize_state_ids(problem_sets[3600.0][0])
154+
assert set(some_problem_set.initial_facts.initial_states) == {0}
155+
assert set(some_problem_set.initial_facts.final_states) == {1, 2, 3}
156156

157157

158158
def test_permute_equal_final_states(

tests/io_serialization/test_amplitude.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@
1818
if TYPE_CHECKING:
1919
from ampform_dpd.io.serialization.format import ModelDefinition
2020

21+
half = sp.Rational(1, 2)
2122

22-
def test_get_decay_product_helicities(model_definition: ModelDefinition):
23+
24+
@pytest.mark.parametrize(
25+
("chain_id", "expected"),
26+
[
27+
(0, ((3, 0), (1, +half))),
28+
(15, ((1, +half), (2, 0))),
29+
(-1, ((2, 0), (3, 0))),
30+
],
31+
)
32+
def test_get_decay_product_helicities(
33+
model_definition: ModelDefinition, chain_id: int, expected: tuple
34+
):
2335
chain_defs = get_decay_chains(model_definition)
24-
half = sp.Rational(1 / 2)
25-
assert _get_decay_product_helicities(chain_defs[0]) == ((3, 0), (1, +half))
26-
assert _get_decay_product_helicities(chain_defs[15]) == ((1, +half), (2, 0))
27-
assert _get_decay_product_helicities(chain_defs[-1]) == ((2, 0), (3, 0))
36+
assert _get_decay_product_helicities(chain_defs[chain_id]) == expected
2837

2938

3039
def test_get_existing_subsystem_ids(model_definition: ModelDefinition):
@@ -35,25 +44,28 @@ def test_get_existing_subsystem_ids(model_definition: ModelDefinition):
3544
def test_get_final_state_helicities(model_definition: ModelDefinition, chain_id: int):
3645
chain_defs = get_decay_chains(model_definition)
3746
assert len(chain_defs) == 26
38-
if chain_id in {19, 20, 22, 25}:
39-
λp = -sp.Rational(1 / 2)
40-
else:
41-
λp = +sp.Rational(1 / 2)
47+
λp = -half if chain_id in {19, 20, 22, 25} else +half
4248
assert _get_final_state_helicities(chain_defs[chain_id]) == {1: λp, 2: 0, 3: 0}
4349

4450

45-
def test_get_resonance_helicity(model_definition: ModelDefinition):
51+
@pytest.mark.parametrize(
52+
("chain_id", "expected_node", "expected_helicity"),
53+
[
54+
(0, (3, 1), +half),
55+
(1, (3, 1), -half),
56+
(-1, (2, 3), 0),
57+
],
58+
)
59+
def test_get_resonance_helicity(
60+
model_definition: ModelDefinition,
61+
chain_id: int,
62+
expected_node: tuple[int, int],
63+
expected_helicity: sp.Rational,
64+
):
4665
chain_defs = get_decay_chains(model_definition)
47-
half = sp.Rational(1 / 2)
48-
node, helicity = _get_resonance_helicity(chain_defs[0])
49-
assert node == (3, 1)
50-
assert helicity == +half
51-
node, helicity = _get_resonance_helicity(chain_defs[1])
52-
assert node == (3, 1)
53-
assert helicity == -half
54-
node, helicity = _get_resonance_helicity(chain_defs[-1])
55-
assert node == (2, 3)
56-
assert helicity == 0
66+
node, helicity = _get_resonance_helicity(chain_defs[chain_id])
67+
assert node == expected_node
68+
assert helicity == expected_helicity
5769

5870

5971
def test_get_weight(model_definition: ModelDefinition):

0 commit comments

Comments
 (0)