Skip to content

Commit

Permalink
update testcase-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
X3nom committed Dec 10, 2024
1 parent 772fb2a commit f41eec3
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/testcase-tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ class tcol:
cprint = lambda message, col=tcol.ENDC: print(col+message+tcol.ENDC)


#============================================================
# GENERAL
#============================================================

def get_out_files(root_dir):
out_files = glob.glob(f"*ans*", root_dir=root_dir) + glob.glob(f"*out*", root_dir=root_dir)
return out_files




#============================================================
# FIX ENCODING
#============================================================
Expand All @@ -46,6 +57,7 @@ def fix_encoding_file(file_path):

# Normalize line endings to LF and prepare UTF-8 content
normalized_content = content.replace("\r\n", "\n").replace("\r", "\n")
if normalized_content[-1] != '\n': normalized_content += '\n' # ensure the file always ends with \n

# Write the file back with UTF-8 encoding
with open(file_path, "w", encoding="utf-8", newline="\n") as file:
Expand Down Expand Up @@ -132,7 +144,8 @@ def gen_check_res(args :argparse.Namespace, gen=True):

else:
verb_print(" searching for ans/out file to compare")
out_files = glob.glob(f"*ans*", root_dir=dir_path) + glob.glob(f"*out*", root_dir=dir_path)

out_files = get_out_files(dir_path)

if len(out_files) != 1:
cprint(f"Error: missing .out/.ans file in {dir_path}", tcol.FAIL)
Expand All @@ -142,9 +155,9 @@ def gen_check_res(args :argparse.Namespace, gen=True):
orig_ans_txt = f.read()

if ans_txt != orig_ans_txt:
cprint(f"WARNING: answer in \"{dir_name}\" does NOT Match answer generated with \"{cmd}\"", tcol.WARNING)
cprint(f"VERIFICATION WARNING: answer in \"{dir_name}\" does NOT Match answer generated with \"{cmd}\"", tcol.WARNING + tcol.BOLD)
else:
verb_print(f" answer in {dir_name} matching")
verb_print(f" answer in {dir_name} matching", tcol.OKGREEN)

test_i += 1

Expand All @@ -164,9 +177,8 @@ def make_import_zip(args :argparse.Namespace):
zipf.mkdir("data/secret")

zipf.writestr("problem.yaml", f"# autogenerated by testcase-tools.py\nname: '{args.name}'")
zipf.writestr("domjudge-problem.ini", f"# autogenerated by testcase-tools.py\ntimelimit='{args.timelimit}'")
if args.problem_pdf is not None:
zipf.write(args.problem_pdf, "problem.pdf")
if args.timelimit is not None: zipf.writestr("domjudge-problem.ini", f"# autogenerated by testcase-tools.py\ntimelimit='{args.timelimit}'")
if args.problem_pdf is not None: zipf.write(args.problem_pdf, "problem.pdf")


test_i = 1
Expand All @@ -182,7 +194,7 @@ def make_import_zip(args :argparse.Namespace):

verb_print(f" searching for matching ans/out file")

out_files = glob.glob(f"*ans*", root_dir=dir_path) + glob.glob(f"*out*", root_dir=dir_path)
out_files = get_out_files(dir_path)

if len(out_files) != 1:
cprint(f"Error: missing .out/.ans file in {dir_path}", tcol.FAIL)
Expand All @@ -206,7 +218,7 @@ def main():
arg_parser.add_argument(
"path",
metavar="PATH",
help="Path to a file or directory"
help="Path to a file or directory containing tests"
)
arg_parser.add_argument(
"-V", "--verbose",
Expand Down Expand Up @@ -239,7 +251,7 @@ def main():
arg_parser.add_argument(
"-z", "--make-zip",
action="store_true",
help="create mass upload zip from directory"
help="create problem upload zip from directory"
)
arg_parser.add_argument(
"-n", "--name",
Expand All @@ -248,12 +260,11 @@ def main():
)
arg_parser.add_argument(
"-tl", "--timelimit",
default=10,
help="specify problem timelimit"
help="specify problem timelimit (optional)"
)
arg_parser.add_argument(
"-pdf", "--problem-pdf",
help="specify problem timelimit"
help="specify problem pdf (optional)"
)

args = arg_parser.parse_args()
Expand Down

0 comments on commit f41eec3

Please sign in to comment.