Skip to content

Commit

Permalink
use absolute paths in example to match docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 17, 2024
1 parent cf1118f commit eee6281
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions docs/source/usage/graders/examples/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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%")

0 comments on commit eee6281

Please sign in to comment.