3"""Unit tests for the pure validation helpers of EventSelectionConfig.
4These need no accumulator: a bare block instance exposes the methods."""
7from EventSelectionAlgorithms.EventSelectionConfig
import EventSelectionConfig
12 self.
b = EventSelectionConfig()
15 for text, exp
in [(
"0", 0.0), (
"25000", 25000.0), (
"1.5", 1.5)]:
16 self.assertEqual(self.
b.check_float(text), exp)
19 self.assertRaises(ValueError, self.
b.check_float,
"-1")
22 self.assertEqual(self.
b.check_float(
"-1", requirePositive=
False), -1.0)
25 self.assertRaises(ValueError, self.
b.check_float,
"abc")
28 self.assertEqual(self.
b.check_int(
"2"), 2)
31 self.assertRaises(ValueError, self.
b.check_int,
"1.5")
34 self.assertRaises(ValueError, self.
b.check_int,
"-3")
37 for sym, enum
in [(
"<",
"LT"), (
">",
"GT"), (
"==",
"EQ"), (
">=",
"GE"), (
"<=",
"LE")]:
38 self.assertEqual(self.
b.check_sign(sym), enum)
41 self.assertRaises(KeyError, self.
b.check_sign,
"=!")
44 self.assertEqual(self.
b.check_btagging(
"GN2v01:FixedCutBEff_85"),
45 [
"GN2v01",
"FixedCutBEff_85"])
48 self.assertRaises(ValueError, self.
b.check_btagging,
"GN2v01")
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])
59 self.assertEqual(self.
b.check_ghosts(
"B!C"),
60 [
"GhostBHadronsFinalCount",
"GhostCHadronsFinalCount"])
63 self.assertEqual(self.
b.check_ghosts(
"MyCustomGhost"), [
"MyCustomGhost"])
66 self.assertEqual(self.
b.checkDecorationName(
""),
"")
69 self.assertEqual(self.
b.checkDecorationName(
"foo_%SYS%"),
"foo_%SYS%,as_char")
72 self.assertEqual(self.
b.checkDecorationName(
"foo_%SYS%,as_char"),
"foo_%SYS%,as_char")
75 self.assertEqual(self.
b.checkDecorationName(
"a_%SYS%&&b_%SYS%,as_char"),
76 "a_%SYS%,as_char&&b_%SYS%,as_char")
79if __name__ ==
"__main__":
test_check_float_rejects_negative(self)
test_check_decoration_empty(self)
test_check_int_rejects_float(self)
test_check_float_allows_negative_when_not_required(self)
test_check_decoration_appends_as_char(self)
test_check_btagging_ok(self)
test_check_int_rejects_negative(self)
test_check_btagging_rejects_malformed(self)
test_check_ghosts_with_veto(self)
test_check_decoration_and_chain(self)
test_check_sign_rejects_unknown(self)
test_check_ghosts_single(self)
test_check_decoration_preserves_existing(self)
test_check_ghosts_passthrough_unknown(self)
test_check_float_ok(self)
test_check_float_rejects_nonnumeric(self)