ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
EventSelectionAlgorithms
python
EventSelectionConfigHelpers_unitTest.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
"""Unit tests for the pure validation helpers of EventSelectionConfig.
4
These need no accumulator: a bare block instance exposes the methods."""
5
6
import
unittest
7
from
EventSelectionAlgorithms.EventSelectionConfig
import
EventSelectionConfig
8
9
10
class
TestHelpers
(unittest.TestCase):
11
def
setUp
(self):
12
self.
b
= EventSelectionConfig()
13
14
def
test_check_float_ok
(self):
15
for
text, exp
in
[(
"0"
, 0.0), (
"25000"
, 25000.0), (
"1.5"
, 1.5)]:
16
self.assertEqual(self.
b
.check_float(text), exp)
17
18
def
test_check_float_rejects_negative
(self):
19
self.assertRaises(ValueError, self.
b
.check_float,
"-1"
)
20
21
def
test_check_float_allows_negative_when_not_required
(self):
22
self.assertEqual(self.
b
.check_float(
"-1"
, requirePositive=
False
), -1.0)
23
24
def
test_check_float_rejects_nonnumeric
(self):
25
self.assertRaises(ValueError, self.
b
.check_float,
"abc"
)
26
27
def
test_check_int_ok
(self):
28
self.assertEqual(self.
b
.check_int(
"2"
), 2)
29
30
def
test_check_int_rejects_float
(self):
31
self.assertRaises(ValueError, self.
b
.check_int,
"1.5"
)
32
33
def
test_check_int_rejects_negative
(self):
34
self.assertRaises(ValueError, self.
b
.check_int,
"-3"
)
35
36
def
test_check_sign_ok
(self):
37
for
sym, enum
in
[(
"<"
,
"LT"
), (
">"
,
"GT"
), (
"=="
,
"EQ"
), (
">="
,
"GE"
), (
"<="
,
"LE"
)]:
38
self.assertEqual(self.
b
.check_sign(sym), enum)
39
40
def
test_check_sign_rejects_unknown
(self):
41
self.assertRaises(KeyError, self.
b
.check_sign,
"=!"
)
42
43
def
test_check_btagging_ok
(self):
44
self.assertEqual(self.
b
.check_btagging(
"GN2v01:FixedCutBEff_85"
),
45
[
"GN2v01"
,
"FixedCutBEff_85"
])
46
47
def
test_check_btagging_rejects_malformed
(self):
48
self.assertRaises(ValueError, self.
b
.check_btagging,
"GN2v01"
)
49
50
def
test_check_ghosts_single
(self):
51
cases = {
"B"
:
"GhostBHadronsFinalCount"
,
"C"
:
"GhostCHadronsFinalCount"
,
52
"T"
:
"GhostTQuarksFinalCount"
,
"W"
:
"GhostWBosonsCount"
,
53
"Z"
:
"GhostZBosonsCount"
,
"H"
:
"GhostHBosonsCount"
,
54
"TAU"
:
"GhostTausFinalCount"
}
55
for
token, exp
in
cases.items():
56
self.assertEqual(self.
b
.check_ghosts(token), [exp])
57
58
def
test_check_ghosts_with_veto
(self):
59
self.assertEqual(self.
b
.check_ghosts(
"B!C"
),
60
[
"GhostBHadronsFinalCount"
,
"GhostCHadronsFinalCount"
])
61
62
def
test_check_ghosts_passthrough_unknown
(self):
63
self.assertEqual(self.
b
.check_ghosts(
"MyCustomGhost"
), [
"MyCustomGhost"
])
64
65
def
test_check_decoration_empty
(self):
66
self.assertEqual(self.
b
.checkDecorationName(
""
),
""
)
67
68
def
test_check_decoration_appends_as_char
(self):
69
self.assertEqual(self.
b
.checkDecorationName(
"foo_%SYS%"
),
"foo_%SYS%,as_char"
)
70
71
def
test_check_decoration_preserves_existing
(self):
72
self.assertEqual(self.
b
.checkDecorationName(
"foo_%SYS%,as_char"
),
"foo_%SYS%,as_char"
)
73
74
def
test_check_decoration_and_chain
(self):
75
self.assertEqual(self.
b
.checkDecorationName(
"a_%SYS%&&b_%SYS%,as_char"
),
76
"a_%SYS%,as_char&&b_%SYS%,as_char"
)
77
78
79
if
__name__ ==
"__main__"
:
80
unittest.main()
python.EventSelectionConfigHelpers_unitTest.TestHelpers
Definition
EventSelectionConfigHelpers_unitTest.py:10
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_float_rejects_negative
test_check_float_rejects_negative(self)
Definition
EventSelectionConfigHelpers_unitTest.py:18
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_decoration_empty
test_check_decoration_empty(self)
Definition
EventSelectionConfigHelpers_unitTest.py:65
python.EventSelectionConfigHelpers_unitTest.TestHelpers.setUp
setUp(self)
Definition
EventSelectionConfigHelpers_unitTest.py:11
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_int_rejects_float
test_check_int_rejects_float(self)
Definition
EventSelectionConfigHelpers_unitTest.py:30
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_sign_ok
test_check_sign_ok(self)
Definition
EventSelectionConfigHelpers_unitTest.py:36
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_int_ok
test_check_int_ok(self)
Definition
EventSelectionConfigHelpers_unitTest.py:27
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_float_allows_negative_when_not_required
test_check_float_allows_negative_when_not_required(self)
Definition
EventSelectionConfigHelpers_unitTest.py:21
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_decoration_appends_as_char
test_check_decoration_appends_as_char(self)
Definition
EventSelectionConfigHelpers_unitTest.py:68
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_btagging_ok
test_check_btagging_ok(self)
Definition
EventSelectionConfigHelpers_unitTest.py:43
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_int_rejects_negative
test_check_int_rejects_negative(self)
Definition
EventSelectionConfigHelpers_unitTest.py:33
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_btagging_rejects_malformed
test_check_btagging_rejects_malformed(self)
Definition
EventSelectionConfigHelpers_unitTest.py:47
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_ghosts_with_veto
test_check_ghosts_with_veto(self)
Definition
EventSelectionConfigHelpers_unitTest.py:58
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_decoration_and_chain
test_check_decoration_and_chain(self)
Definition
EventSelectionConfigHelpers_unitTest.py:74
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_sign_rejects_unknown
test_check_sign_rejects_unknown(self)
Definition
EventSelectionConfigHelpers_unitTest.py:40
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_ghosts_single
test_check_ghosts_single(self)
Definition
EventSelectionConfigHelpers_unitTest.py:50
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_decoration_preserves_existing
test_check_decoration_preserves_existing(self)
Definition
EventSelectionConfigHelpers_unitTest.py:71
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_ghosts_passthrough_unknown
test_check_ghosts_passthrough_unknown(self)
Definition
EventSelectionConfigHelpers_unitTest.py:62
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_float_ok
test_check_float_ok(self)
Definition
EventSelectionConfigHelpers_unitTest.py:14
python.EventSelectionConfigHelpers_unitTest.TestHelpers.test_check_float_rejects_nonnumeric
test_check_float_rejects_nonnumeric(self)
Definition
EventSelectionConfigHelpers_unitTest.py:24
python.EventSelectionConfigHelpers_unitTest.TestHelpers.b
b
Definition
EventSelectionConfigHelpers_unitTest.py:12
Generated on
for ATLAS Offline Software by
1.17.0