コード例 #1
0
    def test_deserialize_trail_mismatched_trail(self):
        # Make another DAG:
        #           +--> step_d -->+
        # step_a -->|              |--> step_b
        #           +--> step_c -->+
        def action_a():
            pass

        def action_b():
            pass

        def action_c():
            pass

        def action_d():
            pass

        step_a = Step(action_a)
        step_b = Step(action_b)
        step_c = Step(action_c)
        step_d = Step(action_d)

        trail_definition = [
            (step_a, step_d),
            (step_a, step_c),
            (step_d, step_b),
            (step_c, step_b),
        ]

        mismatching_trail_data = serialize_trail(make_dag(trail_definition))

        with self.assertRaises(MatchTrailsException):
            deserialize_trail(self.root_step, mismatching_trail_data, {})
コード例 #2
0
    def test_backup_trail(self):
        open_patcher = patch('six.moves.builtins.open')
        mock_open = open_patcher.start()
        json_dump_patcher = patch('autotrail.layer2.trail.json.dump')
        mock_json_dump = json_dump_patcher.start()

        backup_trail(self.root_step, 'foo')

        mock_open.assert_called_once_with('foo', 'w')
        mock_open().__exit__.assert_called_once_with(None, None, None)
        mock_json_dump.assert_called_once_with(serialize_trail(self.root_step),
                                               mock_open().__enter__())

        json_dump_patcher.stop()
        open_patcher.stop()
コード例 #3
0
    def test_serialize_trail(self):
        # Make this DAG:
        #           +--> step_b -->+
        # step_a -->|              |--> step_d
        #           +--> step_c -->+
        def action_a():
            pass

        def action_b():
            pass

        def action_c():
            pass

        def action_d():
            pass

        step_a = Step(action_a)
        step_b = Step(action_b)
        step_c = Step(action_c)
        step_d = Step(action_d)

        trail_definition = [
            (step_a, step_b),
            (step_a, step_c),
            (step_b, step_d),
            (step_c, step_d),
        ]

        root_step = make_dag(trail_definition)
        trail_data = serialize_trail(root_step)

        for step in [step_a, step_b, step_c, step_d]:
            self.assertIn(str(step), trail_data)
            self.assertEqual(trail_data[str(step)][StatusField.STATE],
                             str(step.state))
            self.assertEqual(trail_data[str(step)][StatusField.RETURN_VALUE],
                             str(step.return_value))
            for parent in step.parents:
                self.assertIn(str(parent), trail_data[str(step)]['parents'])
コード例 #4
0
    def setUp(self):
        # Make this DAG:
        #           +--> step_b -->+
        # step_a -->|              |--> step_d
        #           +--> step_c -->+
        def action_a():
            pass

        def action_b():
            pass

        def action_c():
            pass

        def action_d():
            pass

        self.step_a = Step(action_a)
        self.step_b = Step(action_b)
        self.step_c = Step(action_c)
        self.step_d = Step(action_d)

        trail_definition = [
            (self.step_a, self.step_b),
            (self.step_a, self.step_c),
            (self.step_b, self.step_d),
            (self.step_c, self.step_d),
        ]

        self.root_step = make_dag(trail_definition)
        self.step_a.return_value = 'mock return value'
        self.step_a.prompt_messages = ['mock prompt_messages']
        self.step_a.output_messages = ['mock output_messages']
        self.step_a.input_messages = ['mock input_messages']

        self.trail_data = serialize_trail(self.root_step)