StepTest.test_activity_step_create()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
1
"""Unit tests for pydecider.step
2
"""
3
4
import os
5
import sys
6
import unittest
7
8
sys.path.append(
9
    os.path.realpath(
10
        os.path.join(
11
            os.path.dirname(__file__),
12
            '..'
13
        )
14
    )
15
)
16
17
import mock
18
19
from pydecider.step import Step, StepDefinitionError
20
from pydecider.state import StepStateStatus
21
22
23
class StepTest(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
24
    def setUp(self):
25
        self.activities = {
26
            'test1': mock.Mock(),
27
        }
28
29
    def test_step_create_bad_data(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
30
        step_data = {
31
            "name": "bad",
32
        }
33
34
        self.assertRaises(
35
            ValueError,
36
            Step.from_data,
37
            step_data,
38
            self.activities
39
        )
40
41
    def test_step_create_requires(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
42
        step_data = {
43
            "name": "test",
44
            "activity": "test1",  # Note: Not checking activity here
45
            "requires": ["foo", ("bar", "succeeded"), ("baz", "failed")],
46
        }
47
48
        step = Step.from_data(step_data, self.activities)
49
50
        self.assertEquals(
51
            step.requires,
52
            {
53
                'foo': StepStateStatus.completed,
54
                'bar': StepStateStatus.succeeded,
55
                'baz': StepStateStatus.failed,
56
            }
57
        )
58
59
    def test_activity_step_create(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
60
        step_data = {
61
            "name": "test",
62
            "activity": "test1",
63
        }
64
65
        step = Step.from_data(step_data, self.activities)
66
67
        self.assertEquals(step.name, 'test')
68
        self.assertTrue(step.activity is self.activities['test1'])
69
        self.assertTrue(step.input_template is None)
70
71
    def test_activity_step_create_no_activity(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_activity_step_create_no_activity does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
72
        step_data = {
73
            "name": "test",
74
            "activity": "test2",
75
        }
76
77
        self.assertRaises(
78
            KeyError,
79
            Step.from_data,
80
            step_data,
81
            self.activities
82
        )
83
84
    def test_activity_step_create_bad_status(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_activity_step_create_bad_status does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
85
        step_data = {
86
            "name": "test",
87
            "activity": "test1",
88
            "requires": [("foo", "blah")],
89
        }
90
91
        self.assertRaises(
92
            StepDefinitionError,
93
            Step.from_data,
94
            step_data,
95
            self.activities
96
        )
97
98
    def test_activity_step_input_template(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_activity_step_input_template does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
99
        step_data = {
100
            "name": "test",
101
            "activity": "test1",
102
            "requires": ["foo"],
103
            "input": ('{'
104
                '"a": {{foo}},'
105
                '"b": {{__input__}},'
106
                '"c": {{__input__.who}}'
107
            '}')
108
        }
109
110
        step = Step.from_data(step_data, self.activities)
111
112
        self.assertEquals(
113
            step.prepare({
114
                "foo": "hello",
115
                "__input__": {
116
                    "who": "world"
117
                }
118
            }),
119
            {
120
                'a': 'hello',
121
                'b': {
122
                    'who': 'world'
123
                },
124
                'c': 'world'
125
            }
126
        )
127
128
if __name__ == '__main__':
129
    import logging
130
    logging.basicConfig(level=logging.DEBUG)
131
    unittest.main()
132