def download_problem_content(self, problem: Problem) -> ProblemContent: resp = self._request(problem.get_url()) try: return ProblemContent.from_html(resp.text) except (InputFormatDetectionError, SampleDetectionError) as e: raise e
def download_problem_content(self, problem: Problem) -> ProblemContent: resp = self._request(problem.get_url()) try: return ProblemContent.from_html(resp.text) except (InputFormatDetectionError, SampleDetectionError) as e: raise e
def get_problem_content(problem: Problem): def func(): print("downloading html ...", file=sys.stderr) raw_response = atcoder._request(problem.get_url()) return raw_response.text return ProblemContent.from_html(get_and_set_cache("problem/{}".format(problem.problem_id), func))
def get_problem_content(problem: Problem): def func(): print("downloading html ...", file=sys.stderr) raw_response = atcoder._request(problem.get_url()) return raw_response.text return ProblemContent.from_html( get_and_set_cache("problem/{}".format(problem.problem_id), func))
def load_problem_content(self, case_name: str) -> ProblemContent: case_dir = self._get_test_case_dir(case_name) format_file = os.path.join(case_dir, FORMAT_FILE_NAME) example_files = [ os.path.join(case_dir, file) for file in os.listdir(case_dir) if file != FORMAT_FILE_NAME ] with open(format_file, 'r', encoding="utf-8") as f: input_format = f.read() examples = [] for ex_file in example_files: with open(ex_file, 'r', encoding="utf-8") as f: examples.append(Sample(f.read(), None)) return ProblemContent(input_format, examples)
def test_default_code_generators_and_templates(self): def _full_path(filename): return os.path.join(RESOURCE_DIR, "test_default_code_generators_and_templates", filename) input_file = _full_path("echo_test_input.txt") expected_output_file = _full_path("echo_test_output.txt") pred_result = predict_format( ProblemContent(load_text_file( _full_path("echo_test_format.txt")), [ Sample(load_text_file(_full_path("echo_test_input.txt")), None) ])) for lang in ALL_LANGUAGES: expected_default_generated_code_file = _full_path( os.path.join( lang.name, lang.source_code_name("expected_default_generated_code"))) # 1. Compile test with default templates self._compile_and_run(lang, pred_result.format, lang.default_template_path, expected_default_generated_code_file, input_file) # 2. Echo test, which tests custom templates having echo output of input exec_result = self._compile_and_run( lang, pred_result.format, _full_path( os.path.join(lang.name, lang.source_code_name("echo_template"))), _full_path( os.path.join( lang.name, lang.source_code_name( "expected_echo_generated_code"))), input_file) self.assertEqual(load_text_file(expected_output_file), exec_result.output)
def predict_yes_no(html: str) -> Tuple[Optional[str], Optional[str]]: try: outputs = set() for sample in ProblemContent.from_html(html).get_samples(): for x in sample.get_output().split("\n"): outputs.add(x.strip()) except (InputFormatDetectionError, SampleDetectionError) as e: raise YesNoPredictionFailedError(e) yes_kws = ["yes", "possible", "ok"] no_kws = ["no", "impossible", "ng"] yes_str = None no_str = None for val in outputs: if val.lower() in yes_kws: yes_str = val if val.lower() in no_kws: no_str = val return yes_str, no_str
def predict_yes_no(html: str) -> Tuple[Optional[str], Optional[str]]: try: outputs = set() for sample in ProblemContent.from_html(html).get_samples(): for x in sample.get_output().split("\n"): outputs.add(x.strip()) except (InputFormatDetectionError, SampleDetectionError) as e: raise YesNoPredictionFailedError(e) yes_kws = ["yes", "possible"] no_kws = ["no", "impossible"] yes_str = None no_str = None for val in outputs: if val.lower() in yes_kws: yes_str = val if val.lower() in no_kws: no_str = val return yes_str, no_str