def test_parse_range(self): self.assertEqual(util.parse_range(""), []) self.assertEqual(util.parse_range("1-2"), [(1, 2)]) self.assertEqual(util.parse_range("-"), [(1, sys.maxsize)]) self.assertEqual(util.parse_range("-2,4,6-8,10-"), [(1, 2), (4, 4), (6, 8), (10, sys.maxsize)]) self.assertEqual(util.parse_range(" - 3 , 4- 4, 2-6"), [(1, 3), (4, 4), (2, 6)])
def test_range_predicate(self): dummy = None pred = util.RangePredicate(util.parse_range(" - 3 , 4- 4, 2-6")) for i in range(6): self.assertTrue(pred(dummy, dummy)) with self.assertRaises(exception.StopExtraction): bool(pred(dummy, dummy)) pred = util.RangePredicate(util.parse_range("1, 3, 5")) self.assertTrue(pred(dummy, dummy)) self.assertFalse(pred(dummy, dummy)) self.assertTrue(pred(dummy, dummy)) self.assertFalse(pred(dummy, dummy)) self.assertTrue(pred(dummy, dummy)) with self.assertRaises(exception.StopExtraction): bool(pred(dummy, dummy)) pred = util.RangePredicate(util.parse_range("")) with self.assertRaises(exception.StopExtraction): bool(pred(dummy, dummy))