ATLAS Offline Software
Loading...
Searching...
No Matches
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.
4These need no accumulator: a bare block instance exposes the methods."""
5
6import unittest
7from EventSelectionAlgorithms.EventSelectionConfig import EventSelectionConfig
8
9
10class TestHelpers(unittest.TestCase):
11 def setUp(self):
12 self.b = EventSelectionConfig()
13
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
19 self.assertRaises(ValueError, self.b.check_float, "-1")
20
22 self.assertEqual(self.b.check_float("-1", requirePositive=False), -1.0)
23
25 self.assertRaises(ValueError, self.b.check_float, "abc")
26
28 self.assertEqual(self.b.check_int("2"), 2)
29
31 self.assertRaises(ValueError, self.b.check_int, "1.5")
32
34 self.assertRaises(ValueError, self.b.check_int, "-3")
35
37 for sym, enum in [("<", "LT"), (">", "GT"), ("==", "EQ"), (">=", "GE"), ("<=", "LE")]:
38 self.assertEqual(self.b.check_sign(sym), enum)
39
41 self.assertRaises(KeyError, self.b.check_sign, "=!")
42
44 self.assertEqual(self.b.check_btagging("GN2v01:FixedCutBEff_85"),
45 ["GN2v01", "FixedCutBEff_85"])
46
48 self.assertRaises(ValueError, self.b.check_btagging, "GN2v01")
49
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
59 self.assertEqual(self.b.check_ghosts("B!C"),
60 ["GhostBHadronsFinalCount", "GhostCHadronsFinalCount"])
61
63 self.assertEqual(self.b.check_ghosts("MyCustomGhost"), ["MyCustomGhost"])
64
66 self.assertEqual(self.b.checkDecorationName(""), "")
67
69 self.assertEqual(self.b.checkDecorationName("foo_%SYS%"), "foo_%SYS%,as_char")
70
72 self.assertEqual(self.b.checkDecorationName("foo_%SYS%,as_char"), "foo_%SYS%,as_char")
73
75 self.assertEqual(self.b.checkDecorationName("a_%SYS%&&b_%SYS%,as_char"),
76 "a_%SYS%,as_char&&b_%SYS%,as_char")
77
78
79if __name__ == "__main__":
80 unittest.main()