Skip to content

Commit 045f2c8

Browse files
authored
Merge pull request #319 from RemArcAble08/tasks_checks
add testing for tasks practice
2 parents 5499855 + de3d413 commit 045f2c8

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

tasks/.cs50.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
check50:
2+
files: &check50_files
3+
- !exclude "*"
4+
- !require tasks.py

tasks/__init__.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
"""correctly accepts two command-line inputs"""
13+
check50.run("python3 tasks.py").exit(code=1)
14+
15+
@check50.check(exists)
16+
def test_print_add():
17+
"""correctly prints added task"""
18+
output = "1. Attend Lecture\n2. Rip a Phonebook\n3. Call David"
19+
check50.run("python3 tasks.py monday.txt").stdin("add Call David", prompt=True).stdout(regex(output), output).kill()
20+
21+
@check50.check(exists)
22+
def test_case_add():
23+
"""disregards the case of add"""
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_add_txt():
29+
"""test"""
30+
check50.run("python3 testing.py get_level")
31+
32+
@check50.check(exists)
33+
def test_print_remove():
34+
"""correctly prints list after removal"""
35+
output = "1. Rip a Phonebook"
36+
check50.run("python3 tasks.py monday.txt").stdin("remove Attend Lecture", prompt=True).stdout(regex(output), output).kill()
37+
38+
@check50.check(exists)
39+
def test_case_remove():
40+
"""disregards the case of remove"""
41+
output = "1. Rip a Phonebook"
42+
check50.run("python3 tasks.py monday.txt").stdin("rEMoVe Attend Lecture", prompt=True).stdout(regex(output), output).kill()
43+
44+
@check50.check(exists)
45+
def test_invalid_remove():
46+
"""correctly exits when no match to remove"""
47+
check50.run("python3 tasks.py monday.txt").stdin("remove Feed the Cat", prompt=True).exit(code=1)
48+
49+
@check50.check(exists)
50+
def test_just_command():
51+
"""correctly exits when no description"""
52+
check50.run("python3 tasks.py monday.txt").stdin("add", prompt=True).exit(code=1)
53+
54+
@check50.check(exists)
55+
def test_invalid_command():
56+
"""correctly exits when invalid command"""
57+
check50.run("python3 tasks.py monday.txt").stdin("edit Rip a Phonebook", prompt=True).exit(code=1)
58+
59+
def regex(text):
60+
"""match case-sensitively with any characters on either side"""
61+
return rf"^.*{escape(text)}.*$"

tasks/monday.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Attend Lecture
2+
Rip a Phonebook

tasks/testing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from tasks import add_task, remove_task, txt_length, update_txt
2+
import sys
3+
4+
def main():
5+
6+
argument = sys.argv[1]
7+
tasks = ['Attend Lecture', 'Rip a Phonebook']
8+
description = sys.argv[3]
9+
filepath = sys.argv[1]
10+
11+
if argument == "add":
12+
tasks.add_task(tasks, description, filepath)
13+
print(tasks.txt_length(filepath))
14+
15+
if __name__ == "__main__":
16+
main()

0 commit comments

Comments
 (0)