def test_not_aligned_ranges(self): start = 5 stop = 25 step = 10 range_set = RangeSet(start, stop, step) self.assertEqual(range_set.ranges, [Range(5, 9), Range(10, 19), Range(20, 25)])
class RangeSetTestCase(unittest.TestCase): def setUp(self): self.start = 0 self.stop = 49 self.step = 10 self.range_set = RangeSet(self.start, self.stop, self.step) def test_simple(self): workers = list(self.range_set.generate_workers()) expected_workers = [MultiRangeWorker(0, 49, 10)] self.assertEqual(workers, expected_workers) def test_add_subrange(self): sub_range = SubRange(22, 25, value=42) self.range_set.add_sub_range(sub_range) workers = list(self.range_set.generate_workers()) expected_range = Range(20, 29) expected_range.missing_ranges = [SubRange(20, 21), SubRange(26, 29)] expected_range.sub_ranges = [sub_range] partial_range_worker = RangeWorker(expected_range) expected_workers = [MultiRangeWorker(0, 19, 10), partial_range_worker, MultiRangeWorker(30, 49, 10)] self.assertEqual(workers, expected_workers) def test_not_aligned_ranges(self): start = 5 stop = 25 step = 10 range_set = RangeSet(start, stop, step) self.assertEqual(range_set.ranges, [Range(5, 9), Range(10, 19), Range(20, 25)])
def setUp(self): self.start = 0 self.stop = 49 self.step = 10 self.range_set = RangeSet(self.start, self.stop, self.step)