def test_run_single_test_interactive(self): run_command("cp -r test_run_single_test_interactive /tmp", RESOURCE_DIR) test_dir = "/tmp/test_run_single_test_interactive" self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "1", "-j", "interactive", '-c', "True" ])) self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "2", "-j", "interactive", '-c', "True" ]))
def test_run_single_test_interactive(self): test_dir = os.path.join(self.temp_dir, "test") shutil.copytree( os.path.join(RESOURCE_DIR, "test_run_single_test_interactive"), test_dir) self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "1", "-j", "interactive", '-c', "True" ])) self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "2", "-j", "interactive", '-c', "True" ]))
def test_run_single_test_decimal_multiplication(self): test_dir = os.path.join(RESOURCE_DIR, "test_run_single_test_decimal_multiplication") self.assertTrue( tester.main('', [ '-d', test_dir, "-n", "1", "-v", "0.01", "-j", "absolute_or_relative" ])) self.assertTrue( tester.main('', [ '-d', test_dir, "-n", "2", "--error-value", "0.01", "-j", "absolute_or_relative" ])) self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "1", "-v", "0.01", "-j", "absolute"])) self.assertFalse( tester.main( '', ['-d', test_dir, "-n", "2", "-v", "0.01", "-j", "absolute"])) self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "1", "-v", "0.01", "-j", "relative"])) self.assertTrue( tester.main( '', ['-d', test_dir, "-n", "2", "-v", "0.01", "-j", "relative"]))
def test_compiler_and_tester(self): run_command("cp -r test_compiler_and_tester /tmp", RESOURCE_DIR) test_dir = "/tmp/test_compiler_and_tester" os.chdir(test_dir) for lang in ALL_LANGUAGES: metadata = setter_main('', ["--lang", lang.name]) compile_main_and_judge_programs(metadata, force_compile=True) for i in [1, 2, 3, 4]: self.assertTrue( tester.main('', [ '-d', test_dir, "-n", "{:d}".format(i), "-j", "normal" ]))
def test_run_single_test_multisolution(self): test_dir = os.path.join(self.temp_dir, "test") shutil.copytree( os.path.join(RESOURCE_DIR, "test_run_single_test_multisolution"), test_dir) setter_main('', ['-d', test_dir, "-j", "multisolution"]) metadata = Metadata.load_from(os.path.join(test_dir, "metadata.json")) self.assertTrue(isinstance(metadata.judge_method, MultiSolutionJudge)) # Already set setter_main('', ['-d', test_dir, "--lang", "cpp"]) metadata = Metadata.load_from(os.path.join(test_dir, "metadata.json")) self.assertTrue(metadata.lang.name == 'cpp') self.assertTrue( tester.main('', ['-d', test_dir, '-n', '1', '-c', "True"])) self.assertTrue( tester.main('', ['-d', test_dir, "-n", "2", "-c", "True"])) self.assertTrue( tester.main('', ['-d', test_dir, "-n", "3", "-c", "True"])) self.assertTrue( tester.main('', ['-d', test_dir, "-n", "4", "-c", "True"]))
def test_run_single_test_decimal_mixed(self): test_dir = os.path.join(RESOURCE_DIR, "test_run_single_test_decimal_mixed") self.assertFalse( tester.main('', [ '-d', test_dir, "-n", "1", "-v", "0.01", "-j", "absolute_or_relative" ])) self.assertTrue( tester.main('', [ '-d', test_dir, "-n", "2", "-v", "0.01", "-j", "absolute_or_relative" ])) self.assertFalse( tester.main('', [ '-d', test_dir, "-n", "1", "-v", "0.0001", "-j", "absolute_or_relative" ])) self.assertFalse( tester.main('', [ '-d', test_dir, "-n", "2", "-v", "0.0001", "-j", "absolute_or_relative" ]))
def test_run_single_test_multisolution(self): run_command("cp -r test_run_single_test_multisolution /tmp", RESOURCE_DIR) test_dir = "/tmp/test_run_single_test_multisolution" metadata = setter_main('', ['-d', test_dir, "-j", "multisolution"]) set_result = metadata.judge_method.judge_type == JudgeType.MultiSolution self.assertTrue(set_result) # Already set metadata = setter_main('', ['-d', test_dir, "--lang", "cpp"]) self.assertTrue(metadata.lang.name == 'cpp') self.assertTrue( tester.main('', ['-d', test_dir, '-n', '1', '-c', "True"])) self.assertTrue( tester.main('', ['-d', test_dir, "-n", "2", "-c", "True"])) self.assertTrue( tester.main('', ['-d', test_dir, "-n", "3", "-c", "True"])) self.assertTrue( tester.main('', ['-d', test_dir, "-n", "4", "-c", "True"]))
def test_compiler_and_tester(self): test_dir = os.path.join(self.temp_dir, "test") shutil.copytree(os.path.join(RESOURCE_DIR, "test_compiler_and_tester"), test_dir) for lang in ALL_LANGUAGES: setter_main('', ["--lang", lang.name, '-d', test_dir]) metadata = Metadata.load_from( os.path.join(test_dir, "metadata.json")) compile_main_and_judge_programs(metadata, force_compile=True, cwd=test_dir) for i in [1, 2, 3, 4]: self.assertTrue( tester.main('', [ '-d', test_dir, "-n", "{:d}".format(i), "-j", "normal" ]))
def main(prog, args, credential_supplier=None, use_local_session_cache=True) -> bool: parser = argparse.ArgumentParser( prog=prog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( "--exec", '-e', help= "File path to the execution target. [Default] Automatically detected exec file", default=None) parser.add_argument( "--dir", '-d', help="Target directory to test. [Default] Current directory", default=".") parser.add_argument("--timeout", '-t', help="Timeout for each test cases (sec) [Default] 1", type=int, default=1) parser.add_argument( "--code", '-c', help= "Path to the source code to submit [Default] Code path written in metadata.json", type=str, default=None) parser.add_argument( "--force", "-f", action="store_true", help= "Submit the code regardless of the local test result [Default] False", default=False) parser.add_argument("--save-no-session-cache", action="store_true", help="Save no session cache to avoid security risk", default=False) parser.add_argument( "--unlock-safety", "-u", action="store_true", help= "By default, this script only submits the first code per problem. However, you can remove" " the safety by this option in order to submit codes twice or more.", default=False) args = parser.parse_args(args) metadata_file = os.path.join(args.dir, "metadata.json") try: metadata = Metadata.load_from(metadata_file) except IOError: logger.error( "{0} is not found! You need {0} to use this submission functionality." .format(metadata_file)) return False try: client = AtCoderClient() client.login( save_session_cache=args.save_no_session_cache, credential_supplier=credential_supplier, use_local_session_cache=use_local_session_cache, ) except LoginError: logger.error("Login failed. Try again.") return False tester_args = [] if args.exec: tester_args += ["-e", args.exec] if args.dir: tester_args += ["-d", args.dir] if args.timeout: tester_args += ["-t", str(args.timeout)] if args.force or tester.main("", tester_args): submissions = client.download_submission_list(metadata.problem.contest) if not args.unlock_safety: for submission in submissions: if submission.problem_id == metadata.problem.problem_id: logger.error( with_color( "Cancel submitting because you already sent some code to the problem. Please " "specify -u to send the code. {}".format( metadata.problem.contest.get_submissions_url( submission)), Fore.LIGHTRED_EX)) return False code_path = args.code or os.path.join(args.dir, metadata.code_filename) with open(code_path, 'r') as f: source = f.read() logger.info("Submitting {} as {}".format(code_path, metadata.lang.name)) submission = client.submit_source_code(metadata.problem.contest, metadata.problem, metadata.lang, source) logger.info("{} {}".format( with_color("Done!", Fore.LIGHTGREEN_EX), metadata.problem.contest.get_submissions_url(submission)))
def test_run_single_test(self): test_dir = os.path.join(RESOURCE_DIR, "test_run_single_test") self.assertTrue(tester.main('', ['-d', test_dir, "-n", "1"])) self.assertFalse(tester.main('', ['-d', test_dir, "-n", "2"]))
def test_multiple_exec_files(self): all_ok = tester.main( '', ['-d', os.path.join(RESOURCE_DIR, "test_multiple_exec_files")]) self.assertTrue(all_ok)
def test_run_single_test(self): test_dir = os.path.join(RESOURCE_DIR, "test_run_single_test") self.assertTrue(tester.main('', ['-d', test_dir, "-n", "1"])) self.assertFalse(tester.main('', ['-d', test_dir, "-n", "2"]))
def test_multiple_exec_files(self): all_ok = tester.main( '', ['-d', os.path.join(RESOURCE_DIR, "test_multiple_exec_files")]) self.assertTrue(all_ok)
def main(prog, args, credential_supplier=None, use_local_session_cache=True) -> bool: parser = argparse.ArgumentParser( prog=prog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument("--exec", '-e', help="File path to the execution target. [Default] Automatically detected exec file", default=None) parser.add_argument("--dir", '-d', help="Target directory to test. [Default] Current directory", default=".") parser.add_argument("--timeout", '-t', help="Timeout for each test cases (sec) [Default] 1", type=int, default=1) parser.add_argument("--code", '-c', help="Path to the source code to submit [Default] Code path written in metadata.json", type=str, default=None) parser.add_argument("--force", "-f", action="store_true", help="Submit the code regardless of the local test result [Default] False", default=False) parser.add_argument("--save-no-session-cache", action="store_true", help="Save no session cache to avoid security risk", default=False) parser.add_argument("--unlock-safety", "-u", action="store_true", help="By default, this script only submits the first code per problem. However, you can remove" " the safety by this option in order to submit codes twice or more.", default=False) args = parser.parse_args(args) metadata_file = os.path.join(args.dir, "metadata.json") try: metadata = Metadata.load_from(metadata_file) except IOError: logging.error( "{0} is not found! You need {0} to use this submission functionality.".format(metadata_file)) return False try: client = AtCoderClient() client.login(save_session_cache=args.save_no_session_cache, credential_supplier=credential_supplier, use_local_session_cache=use_local_session_cache, ) except LoginError: logging.error("Login failed. Try again.") return False tester_args = [] if args.exec: tester_args += ["-e", args.exec] if args.dir: tester_args += ["-d", args.dir] if args.timeout: tester_args += ["-t", str(args.timeout)] if args.force or tester.main("", tester_args): submissions = client.download_submission_list(metadata.problem.contest) if not args.unlock_safety: for submission in submissions: if submission.problem_id == metadata.problem.problem_id: logging.error(with_color("Cancel submitting because you already sent some code to the problem. Please " "specify -u to send the code. {}".format( metadata.problem.contest.get_submissions_url(submission)), Fore.LIGHTRED_EX)) return False code_path = args.code or os.path.join(args.dir, metadata.code_filename) with open(code_path, 'r') as f: source = f.read() logging.info( "Submitting {} as {}".format(code_path, metadata.lang.name)) submission = client.submit_source_code( metadata.problem.contest, metadata.problem, metadata.lang, source) logging.info("{} {}".format( with_color("Done!", Fore.LIGHTGREEN_EX), metadata.problem.contest.get_submissions_url(submission)))