| 1 |  |  | """Unit tests for pydecider.activity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 pydecider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | import pydecider.activity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class StepStateTest(unittest.TestCase): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 23 |  | View Code Duplication |     def test_basic_activity(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         """Test basic definition of activities. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         my_act = pydecider.activity.Activity.from_data( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 'name': 'MyActivity', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 'version': '1.0', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 'input_spec': None, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 'outputs_spec': None, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         self.assertEqual(my_act.name, 'MyActivity') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         self.assertEqual(my_act.version, '1.0') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         self.assertTrue(my_act.check_input({'anything': 'goes'})) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         self.assertEqual(my_act.render_outputs({'anything': 'goes'}), {}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         # Test default values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         self.assertEqual(my_act.heartbeat_timeout, '60') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         self.assertEqual(my_act.schedule_to_start_timeout, '43200') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         self.assertEqual(my_act.schedule_to_close_timeout, '518400') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         self.assertEqual(my_act.start_to_close_timeout, '432000') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 45 |  | View Code Duplication |     def test_basic_activity_advanced(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         """Test advanced definition of activities. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         my_act = pydecider.activity.Activity.from_data( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 'name': 'MyActivity2', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 'version': '2.0', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 'task_list': 'foobar', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 'heartbeat_timeout': '42', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 'schedule_to_start_timeout': '43', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 'schedule_to_close_timeout': '44', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 'start_to_close_timeout': '45', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         self.assertEqual(my_act.name, 'MyActivity2') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         self.assertEqual(my_act.version, '2.0') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         self.assertTrue(my_act.check_input({'anything': 'goes'})) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         self.assertEqual(my_act.render_outputs({'anything': 'goes'}), {}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         self.assertEqual(my_act.heartbeat_timeout, '42') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         self.assertEqual(my_act.schedule_to_start_timeout, '43') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         self.assertEqual(my_act.schedule_to_close_timeout, '44') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         self.assertEqual(my_act.start_to_close_timeout, '45') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     def test_input_spec(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         my_act = pydecider.activity.Activity.from_data( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 'name': 'MyActivity', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 'version': '1.0', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 'input_spec': { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                     'type': 'object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                     'properties': { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                         'a': { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                             'type': 'string' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                     'required': ['a'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         self.assertTrue(my_act.check_input({'a': 'hello'})) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         self.assertRaises( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             pydecider.schema.ValidationError, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             my_act.check_input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             {'anything': 'goes'}, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     def test_outputs_spec(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         my_act = pydecider.activity.Activity.from_data( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 'name': 'MyActivity', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 'version': '1.0', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 'outputs_spec': { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     'a': '$', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                     'b': '$.hello', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         self.assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             my_act.render_outputs({'hello': 'world'}), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 'a': {'hello': 'world'}, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 'b': 'world' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         ) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |     def test_invalid_outputs_spec(self): | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         self.assertRaises( | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |             pydecider.schema.ValidationError, | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |             pydecider.activity.Activity.from_data, | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |             { | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |                 'name': 'MyActivity', | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |                 'version': '1.0', | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |                 'outputs_spec': { | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |                     '__bad_name__': 'bad', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | if __name__ == '__main__': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     import logging | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     logging.basicConfig(level=logging.DEBUG) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  |     unittest.main() | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |  | 
            
                        
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.