Exemplo n.º 1
0
 def test_delete_removes_definition(self):
     parser_def = ParserDefinition.create('test_script.py')
     json_data = argutil.load(parser_def.definitions_file)
     self.assertIn(parser_def.module, json_data['modules'])
     parser_def.delete()
     json_data = argutil.load(parser_def.definitions_file)
     self.assertNotIn(parser_def.module, json_data['modules'])
Exemplo n.º 2
0
 def test_delete_removes_defaults(self):
     parser_def = ParserDefinition.create('test_script.py')
     parser_def.add_argument('--foo')
     parser_def.set_defaults(foo='bar')
     json_data = argutil.load(parser_def.defaults_file)
     self.assertIn(parser_def.module, json_data)
     parser_def.delete()
     json_data = argutil.load(parser_def.defaults_file)
     self.assertNotIn(parser_def.module, json_data)
Exemplo n.º 3
0
 def test_load_returns_file_contents(self):
     expected = {
         'modules': {
             'test_script': {}
         }
     }
     self.create_json_file(DEFINITIONS_FILE, expected)
     self.assertDictEqual(argutil.load(DEFINITIONS_FILE), expected)
Exemplo n.º 4
0
 def test_init_definitions_file_contains_correct_structure(self):
     ParserDefinition.create('test_script.py', DEFINITIONS_FILE)
     expected = {
         'modules': {
             'test_script': {
                 'examples': [],
                 'args': []
             }
         }
     }
     self.assertDictEqual(argutil.load(DEFINITIONS_FILE), expected)
Exemplo n.º 5
0
 def test_create_appends_to_existing_definitions_file(self):
     base_data = {
         'modules': {
             'existing_module': {
                 'examples': [],
                 'args': []
             }
         }
     }
     self.create_json_file(DEFINITIONS_FILE, base_data)
     ParserDefinition.create('test_script.py', DEFINITIONS_FILE)
     expected = {
         'modules': {
             'existing_module': {
                 'examples': [],
                 'args': []
             },
             'test_script': {
                 'examples': [],
                 'args': []
             }
         }
     }
     self.assertDictEqual(argutil.load(DEFINITIONS_FILE), expected)
Exemplo n.º 6
0
 def test_load_error_unknown_file_mode(self):
     with self.assertRaises(ValueError):
         argutil.load(DEFINITIONS_FILE, 'u')
Exemplo n.º 7
0
 def test_load_create_mode_ignores_file_contents(self):
     self.create_json_file(DEFINITIONS_FILE, {})
     expected = {}
     self.assertDictEqual(argutil.load(DEFINITIONS_FILE, 'w'), expected)
Exemplo n.º 8
0
 def test_load_error_nonexistent_file_mode_read_only(self):
     self.assertIs(os.path.isfile(DEFINITIONS_FILE), False)
     with self.assertRaises(FileNotFoundError):
         argutil.load(DEFINITIONS_FILE, 'r')
Exemplo n.º 9
0
 def test_load_nonexistent_file_not_created(self):
     self.assertIs(os.path.isfile(DEFINITIONS_FILE), False)
     argutil.load(DEFINITIONS_FILE)
     self.assertIs(os.path.isfile(DEFINITIONS_FILE), False)
Exemplo n.º 10
0
 def test_load_returns_empty_data_on_nonexistent_file(self):
     self.assertIs(os.path.isfile(DEFINITIONS_FILE), False)
     expected = {}
     self.assertDictEqual(argutil.load(DEFINITIONS_FILE), expected)
Exemplo n.º 11
0
 def assertModifiedModule(self, expected=None, script='test_script.py'):
     with TempWorkingDirectory(WD, False):
         parser_def = argutil.ParserDefinition.create(script)
         yield parser_def
         self.assertDictEqual(argutil.load(DEFINITIONS_FILE), expected)
Exemplo n.º 12
0
 def test_set_defaults_nested(self):
     parser_def = argutil.ParserDefinition.create('test_script.py')
     parser_def.set_defaults(**{"command1.command2": "value"})
     expected = {"test_script": {"command1": {"command2": "value"}}}
     actual = argutil.load(parser_def.defaults_file)
     self.assertDictEqual(actual, expected)