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\n 2. Rip a Phonebook\n 3. 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\n 2. Rip a Phonebook\n 3. 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 )} .*$"
0 commit comments