|
| 1 | +import check50 |
| 2 | +from re import escape |
| 3 | + |
| 4 | +@check50.check() |
| 5 | +def exists(): |
| 6 | + """tasks.py exists""" |
| 7 | + check50.exists("tasks.py") |
| 8 | + check50.include("testing.py", "monday.txt") |
| 9 | + |
| 10 | +@check50.check(exists) |
| 11 | +def test_correct_input(): |
| 12 | + """tasks.py correctly accepts two command-line inputs""" |
| 13 | + check50.run("python3 tasks.py").exit(code=1) |
| 14 | + |
| 15 | +@check50.check(exists) |
| 16 | +def test_simple_add(): |
| 17 | + """tasks.py correctly handles simple add case""" |
| 18 | + output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Eat" |
| 19 | + check50.run("python3 tasks.py monday.txt").stdin("add Eat", prompt=True).stdout(regex(output), output).kill() |
| 20 | + |
| 21 | +@check50.check(exists) |
| 22 | +def test_print_add(): |
| 23 | + """tasks.py correctly prints added task""" |
| 24 | + output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David" |
| 25 | + check50.run("python3 tasks.py monday.txt").stdin("add Call David", prompt=True).stdout(regex(output), output).kill() |
| 26 | + |
| 27 | +@check50.check(exists) |
| 28 | +def test_case_add(): |
| 29 | + """tasks.py correctly handles case-sensitive add""" |
| 30 | + output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David" |
| 31 | + check50.run("python3 tasks.py monday.txt").stdin("aDd Call David", prompt=True).stdout(regex(output), output).kill() |
| 32 | + |
| 33 | +@check50.check(exists) |
| 34 | +def test_print_remove(): |
| 35 | + """tasks.py correctly prints list after removal""" |
| 36 | + output = "1. Rip a Phonebook" |
| 37 | + check50.run("python3 tasks.py monday.txt").stdin("remove Attend Lecture", prompt=True).stdout(regex(output), output).kill() |
| 38 | + |
| 39 | +@check50.check(exists) |
| 40 | +def test_case_remove(): |
| 41 | + """tasks.py correctly handles case-sensitive remove""" |
| 42 | + output = "1. Rip a Phonebook" |
| 43 | + check50.run("python3 tasks.py monday.txt").stdin("rEMoVe Attend Lecture", prompt=True).stdout(regex(output), output).kill() |
| 44 | + |
| 45 | +@check50.check(exists) |
| 46 | +def test_invalid_remove(): |
| 47 | + """tasks.py correctly exits when no match to remove""" |
| 48 | + check50.run("python3 tasks.py monday.txt").stdin("remove Feed the Cat", prompt=True).exit(code=1) |
| 49 | + |
| 50 | +@check50.check(exists) |
| 51 | +def test_just_command(): |
| 52 | + """tasks.py correctly exits when no task is given""" |
| 53 | + check50.run("python3 tasks.py monday.txt").stdin("add", prompt=True).exit(code=1) |
| 54 | + |
| 55 | +@check50.check(exists) |
| 56 | +def test_invalid_command(): |
| 57 | + """tasks.py correctly exits when invalid operation""" |
| 58 | + check50.run("python3 tasks.py monday.txt").stdin("edit Rip a Phonebook", prompt=True).exit(code=1) |
| 59 | + |
| 60 | +def regex(text): |
| 61 | + """match case-sensitively with any characters on either side""" |
| 62 | + return rf"^.*{escape(text)}.*$" |
0 commit comments