def config_setting_test_module(self, test_opts: dict): self.check_test_opts(test_opts) # check if user config path is set or not default_conf: dict = {} if test_opts['config_type'] == 'cli': default_conf = deepcopy(tbears_cli_config_reset) elif test_opts['config_type'] == 'server': default_conf = deepcopy(tbears_server_config_reset) if test_opts.get('user_path', None): with open(test_opts['user_path']) as user_conf_path: user_conf: dict = json.load(user_conf_path) default_conf.update(user_conf) if test_opts['command'] in default_conf: default_conf.update(default_conf[test_opts['command']]) del default_conf[test_opts['command']] whole_possible_cli = self.make_whole_possible_cli(test_opts) for cli in whole_possible_cli: parsed = self.parser.parse_args(cli.split()) # should be refactor, get_icon_conf methods has one more parameter (project param) actual_conf = test_opts['get_config_func'](parsed.command, args=vars(parsed)) expected_conf = deepcopy(default_conf) expected_conf.update( {k: v for k, v in vars(parsed).items() if v is not None}) config_option_list = self.make_config_option_list( parsed_args=vars(parsed), config_name=test_opts['config_type']) # print('============================================cli=============================================') # print('* cli: ', cli) # print('* expected_conf: ', expected_conf) # print('* actual_conf: ', actual_conf) for key in config_option_list: # actual_conf['command'] = 'raise_error' try: self.assertEqual( expected_conf[key], actual_conf[key], msg='\nfailed command: ' + test_opts['command'] + '\nfailed cli: ' + cli + '\nfailed key: ' + key + '\ncase: ' + test_opts['description'] + '\n') except AssertionError as e: self.verificationErrors.append(str(e)) if test_opts['config_type'] == 'cli': tbears_cli_config.update(deepcopy(tbears_cli_config_reset)) elif test_opts['config_type'] == 'server': tbears_server_config.update(deepcopy(tbears_server_config_reset))
def tearDown(self): rm_file_dir(self.tear_down_params) for idx, error in enumerate(self.verificationErrors): print('============ error number: '+str(idx)+' =====================') print(error) print(' ') self.assertEqual([], self.verificationErrors) tbears_server_config.update(deepcopy(tbears_server_config_reset)) tbears_cli_config.update(deepcopy(tbears_cli_config_reset))