Exemplo n.º 1
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))
Exemplo n.º 2
0
 def test_gt(self):
     # Verify that Origin instances are ordered by their constituting
     # components.
     self.assertTrue(
         Origin(FileTextSource('file.txt'), 1, 1) < Origin(
             FileTextSource('file.txt'), 1, 2) < Origin(
                 FileTextSource('file.txt'), 1, 3))
     self.assertTrue(
         Origin(FileTextSource('file.txt'), 1, 10) < Origin(
             FileTextSource('file.txt'), 2, 10) < Origin(
                 FileTextSource('file.txt'), 3, 10))
     self.assertTrue(
         Origin(FileTextSource('file1.txt'), 1, 10) < Origin(
             FileTextSource('file2.txt'), 1, 10) < Origin(
                 FileTextSource('file3.txt'), 1, 10))
Exemplo n.º 3
0
 def test_origin_from_filename_is_filename(self):
     # If the test's origin has a filename, we need a valid origin
     # with proper data.
     #
     # We're faking the name by using a StringIO subclass with a
     # name property, which is how rfc822 gets that data.
     expected_origin = Origin(FileTextSource("file.txt"), 1, 1)
     with NamedStringIO("key:value", fake_filename="file.txt") 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)
Exemplo n.º 4
0
 def test_eq(self):
     # Verify instances of Origin are all equal to other instances with the
     # same instance attributes but not equal to instances with different
     # attributes.
     origin1 = Origin(self.origin.source, self.origin.line_start,
                      self.origin.line_end)
     origin2 = Origin(self.origin.source, self.origin.line_start,
                      self.origin.line_end)
     self.assertTrue(origin1 == origin2)
     origin_other1 = Origin(self.origin.source, self.origin.line_start + 1,
                            self.origin.line_end)
     self.assertTrue(origin1 != origin_other1)
     self.assertFalse(origin1 == origin_other1)
     origin_other2 = Origin(self.origin.source, self.origin.line_start,
                            self.origin.line_end + 1)
     self.assertTrue(origin1 != origin_other2)
     self.assertFalse(origin1 == origin_other2)
     origin_other3 = Origin(FileTextSource('unrelated'),
                            self.origin.line_start, self.origin.line_end)
     self.assertTrue(origin1 != origin_other3)
     self.assertFalse(origin1 == origin_other3)
Exemplo n.º 5
0
 def test_str__whole_file(self):
     # verify that Origin.__str__() behaves differently when the range
     # is empty.
     expected = 'file.txt'
     observed = str(Origin(FileTextSource('file.txt')))
     self.assertEqual(expected, observed)
Exemplo n.º 6
0
 def test_str__single_line(self):
     # verify that Origin.__str__() behaves differently when the range
     # describes a single line.
     expected = 'file.txt:15'
     observed = str(Origin(FileTextSource('file.txt'), 15, 15))
     self.assertEqual(expected, observed)
Exemplo n.º 7
0
 def setUp(self):
     self.origin = Origin(FileTextSource('file.txt'), 10, 12)
Exemplo n.º 8
0
 def setUp(self):
     self.raw_data = dict(key=' value')
     self.data = dict(key='value')
     self.origin = Origin(FileTextSource('file.txt'), 1, 1)
     self.record = RFC822Record(self.data, self.origin, self.raw_data)