From eee62814b8848e1b4509d1ac08682eddef4a68f8 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 17 Oct 2024 19:11:32 -0400 Subject: [PATCH] use absolute paths in example to match docs --- docs/source/usage/graders/examples/file_io.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/source/usage/graders/examples/file_io.py b/docs/source/usage/graders/examples/file_io.py index 003525cf..55b95f31 100644 --- a/docs/source/usage/graders/examples/file_io.py +++ b/docs/source/usage/graders/examples/file_io.py @@ -8,20 +8,24 @@ student_submission = Path(sys.argv[2]) # input file is in the same directory as our grader (this file) -INPUT_FILE = Path(__file__).parent / "input.txt" +# make sure to use the absolute path +INPUT_FILE = (Path(__file__).parent / "input.txt").resolve() + # output file is in the same directory as the student submission # This way we can avoid multiple submissions trying to write to # the same file. -OUTPUT_FILE = student_submission.parent / "output.txt" +# Again, making sure to use the absolute path +OUTPUT_FILE = (student_submission.parent / "output.txt").resolve() command = [ sys.executable, submission, # give read permissions to the input + # making sure to use the absolute path to the file "--read", INPUT_FILE, - # and allow them to read/write to output + # and allow them to read/write to the output file "--write", OUTPUT_FILE, # and then pass the arguments to the student submission @@ -37,7 +41,11 @@ check=False, ) -if resp.returncode == 0: - print(f"Score: {100 if OUTPUT_FILE.read_text() == INPUT_FILE.read_text() else 0}%") -else: +if ( + resp.returncode != 0 + or not OUTPUT_FILE.exists() + or OUTPUT_FILE.read_text() != INPUT_FILE.read_text() +): print("Score: 0%") +else: + print("Score: 100%")