def __init__(self, code_style_config: CodeStyleConfig = CodeStyleConfig(), postprocess_config: PostprocessConfig = PostprocessConfig(), etc_config: EtcConfig = EtcConfig()): self.code_style_config = code_style_config self.postprocess_config = postprocess_config self.etc_config = etc_config
def load(cls, fp: TextIO, args: Optional[Namespace] = None): """ :param fp: .toml file's file pointer :param args: command line arguments :return: Config instance """ config_dic = toml.load(fp) code_style_config_dic = config_dic.get('codestyle', {}) postprocess_config_dic = config_dic.get('postprocess', {}) etc_config_dic = config_dic.get('etc', {}) if args: code_style_config_dic = _update_config_dict(code_style_config_dic, dict(template_file=args.template, workspace_dir=args.workspace, lang=args.lang)) etc_config_dic = _update_config_dict(etc_config_dic, dict(download_without_login=args.without_login, parallel_download=args.parallel, save_no_session_cache=args.save_no_session_cache)) return Config( code_style_config=CodeStyleConfig(**code_style_config_dic), postprocess_config=PostprocessConfig(**postprocess_config_dic), etc_config=EtcConfig(**etc_config_dic) )
def test_prepare_contest_aborts_after_max_retry_attempts(self, mock_sleep): mock_client = mock.Mock(spec=AtCoderClient) mock_client.download_problem_list.return_value = [] self.assertRaises( EnvironmentInitializationError, prepare_contest, mock_client, "agc029", Config( code_style_config=CodeStyleConfig( workspace_dir=self.temp_dir, template_file=TEMPLATE_PATH, lang="cpp", ), etc_config=EtcConfig( in_example_format="input_{}.txt", out_example_format="output_{}.txt" )) ) self.assertEqual(mock_sleep.call_count, 10) mock_sleep.assert_has_calls([mock.call(1.5), mock.call(3.0), mock.call(6.0), mock.call(12.0), mock.call(24.0), mock.call(48.0), mock.call(60.0), mock.call(60.0), mock.call(60.0), mock.call(60.0)])
def test_backup(self): answer_data_dir_path = os.path.join(RESOURCE_DIR, "test_backup") # Prepare workspace twice for _ in range(2): prepare_contest( AtCoderClient(), "agc029", Config(code_style_config=CodeStyleConfig( workspace_dir=self.temp_dir, template_file=TEMPLATE_PATH, lang="cpp", ), etc_config=EtcConfig( in_example_format="input_{}.txt", out_example_format="output_{}.txt"))) self.assertDirectoriesEqual(answer_data_dir_path, self.temp_dir)
def load(cls, fp: TextIO, args: Optional[Namespace] = None): """ :param fp: .toml file's file pointer :param args: command line arguments :return: Config instance """ config_dic = toml.load(fp) code_style_config_dic = config_dic.get('codestyle', {}) postprocess_config_dic = config_dic.get('postprocess', {}) etc_config_dic = config_dic.get('etc', {}) if args: d = dict() if hasattr(args, 'template'): d['template_file'] = args.template if hasattr(args, 'workspace'): d['workspace_dir'] = args.workspace if hasattr(args, 'lang'): d['lang'] = args.lang code_style_config_dic = _update_config_dict( code_style_config_dic, d) lang = code_style_config_dic['lang'] if lang in config_dic: code_style_config_dic = _update_config_dict( code_style_config_dic, config_dic[lang]) d = dict() if hasattr(args, 'without_login'): d['download_without_login'] = args.without_login if hasattr(args, 'parallel'): d['parallel_download'] = args.parallel if hasattr(args, 'save_no_session_cache'): d['save_no_session_cache'] = args.save_no_session_cache etc_config_dic = _update_config_dict(etc_config_dic, d) print(code_style_config_dic) return Config( code_style_config=CodeStyleConfig(**code_style_config_dic), postprocess_config=PostprocessConfig(**postprocess_config_dic), etc_config=EtcConfig(**etc_config_dic))
def load(cls, fp: TextIO, args: Optional[ProgramArgs] = None): """ :param fp: .toml file's file pointer :param args: command line arguments :return: Config instance """ config_dic = toml.load(fp) # Root 'codestyle' is common code style common_code_style_config_dic = config_dic.get( _CODE_STYLE_CONFIG_KEY, {}) postprocess_config_dic = config_dic.get(_POST_PROCESS_CONFIG_KEY, {}) etc_config_dic = config_dic.get('etc', {}) run_config_dic = config_dic.get(_RUN_CONFIG_KEY, {}) code_style_config_dic = {**common_code_style_config_dic} # Handle config override strategy in the following code # (Most preferred) program arguments > lang-specific > common config (Least preferred) lang = (args and args.lang) or common_code_style_config_dic.get( "lang", DEFAULT_LANGUAGE) code_style_config_dic = _update_config_dict( code_style_config_dic, dict(lang=lang)) if lang in config_dic: lang_specific_config_dic = config_dic[lang] # e.g. [cpp.codestyle] if _CODE_STYLE_CONFIG_KEY in lang_specific_config_dic: lang_code_style = lang_specific_config_dic[_CODE_STYLE_CONFIG_KEY] if "lang" in lang_code_style: logger.warn( with_color("'lang' is only valid in common code style config, " "but detected in language-specific code style config. It will be ignored.", Fore.RED)) del lang_code_style["lang"] code_style_config_dic = _update_config_dict(code_style_config_dic, lang_code_style) # e.g. [cpp.postprocess] if _POST_PROCESS_CONFIG_KEY in lang_specific_config_dic: postprocess_config_dic = _update_config_dict(postprocess_config_dic, lang_specific_config_dic[_POST_PROCESS_CONFIG_KEY]) if _RUN_CONFIG_KEY in lang_specific_config_dic: # e.g. [cpp.run] run_config_dic = _update_config_dict(run_config_dic, lang_specific_config_dic[_RUN_CONFIG_KEY]) if args: code_style_config_dic = _update_config_dict( code_style_config_dic, dict(template_file=args.template, workspace_dir=args.workspace) ) etc_config_dic = _update_config_dict( etc_config_dic, dict( download_without_login=args.without_login, parallel_download=args.parallel, save_no_session_cache=args.save_no_session_cache, compile_before_testing=args.compile_before_testing, compile_only_when_diff_detected=args.compile_only_when_diff_detected ) ) return Config( code_style_config=CodeStyleConfig(**code_style_config_dic), postprocess_config=PostprocessConfig(**postprocess_config_dic), etc_config=EtcConfig(**etc_config_dic), run_config=RunConfig(**run_config_dic) )