22 """Helper class to test an IoV"""
25 """Helper function to turn a tuple/None/list(tuple) into iov instances"""
26 if isinstance(iov, list):
34 """Test that we get errors when creating invalid iovs"""
35 with self.assertRaises(ValueError):
37 with self.assertRaises(ValueError):
39 with self.assertRaises(ValueError):
41 with self.assertRaises(ValueError):
43 with self.assertRaises(ValueError):
45 with self.assertRaises(ValueError):
47 with self.assertRaises(ValueError):
49 with self.assertRaises(ValueError):
52 self.assertEqual(iov.final, (math.inf, math.inf))
54 self.assertEqual(iov.final, (1, math.inf))
58 """Test that we can intersect iovs"""
59 iov = IntervalOfValidity
61 [(0, 0, 10, 0), (11, 10, 11, 12),
None],
62 [(0, 0, 10, 0), (8, 0, 10, 12), (8, 0, 10, 0)],
63 [(0, 0, 0, 0), (0, 0, -1, -1), (0, 0, 0, 0)],
64 [(0, 0, -1, -1), (20, 12, 21, 234), (20, 12, 21, 234)],
65 [(0, 0, 2, -1), (1, 1, 2, 8), (1, 1, 2, 8)],
66 [(1, 2, 2, -1), (0, 0, 2, 8), (1, 2, 2, 8)],
67 [(1, 0, 3, -1), (0, 0, 2, -1), (1, 0, 2, -1)],
68 [(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],
70 self.assertEqual(iov(a) & iov(b), self.
iovify(c), f
'{a} & {b} = {c}')
71 self.assertEqual(iov(b) & iov(a), self.
iovify(c), f
'{a} & {b} = {c}')
74 """Test that we can calculate the union of iovs"""
75 iov = IntervalOfValidity
77 [(0, 0, 10, 0), (11, 10, 11, 12),
None],
78 [(0, 0, 10, 0), (8, 0, 10, 12), (0, 0, 10, 12)],
79 [(0, 0, 0, 0), (0, 0, -1, -1), (0, 0, -1, -1)],
80 [(0, 0, -1, -1), (20, 12, 21, 234), (0, 0, -1, -1)],
81 [(0, 0, 2, -1), (1, 1, 2, 8), (0, 0, 2, -1)],
82 [(1, 2, 2, -1), (0, 0, 2, 8), (0, 0, 2, -1)],
83 [(1, 0, 3, -1), (0, 0, 2, -1), (0, 0, 3, -1)],
84 [(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],
85 [(0, 0, 1, 1), (1, 2, 1, 3), (0, 0, 1, 3)],
86 [(0, 0, 1, 1), (1, 3, 1, 4),
None],
87 [(0, 0, 1, -1), (2, 0, 2, 1), (0, 0, 2, 1)],
88 [(0, 0, 1, -1), (2, 0, 2, 1), (0, 0, 2, 1)],
89 [(0, 0, 1, -1), (2, 1, 2, 1),
None],
90 [(0, 0, 1, -1), (1, 9999, 2, 1), (0, 0, 2, 1)],
92 self.assertEqual(iov(a) | iov(b), self.
iovify(c), f
'{a} | {b} = {c}')
93 self.assertEqual(iov(b) | iov(a), self.
iovify(c), f
'{a} | {b} = {c}')
96 """Test that we can calculate the union starting at run 1 as well"""
97 iov = IntervalOfValidity
98 self.assertEqual(iov(0, 0, 1, -1).union(iov(2, 1, 2, -1)),
None)
99 self.assertEqual(iov(0, 0, 1, -1).union(iov(2, 1, 2, -1),
True), iov(0, 0, 2, -1))
102 """Test subtracting iovs from another"""
103 iov = IntervalOfValidity
105 [(0, 0, 10, 0), (11, 10, 11, 12), (0, 0, 10, 0), (11, 10, 11, 12)],
106 [(0, 0, 10, 0), (8, 0, 10, 12), (0, 0, 7, -1), (10, 1, 10, 12)],
107 [(0, 0, 0, 0), (0, 0, -1, -1),
None, (0, 1, -1, -1)],
108 [(0, 0, -1, -1), (20, 12, 21, 234), [(0, 0, 20, 11), (21, 235, -1, -1)],
None],
109 [(0, 0, 2, -1), (1, 1, 2, 8), [(0, 0, 1, 0), (2, 9, 2, -1)],
None],
110 [(1, 2, 2, -1), (0, 0, 2, 8), (2, 9, 2, -1), (0, 0, 1, 1)],
111 [(1, 0, 3, -1), (0, 0, 2, -1), (3, 0, 3, -1), (0, 0, 0, -1)],
112 [(0, 0, -1, -1), (0, 0, -1, -1),
None,
None],
113 [(0, 0, 1, -1), (0, 0, 1, -1),
None,
None],
114 [(0, 0, 0, 0), (0, 0, 0, 0),
None,
None],
115 [(0, 0, 1, -1), (2, 0, 2, -1), (0, 0, 1, -1), (2, 0, 2, -1)],
116 [(11, 0, 12, 86), (0, 0, 11, -1), (12, 0, 12, 86), (0, 0, 10, -1)],
118 self.assertEqual(iov(a) - iov(b), self.
iovify(c), f
'{a} - {b} = {c}')
119 self.assertEqual(iov(b) - iov(a), self.
iovify(d), f
'{b} - {a} = {d}')
123 """Helper class to test a set of IoVs"""
126 """Test adding iovs to a set"""
128 [(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)],
129 [(0, i, 0, i)
for i
in range(0, 100)],
130 [(0, i, 0, i)
for i
in range(0, 100, 2)],
133 [(0, 0, 1, -1), (2, 1, 2, -1), (3, 1, 3, 6), (3, 8, 3, 8)],
135 [(0, i, 0, i)
for i
in range(0, 100, 2)],
139 for input, output
in zip(inputs, results):
141 for iov
in random.sample(input, len(input)):
144 self.assertEqual(s.iovs, output)
147 """Test removing iovs from a set"""
149 s.add((0, 0, 0, 100))
150 to_remove = [(0, i, 0, i)
for i
in range(0, 100, 2)]
154 for iov
in random.sample(to_remove, len(to_remove)):
156 self.assertEqual(s.iovs, result)
159 """Test intersecting two sets"""
162 iovs.append((i, 0, i + 5, -1))
165 a =
IoVSet([IntervalOfValidity.always()])
166 for iov
in random.sample(iovs, len(iovs)):
168 self.assertEqual(a.iovs, result)
169 full =
IoVSet(iovs, allow_overlaps=
True)
173def load_tests(loader, tests, ignore):
174 """Add the doctests to the list of tests"""
179if __name__ ==
"__main__":
def test_union_startone(self)
def test_intersection(self)
def test_intersection(self)