예제 #1
0
 def setUp(self):
     self._full_record = RFC822Record({
         'plugin': 'plugin',
         'id': 'id',
         'summary': 'summary-value',
         'requires': 'requires',
         'command': 'command',
         'description': 'description-value'
     }, Origin(FileTextSource('file.txt'), 1, 5))
     self._full_gettext_record = RFC822Record({
         '_plugin': 'plugin',
         '_id': 'id',
         '_summary': 'summary-value',
         '_requires': 'requires',
         '_command': 'command',
         '_description': 'description-value',
         '_siblings': '[{"id": "foo", "depends": "bar"}]'
     }, Origin(FileTextSource('file.txt.in'), 1, 5))
     self._min_record = RFC822Record({
         'plugin': 'plugin',
         'id': 'id',
     }, Origin(FileTextSource('file.txt'), 1, 2))
     self._split_description_record = RFC822Record({
         'id': 'id',
         'purpose': 'purpose-value',
         'steps': 'steps-value',
         'verification': 'verification-value'
     }, Origin(FileTextSource('file.txt'), 1, 1))
예제 #2
0
    def setUp(self):
        A = make_job('A')
        B = make_job('B', plugin='local', description='foo')
        C = make_job('C')
        D = B.create_child_job_from_record(
            RFC822Record(data={
                'id': 'D',
                'plugin': 'shell'
            },
                         origin=Origin(source=JobOutputTextSource(B),
                                       line_start=1,
                                       line_end=1)))
        E = B.create_child_job_from_record(
            RFC822Record(data={
                'id': 'E',
                'plugin': 'local',
                'description': 'bar'
            },
                         origin=Origin(source=JobOutputTextSource(B),
                                       line_start=1,
                                       line_end=1)))
        F = E.create_child_job_from_record(
            RFC822Record(data={
                'id': 'F',
                'plugin': 'shell'
            },
                         origin=Origin(source=JobOutputTextSource(E),
                                       line_start=1,
                                       line_end=1)))
        G = make_job('G', plugin='local', description='baz')
        R = make_job('R', plugin='resource')
        Z = make_job('Z', plugin='local', description='zaz')

        self.tree = JobTreeNode.create_tree([R, B, C, D, E, F, G, A, Z],
                                            legacy_mode=True)
예제 #3
0
 def setUp(self):
     self.A = make_job('a', name='A')
     self.B = make_job('b', name='B', plugin='local', description='foo')
     self.C = make_job('c', name='C')
     self.D = self.B.create_child_job_from_record(
         RFC822Record(data={
             'id': 'd',
             'name': 'D',
             'plugin': 'shell'
         },
                      origin=Origin(source=JobOutputTextSource(self.B),
                                    line_start=1,
                                    line_end=1)))
     self.E = self.B.create_child_job_from_record(
         RFC822Record(data={
             'id': 'e',
             'name': 'E',
             'plugin': 'shell'
         },
                      origin=Origin(source=JobOutputTextSource(self.B),
                                    line_start=1,
                                    line_end=1)))
     self.F = make_job('f', name='F', plugin='resource', description='baz')
     self.tree = SelectableJobTreeNode.create_tree(
         [self.A, self.B, self.C, self.D, self.E, self.F], legacy_mode=True)
 def setUp(self):
     self._record = RFC822Record({
         'id': 'id',
         'name': 'name',
     }, Origin(FileTextSource('file.txt'), 1, 2))
     self._gettext_record = RFC822Record({
         '_id': 'id',
         '_name': 'name'
     }, Origin(FileTextSource('file.txt.in'), 1, 2))
     warnings.filterwarnings('ignore',
                             'validate is deprecated since version 0.11')
예제 #5
0
 def test_via_does_not_change_checksum(self):
     """
     verify that the 'via' attribute in no way influences job checksum
     """
     # Create a 'parent' job
     parent = JobDefinition({'id': 'parent', 'plugin': 'local'})
     # Create a 'child' job, using create_child_job_from_record() should
     # time the two so that child.via should be parent.checksum.
     #
     # The elaborate record that gets passed has all the meta-data that
     # traces back to the 'parent' job (as well as some imaginary line_start
     # and line_end values for the purpose of the test).
     child = parent.create_child_job_from_record(
         RFC822Record(data={
             'id': 'test',
             'plugin': 'shell'
         },
                      origin=Origin(source=JobOutputTextSource(parent),
                                    line_start=1,
                                    line_end=1)))
     # Now 'child.via' should be the same as 'parent.checksum'
     self.assertEqual(child.via, parent.checksum)
     # Create an unrelated job 'helper' with the definition identical as
     # 'child' but without any ties to the 'parent' job
     helper = JobDefinition({'id': 'test', 'plugin': 'shell'})
     # And again, child.checksum should be the same as helper.checksum
     self.assertEqual(child.checksum, helper.checksum)
예제 #6
0
 def dump(self, data, stream):
     entry = OrderedDict()
     string_stream = StringIO()
     for job_name, job_data in sorted(data['result_map'].items()):
         entry['name'] = job_name
         entry.update(job_data)
         RFC822Record(entry).dump(string_stream)
     stream.write(string_stream.getvalue().encode('UTF-8'))
예제 #7
0
 def setUp(self):
     self._record = RFC822Record(
         {
             'id': 'id',
             'unit': 'exporter',
             '_summary': 'summary',
             'entry_point': 'text',
             'file_extension': 'file_extension',
         }, Origin(FileTextSource('file.txt'), 1, 2))
예제 #8
0
 def test_parse_typical(self):
     """
     verify typical operation without any parsing errors
     """
     # Setup a mock job and result, give some io log to the result
     job = mock.Mock(spec=JobDefinition)
     result = mock.Mock(spec=IJobResult)
     result.get_io_log.return_value = [(0, 'stdout', b'attr: value1\n'),
                                       (0, 'stdout', b'\n'),
                                       (0, 'stdout', b'attr: value2\n')]
     # Parse the IO log records
     records = list(gen_rfc822_records_from_io_log(job, result))
     # Ensure that we saw both records
     self.assertEqual(records, [
         RFC822Record({'attr': 'value1'},
                      Origin(JobOutputTextSource(job), 1, 1)),
         RFC822Record({'attr': 'value2'},
                      Origin(JobOutputTextSource(job), 3, 3)),
     ])
 def setUp(self):
     self._record = RFC822Record(
         {
             'id': 'id',
             'unit': 'exporter',
             '_summary': 'summary',
             'entry_point': 'text',
             'file_extension': 'file_extension',
         }, Origin(FileTextSource('file.txt'), 1, 2))
     warnings.filterwarnings('ignore',
                             'validate is deprecated since version 0.11')
예제 #10
0
 def setUp(self):
     self._full_record = RFC822Record(
         {
             'plugin': 'plugin',
             'id': 'id',
             'summary': 'summary',
             'requires': 'requires',
             'command': 'command',
             'description': 'description'
         }, Origin(FileTextSource('file.txt'), 1, 5))
     self._full_gettext_record = RFC822Record(
         {
             '_plugin': 'plugin',
             '_id': 'id',
             '_summary': 'summary',
             '_requires': 'requires',
             '_command': 'command',
             '_description': 'description'
         }, Origin(FileTextSource('file.txt.in'), 1, 5))
     self._min_record = RFC822Record({
         'plugin': 'plugin',
         'id': 'id',
     }, Origin(FileTextSource('file.txt'), 1, 2))
예제 #11
0
 def test_equality(self):
     # Equality is compared by normalized data, the raw data doesn't count
     other_raw_data = {'key': 'value '}
     # This other raw data is actually different to the one we're going to
     # test against
     self.assertNotEqual(other_raw_data, self.raw_data)
     # Let's make another record with different raw data
     other_record = RFC822Record(self.data, self.origin, other_raw_data)
     # The normalized data is identical
     self.assertEqual(other_record.data, self.record.data)
     # The raw data is not
     self.assertNotEqual(other_record.raw_data, self.record.raw_data)
     # The origin is the same (just a sanity check)
     self.assertEqual(other_record.origin, self.record.origin)
     # Let's look at the whole object, they should be equal
     self.assertTrue(other_record == self.record)
     self.assertTrue(not (other_record != self.record))
예제 #12
0
 def test_parse_error(self, mock_logger):
     # Setup a mock job and result, give some io log to the result
     job = mock.Mock(spec=JobDefinition)
     result = mock.Mock(spec=IJobResult)
     result.get_io_log.return_value = [(0, 'stdout', b'attr: value1\n'),
                                       (0, 'stdout', b'\n'),
                                       (0, 'stdout', b'error\n'),
                                       (0, 'stdout', b'\n'),
                                       (0, 'stdout', b'attr: value2\n')]
     # Parse the IO log records
     records = list(gen_rfc822_records_from_io_log(job, result))
     # Ensure that only the first record was generated
     self.assertEqual(records, [
         RFC822Record({'attr': 'value1'},
                      Origin(JobOutputTextSource(job), 1, 1)),
     ])
     # Ensure that a warning was logged
     mock_logger.warning.assert_called_once_with(
         "local script %s returned invalid RFC822 data: %s", job,
         RFC822SyntaxError(None, 3,
                           "Unexpected non-empty line: 'error\\n'"))
예제 #13
0
 def test_multiple_record(self):
     with StringIO() as stream:
         RFC822Record({'key1': 'value1', 'key2': 'value2'}).dump(stream)
         self.assertIn(stream.getvalue(),
                       ("key1: value1\nkey2: value2\n\n",
                        "key2: value2\nkey1: value1\n\n"))
예제 #14
0
 def test_from_rfc822_record_missing_id(self):
     record = RFC822Record({'plugin': 'plugin'})
     with self.assertRaises(ValueError):
         JobDefinition.from_rfc822_record(record)
예제 #15
0
 def test_multiline_value_with_period(self):
     text = ("key:\n" " longer\n" " ..\n" " value\n\n")
     with StringIO() as stream:
         RFC822Record({'key': 'longer\n.\nvalue'}).dump(stream)
         self.assertEqual(stream.getvalue(), text)
예제 #16
0
 def test_single_record(self):
     with StringIO() as stream:
         RFC822Record({'key': 'value'}).dump(stream)
         self.assertEqual(stream.getvalue(), "key: value\n\n")
예제 #17
0
 def setUp(self):
     self.raw_data = {'key': ' value'}
     self.data = {'key': 'value'}
     self.origin = Origin(FileTextSource('file.txt'), 1, 1)
     self.record = RFC822Record(self.data, self.origin, self.raw_data)
예제 #18
0
 def test_type_error(self):
     with StringIO() as stream:
         with self.assertRaises(AttributeError):
             RFC822Record(['key', 'value']).dump(stream)