def _to_lines_by_slice(self, conds, no_config=False): # [10:20] # ^^^^^ # body body = conds[1:-1] start, end = body.split(':', 1) def conv(s): if s=='': return None return int(s) start = conv(start) end = conv(end) return util.slice_friendly(self.to_lines(no_config=no_config), start, end)
def test_slice_friendly(self): a = [1,2,3,4,5] self.assertEqual(a, util.slice_friendly(a, 1, 5)) self.assertEqual([1,2,3], util.slice_friendly(a, 1, 3)) self.assertEqual([2,3], util.slice_friendly(a, 2, 3)) self.assertEqual([3], util.slice_friendly(a, 3, 3)) self.assertEqual([4,5], util.slice_friendly(a, 4, 5)) self.assertEqual(a, util.slice_friendly(a, 1, None)) self.assertEqual([5], util.slice_friendly(a, 5, None)) self.assertEqual([3,4,5], util.slice_friendly(a, 3, None)) self.assertEqual([1], util.slice_friendly(a, None, 1)) self.assertEqual([1,2,3], util.slice_friendly(a, None, 3)) self.assertEqual(a, util.slice_friendly(a, None, 5)) self.assertEqual(a, util.slice_friendly(a, None, None))