@@ -22,7 +22,7 @@ def count_lines(self, file_name):
22
22
self .fail ()
23
23
24
24
def test_counting_lines (self ):
25
- self .assertEqual (__ , self .count_lines ("example_file.txt" ))
25
+ self .assertEqual (4 , self .count_lines ("example_file.txt" ))
26
26
27
27
# ------------------------------------------------------------------
28
28
@@ -41,7 +41,7 @@ def find_line(self, file_name):
41
41
self .fail ()
42
42
43
43
def test_finding_lines (self ):
44
- self .assertEqual (__ , self .find_line ("example_file.txt" ))
44
+ self .assertEqual ("test \n " , self .find_line ("example_file.txt" ))
45
45
46
46
## ------------------------------------------------------------------
47
47
## THINK ABOUT IT:
@@ -85,13 +85,18 @@ def count_lines2(self, file_name):
85
85
return len (file .readlines ())
86
86
87
87
def test_counting_lines2 (self ):
88
- self .assertEqual (__ , self .count_lines2 ("example_file.txt" ))
88
+ self .assertEqual (4 , self .count_lines2 ("example_file.txt" ))
89
89
90
90
# ------------------------------------------------------------------
91
91
92
92
def find_line2 (self , file_name ):
93
93
# Using the context manager self.FileContextManager, rewrite this
94
94
# function to return the first line containing the letter 'e'.
95
+ with self .FileContextManager ("example_file.txt" ) as f :
96
+ for line in f :
97
+ match = re .search ("e" , line )
98
+ if match :
99
+ return line
95
100
return None
96
101
97
102
def test_finding_lines2 (self ):
@@ -105,4 +110,4 @@ def count_lines3(self, file_name):
105
110
return len (file .readlines ())
106
111
107
112
def test_open_already_has_its_own_built_in_context_manager (self ):
108
- self .assertEqual (__ , self .count_lines3 ("example_file.txt" ))
113
+ self .assertEqual (4 , self .count_lines3 ("example_file.txt" ))
0 commit comments