def test_comparison_operators_different_lines(self): unequal_origin_1 = Origin("file.txt", 10, 13) unequal_origin_2 = Origin("file.txt", 11, 12) unequal_origin_3 = Origin("file.txt", 10, 11) self.assertNotEqual(self.origin, unequal_origin_1) self.assertNotEqual(self.origin, unequal_origin_2) self.assertTrue(self.origin < unequal_origin_1) self.assertTrue(self.origin > unequal_origin_3)
def make_job(name, plugin="dummy", requires=None, depends=None, **kwargs): """ Make and return a dummy JobDefinition instance """ # Jobs are usually loaded from RFC822 records and use the # origin tracking to understand which file they came from. # # Here we can create a Origin instance that pinpoints the # place that called make_job(). This aids in debugging as # the origin field is printed by JobDefinition repr caller_frame, filename, lineno = inspect.stack(0)[1][:3] try: # XXX: maybe create special origin subclass for such things? origin = Origin(filename, lineno, lineno) finally: # Explicitly delete the frame object, this breaks the # reference cycle and makes this part of the code deterministic # with regards to the CPython garbage collector. # # As recommended by the python documentation: # http://docs.python.org/3/library/inspect.html#the-interpreter-stack del caller_frame # Carefully add additional data into the job definition so that we # don't add any spurious None-valued keys that change the checksum. data = {'name': name} if plugin is not None: data['plugin'] = plugin if requires is not None: data['requires'] = requires if depends is not None: data['depends'] = depends # Add any custom key-value properties data.update(kwargs) return JobDefinition(data, origin)
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("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)
def setUp(self): self._full_record = RFC822Record( { 'plugin': 'plugin', 'name': 'name', 'requires': 'requires', 'command': 'command', 'description': 'description' }, Origin('file.txt', 1, 5)) self._full_gettext_record = RFC822Record( { '_plugin': 'plugin', '_name': 'name', '_requires': 'requires', '_command': 'command', '_description': 'description' }, Origin('file.txt.in', 1, 5)) self._min_record = RFC822Record({ 'plugin': 'plugin', 'name': 'name', }, Origin('file.txt', 1, 2))
def test_smoke(self): data = {'key': 'value'} origin = Origin('file.txt', 1, 1) record = RFC822Record(data, origin) self.assertEqual(record.data, data) self.assertEqual(record.origin, origin)
def test_comparison_operators_different_files(self): unequal_origin = Origin("ghostfile.txt", 10, 12) self.assertNotEqual(self.origin, unequal_origin)
def test_equal_operator(self): equal_origin = Origin("file.txt", 10, 12) self.assertEqual(self.origin, equal_origin)
def setUp(self): self.origin = Origin("file.txt", 10, 12)