示例#1
0
 def test_load_config_fails_due_to_typo(self):
     try:
         with open(os.path.join(RESOURCE_DIR, "typo_in_postprocess.toml"),
                   'r') as f:
             Config.load(f)
     except TypeError:
         pass
示例#2
0
    def test_load_config(self):
        os.chdir(RESOURCE_DIR)

        with open(os.path.join(RESOURCE_DIR, "all_options.toml"), 'r') as f:
            config = Config.load(f)

        self.assertEqual(3, config.code_style_config.indent_width)
        self.assertEqual(INDENT_TYPE_TAB, config.code_style_config.indent_type)
        self.assertEqual(CPP, config.code_style_config.lang)
        self.assertEqual("g++ main.cpp", config.run_config.compile_command)
        self.assertEqual("./main", config.run_config.run_command)
        self.assertEqual("workspace_dir",
                         config.code_style_config.workspace_dir)

        self.assertEqual(True, config.etc_config.download_without_login)
        self.assertEqual(True, config.etc_config.parallel_download)
        self.assertEqual(True, config.etc_config.save_no_session_cache)
        self.assertEqual("in", config.etc_config.in_example_format)
        self.assertEqual("out", config.etc_config.out_example_format)
        self.assertEqual(True, config.etc_config.compile_before_testing)
        self.assertEqual(False,
                         config.etc_config.compile_only_when_diff_detected)

        contest_dir = os.path.join(RESOURCE_DIR, "mock_contest")
        problem_dir = os.path.join(contest_dir, "mock_problem")
        self.assertEqual(
            "problem\nmock_problem\n",
            config.postprocess_config.execute_on_problem_dir(contest_dir))
        self.assertEqual(
            "contest\nmock_file.txt\n",
            config.postprocess_config.execute_on_contest_dir(problem_dir))
        with open(config.code_style_config.template_file, 'r') as f:
            self.assertEqual("this is custom_template.cpp", f.read())
示例#3
0
    def test_load_code_style_config(self):
        with open(os.path.join(RESOURCE_DIR, "with_indent_width.toml"),
                  'r') as f:
            config = Config.load(f).code_style_config

        self.assertEqual(8, config.indent_width)
        self.assertEqual(INDENT_TYPE_SPACE, config.indent_type)
示例#4
0
 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)])
示例#5
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",
             )))
     self.assertDirectoriesEqual(answer_data_dir_path, self.temp_dir)
示例#6
0
    def test_load_with_program_args(self):
        os.chdir(RESOURCE_DIR)

        with open(os.path.join(RESOURCE_DIR, "all_options.toml"), 'r') as f:
            config = Config.load(
                f,
                ProgramArgs.load(
                    Namespace(lang="python",
                              template=None,
                              workspace=None,
                              without_login=None,
                              parallel=None,
                              save_no_session_cache=None)))

        self.assertEqual(PYTHON, config.code_style_config.lang)
    def test_load_config(self):
        os.chdir(RESOURCE_DIR)

        with open(os.path.join(RESOURCE_DIR, "all_options.toml"), 'r') as f:
            config = Config.load(f)

        self.assertEqual(8, config.code_style_config.indent_width)
        self.assertEqual(INDENT_TYPE_TAB, config.code_style_config.indent_type)

        contest_dir = os.path.join(RESOURCE_DIR, "mock_contest")
        problem_dir = os.path.join(contest_dir, "mock_problem")
        self.assertEqual("problem\nmock_problem\n",
                         config.postprocess_config.execute_on_problem_dir(contest_dir))
        self.assertEqual("contest\nmock_file.txt\n",
                         config.postprocess_config.execute_on_contest_dir(problem_dir))
        with open(config.code_style_config.template_file, 'r') as f:
            self.assertEqual("this is custom_template.cpp", f.read())
示例#8
0
    def test_language_specific_options(self):
        os.chdir(RESOURCE_DIR)

        with open(os.path.join(RESOURCE_DIR, "lang_specific_options.toml"),
                  'r') as f:
            config = Config.load(f)

        self.assertEqual('new_value', config.run_config.compile_command)
        self.assertEqual('kept_value', config.run_config.run_command)

        self.assertEqual('new_value', config.run_config.compile_command)
        self.assertEqual('kept_value', config.run_config.run_command)

        self.assertEqual('new_value',
                         config.postprocess_config.exec_cmd_on_problem_dir)
        self.assertEqual('kept_value',
                         config.postprocess_config.exec_cmd_on_contest_dir)

        self.assertEqual('kept_value', config.etc_config.in_example_format)
示例#9
0
    def test_load_config(self):
        os.chdir(RESOURCE_DIR)

        with open(os.path.join(RESOURCE_DIR, "all_options.toml"), 'r') as f:
            config = Config.load(f)

        self.assertEqual(8, config.code_style_config.indent_width)
        self.assertEqual(INDENT_TYPE_TAB, config.code_style_config.indent_type)

        contest_dir = os.path.join(RESOURCE_DIR, "mock_contest")
        problem_dir = os.path.join(contest_dir, "mock_problem")
        self.assertEqual(
            "problem\nmock_problem\n",
            config.postprocess_config.execute_on_problem_dir(contest_dir))
        self.assertEqual(
            "contest\nmock_file.txt\n",
            config.postprocess_config.execute_on_contest_dir(problem_dir))
        with open(config.code_style_config.template_file, 'r') as f:
            self.assertEqual("this is custom_template.cpp", f.read())
 def test_load_default_config(self):
     with open(get_default_config_path(), 'r') as f:
         Config.load(f)
 def test_load_config_fails_due_to_typo(self):
     try:
         with open(os.path.join(RESOURCE_DIR, "typo_in_postprocess.toml"), 'r') as f:
             Config.load(f)
     except TypeError:
         pass
    def test_load_code_style_config(self):
        with open(os.path.join(RESOURCE_DIR, "with_indent_width.toml"), 'r') as f:
            config = Config.load(f).code_style_config

        self.assertEqual(8, config.indent_width)
        self.assertEqual(INDENT_TYPE_SPACE, config.indent_type)
示例#13
0
 def _load(path: str) -> Config:
     logging.info("Going to load {} as config".format(path))
     with open(path, 'r') as f:
         return Config.load(f, args)
示例#14
0
 def test_load_default_config(self):
     with open(get_default_config_path(), 'r') as f:
         Config.load(f)
示例#15
0
 def _load(path: str) -> Config:
     logging.info("Going to load {} as config".format(path))
     with open(path, 'r') as f:
         return Config.load(f, args)