Example #1
0
 def test_with_offset(self):
     # Verify how Origin.with_offset() works as expected.
     origin1 = Origin(UnknownTextSource(), 1, 2)
     origin2 = origin1.with_offset(10)
     self.assertEqual(origin2.line_start, 11)
     self.assertEqual(origin2.line_end, 12)
     self.assertIs(origin2.source, origin1.source)
Example #2
0
 def test_origin_from_stream_is_Unknown(self):
     # Verify that gen_rfc822_records() uses origin instances with source
     # equal to UnknownTextSource, when no explicit source is provided and
     # the stream has no name to infer a FileTextSource() from.
     expected_origin = Origin(UnknownTextSource(), 1, 1)
     with StringIO("key:value") as stream:
         records = type(self).loader(stream)
     self.assertEqual(len(records), 1)
     self.assertEqual(records[0].data, {'key': 'value'})
     self.assertEqual(records[0].origin, expected_origin)
Example #3
0
 def test_relative_to(self):
     # Verify how Origin.relative_to() works in various situations.
     #
     # If the source does not have relative_to method, nothing is changed.
     origin = Origin(UnknownTextSource(), 1, 2)
     self.assertIs(origin.relative_to('/some/path'), origin)
     # otherwise the source is replaced and a new origin is returned
     self.assertEqual(
         Origin(FileTextSource('/some/path/file.txt'), 1,
                2).relative_to('/some/path'),
         Origin(FileTextSource('file.txt'), 1, 2))
Example #4
0
 def test_just_file(self):
     origin1 = Origin(UnknownTextSource(), 1, 2)
     origin2 = origin1.just_file()
     self.assertEqual(origin2.line_start, None)
     self.assertEqual(origin2.line_end, None)
     self.assertIs(origin2.source, origin1.source)
Example #5
0
 def test_with_offset_whole_file(self):
     origin1 = Origin(UnknownTextSource())
     self.assertEqual(origin1.mode(), OriginMode.whole_file)
     self.assertEqual(origin1.with_offset(10), origin1)
Example #6
0
 def test_gt(self):
     # Verify that instances of UnknownTextSource are not ordered.
     other_src = UnknownTextSource()
     self.assertFalse(self.src < other_src)
     self.assertFalse(other_src < self.src)
Example #7
0
 def test_eq(self):
     # Verify instances of UnknownTextSource are all equal to each other
     # but not equal to any other object.
     other_src = UnknownTextSource()
     self.assertTrue(self.src == other_src)
     self.assertFalse(self.src == "???")
Example #8
0
 def setUp(self):
     self.src = UnknownTextSource()