Skip to content

Fix unit test for segment.__contains__ in Python 3

Leo P. Singer requested to merge leo-singer/glue:fix-containts-test into master

Paraphrasing the documentation for glue.segment.__contains__ in glue/segments.py: if a is a segment or a sequence of length two, then a in b tests if b[0] <= a[0] <= a[1] <= b[1]. Otherwise, a in b tests if b[0] <= a <= b[1]. The following four tests happen to work and return False in Python 2, but they raise a TypeError in Python 3 because Python does not permit comparisons of numbers with sequences (the exception message is '<' not supported between instances of 'list' and 'int').

self.assertEqual(False, [] in segments.segment(0, 4))
self.assertEqual(False, [0] in segments.segment(0, 4))
self.assertEqual(False, [2] in segments.segment(0, 4))
self.assertEqual(False, [1, 2, 3] in segments.segment(0, 4))

Merge request reports

Loading