11 from conditions_db
import iov
15 """Helper class to test an IoV"""
18 """Helper function to turn a tuple/None/list(tuple) into iov instances"""
19 if isinstance(iov, list):
27 """Test that we get errors when creating invalid iovs"""
28 with self.assertRaises(ValueError):
30 with self.assertRaises(ValueError):
32 with self.assertRaises(ValueError):
34 with self.assertRaises(ValueError):
36 with self.assertRaises(ValueError):
38 with self.assertRaises(ValueError):
40 with self.assertRaises(ValueError):
42 with self.assertRaises(ValueError):
45 self.assertEqual(iov.final, (math.inf, math.inf))
47 self.assertEqual(iov.final, (1, math.inf))
51 """Test that we can intersect iovs"""
52 iov = IntervalOfValidity
54 [(0, 0, 10, 0), (11, 10, 11, 12),
None],
55 [(0, 0, 10, 0), (8, 0, 10, 12), (8, 0, 10, 0)],
56 [(0, 0, 0, 0), (0, 0, -1, -1), (0, 0, 0, 0)],
57 [(0, 0, -1, -1), (20, 12, 21, 234), (20, 12, 21, 234)],
58 [(0, 0, 2, -1), (1, 1, 2, 8), (1, 1, 2, 8)],
59 [(1, 2, 2, -1), (0, 0, 2, 8), (1, 2, 2, 8)],
60 [(1, 0, 3, -1), (0, 0, 2, -1), (1, 0, 2, -1)],
61 [(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],
63 self.assertEqual(iov(a) & iov(b), self.
iovify(c), f
'{a} & {b} = {c}')
64 self.assertEqual(iov(b) & iov(a), self.
iovify(c), f
'{a} & {b} = {c}')
67 """Test that we can calculate the union of iovs"""
68 iov = IntervalOfValidity
70 [(0, 0, 10, 0), (11, 10, 11, 12),
None],
71 [(0, 0, 10, 0), (8, 0, 10, 12), (0, 0, 10, 12)],
72 [(0, 0, 0, 0), (0, 0, -1, -1), (0, 0, -1, -1)],
73 [(0, 0, -1, -1), (20, 12, 21, 234), (0, 0, -1, -1)],
74 [(0, 0, 2, -1), (1, 1, 2, 8), (0, 0, 2, -1)],
75 [(1, 2, 2, -1), (0, 0, 2, 8), (0, 0, 2, -1)],
76 [(1, 0, 3, -1), (0, 0, 2, -1), (0, 0, 3, -1)],
77 [(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],
78 [(0, 0, 1, 1), (1, 2, 1, 3), (0, 0, 1, 3)],
79 [(0, 0, 1, 1), (1, 3, 1, 4),
None],
80 [(0, 0, 1, -1), (2, 0, 2, 1), (0, 0, 2, 1)],
81 [(0, 0, 1, -1), (2, 0, 2, 1), (0, 0, 2, 1)],
82 [(0, 0, 1, -1), (2, 1, 2, 1),
None],
83 [(0, 0, 1, -1), (1, 9999, 2, 1), (0, 0, 2, 1)],
85 self.assertEqual(iov(a) | iov(b), self.
iovify(c), f
'{a} | {b} = {c}')
86 self.assertEqual(iov(b) | iov(a), self.
iovify(c), f
'{a} | {b} = {c}')
89 """Test that we can calculate the union starting at run 1 as well"""
90 iov = IntervalOfValidity
91 self.assertEqual(iov(0, 0, 1, -1).union(iov(2, 1, 2, -1)),
None)
92 self.assertEqual(iov(0, 0, 1, -1).union(iov(2, 1, 2, -1),
True), iov(0, 0, 2, -1))
95 """Test subtracting iovs from another"""
96 iov = IntervalOfValidity
98 [(0, 0, 10, 0), (11, 10, 11, 12), (0, 0, 10, 0), (11, 10, 11, 12)],
99 [(0, 0, 10, 0), (8, 0, 10, 12), (0, 0, 7, -1), (10, 1, 10, 12)],
100 [(0, 0, 0, 0), (0, 0, -1, -1),
None, (0, 1, -1, -1)],
101 [(0, 0, -1, -1), (20, 12, 21, 234), [(0, 0, 20, 11), (21, 235, -1, -1)],
None],
102 [(0, 0, 2, -1), (1, 1, 2, 8), [(0, 0, 1, 0), (2, 9, 2, -1)],
None],
103 [(1, 2, 2, -1), (0, 0, 2, 8), (2, 9, 2, -1), (0, 0, 1, 1)],
104 [(1, 0, 3, -1), (0, 0, 2, -1), (3, 0, 3, -1), (0, 0, 0, -1)],
105 [(0, 0, -1, -1), (0, 0, -1, -1),
None,
None],
106 [(0, 0, 1, -1), (0, 0, 1, -1),
None,
None],
107 [(0, 0, 0, 0), (0, 0, 0, 0),
None,
None],
108 [(0, 0, 1, -1), (2, 0, 2, -1), (0, 0, 1, -1), (2, 0, 2, -1)],
109 [(11, 0, 12, 86), (0, 0, 11, -1), (12, 0, 12, 86), (0, 0, 10, -1)],
111 self.assertEqual(iov(a) - iov(b), self.
iovify(c), f
'{a} - {b} = {c}')
112 self.assertEqual(iov(b) - iov(a), self.
iovify(d), f
'{b} - {a} = {d}')
116 """Helper class to test a set of IoVs"""
119 """Test adding iovs to a set"""
121 [(0, 0, 0, -1), (1, 0, 1, -1), (2, 1, 2, -1), (3, 1, 3, 1), (3, 2, 3, 2), (3, 3, 3, 6), (3, 8, 3, 8)],
122 [(0, i, 0, i)
for i
in range(0, 100)],
123 [(0, i, 0, i)
for i
in range(0, 100, 2)],
126 [(0, 0, 1, -1), (2, 1, 2, -1), (3, 1, 3, 6), (3, 8, 3, 8)],
128 [(0, i, 0, i)
for i
in range(0, 100, 2)],
132 for input, output
in zip(inputs, results):
134 for iov
in random.sample(input, len(input)):
137 self.assertEqual(s.iovs, output)
140 """Test removing iovs from a set"""
142 s.add((0, 0, 0, 100))
143 to_remove = [(0, i, 0, i)
for i
in range(0, 100, 2)]
147 for iov
in random.sample(to_remove, len(to_remove)):
149 self.assertEqual(s.iovs, result)
152 """Test intersecting two sets"""
155 iovs.append((i, 0, i+5, -1))
158 a =
IoVSet([IntervalOfValidity.always()])
159 for iov
in random.sample(iovs, len(iovs)):
161 self.assertEqual(a.iovs, result)
162 full =
IoVSet(iovs, allow_overlaps=
True)
166 def load_tests(loader, tests, ignore):
167 """Add the doctests to the list of tests"""
168 tests.addTests(doctest.DocTestSuite(iov))
171 if __name__ ==
"__main__":