1 | """Unit tests for pydecider.state_machine |
||
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 collections |
||
18 | import mock |
||
19 | import yaml |
||
0 ignored issues
–
show
|
|||
20 | |||
21 | import pydecider |
||
22 | import pydecider.state |
||
23 | |||
24 | |||
25 | TestParent = collections.namedtuple('TestParent', ['name', 'output']) |
||
26 | |||
27 | |||
28 | class StepStateTest(unittest.TestCase): |
||
0 ignored issues
–
show
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. ![]() |
|||
29 | def setUp(self): |
||
30 | self.mock_step = mock.Mock() |
||
31 | self.step_state = pydecider.state.StepState(step=self.mock_step, |
||
32 | status='running', |
||
33 | context='__test__') |
||
34 | |||
35 | def test_step_prepare_no_parents(self): |
||
36 | """No parents, `step.prepare` called with an empty dict.""" |
||
37 | self.step_state.update('ready', '__test_update__') |
||
38 | self.mock_step.prepare.assert_called_with({}) |
||
39 | |||
40 | def test_step_prepare_parents(self): |
||
41 | """Make sure `step.prepare` is called with a dict of all the parents |
||
42 | attributes. |
||
43 | """ |
||
44 | self.step_state.parents = [ |
||
45 | TestParent('foo', {'a': 1}), |
||
46 | TestParent('bar', {'b': 1}), |
||
47 | TestParent('baz', {'c': 1}), |
||
48 | ] |
||
49 | self.step_state.update('ready', '__test_update__') |
||
50 | self.mock_step.prepare.assert_called_with( |
||
51 | { |
||
52 | 'foo': {'a': 1}, |
||
53 | 'bar': {'b': 1}, |
||
54 | 'baz': {'c': 1}, |
||
55 | } |
||
56 | ) |
||
57 | |||
58 | def test_step_prepare_parents_with_input(self): |
||
0 ignored issues
–
show
The name
test_step_prepare_parents_with_input 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. ![]() |
|||
59 | """Make sure `step.prepare` is called with a dict of all the parents |
||
60 | attributes and that the special input step in properly named. |
||
61 | """ |
||
62 | self.step_state.parents = [ |
||
63 | TestParent('foo', {'a': 1}), |
||
64 | TestParent(pydecider.state.INIT_STEP, {'b': 1}), |
||
65 | TestParent('baz', {'c': 1}), |
||
66 | ] |
||
67 | self.step_state.update('ready', '__test_update__') |
||
68 | self.mock_step.prepare.assert_called_with( |
||
69 | { |
||
70 | 'foo': {'a': 1}, |
||
71 | '__input__': {'b': 1}, |
||
72 | 'baz': {'c': 1}, |
||
73 | } |
||
74 | ) |
||
75 | |||
76 | def test_step_prepare_parents_with_none(self): |
||
0 ignored issues
–
show
The name
test_step_prepare_parents_with_none 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. ![]() |
|||
77 | """Make sure `step.prepare` is called with a dict of all the parents |
||
78 | attributes and parents with None as output are properly handled. |
||
79 | """ |
||
80 | self.step_state.parents = [ |
||
81 | TestParent('foo', {'a': 1}), |
||
82 | TestParent('bar', None), |
||
83 | TestParent('baz', {'c': 1}), |
||
84 | ] |
||
85 | self.step_state.update('ready', '__test_update__') |
||
86 | self.mock_step.prepare.assert_called_with( |
||
87 | { |
||
88 | 'foo': {'a': 1}, |
||
89 | 'bar': None, |
||
90 | 'baz': {'c': 1}, |
||
91 | } |
||
92 | ) |
||
93 | |||
94 | |||
95 | if __name__ == '__main__': |
||
96 | import logging |
||
97 | logging.basicConfig(level=logging.DEBUG) |
||
98 | unittest.main() |
||
99 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.