@@ -100,15 +100,14 @@ def assertContains(self, needle, haystack):
100
100
def test_output_isolated_correctly (self ):
101
101
log_path = get_absolute_path (
102
102
'test_data/test_output_isolated_correctly.log' )
103
- file = open (log_path )
104
- result = kunit_parser .isolate_kunit_output (file .readlines ())
103
+ with open (log_path ) as file :
104
+ result = kunit_parser .isolate_kunit_output (file .readlines ())
105
105
self .assertContains ('TAP version 14' , result )
106
106
self .assertContains (' # Subtest: example' , result )
107
107
self .assertContains (' 1..2' , result )
108
108
self .assertContains (' ok 1 - example_simple_test' , result )
109
109
self .assertContains (' ok 2 - example_mock_test' , result )
110
110
self .assertContains ('ok 1 - example' , result )
111
- file .close ()
112
111
113
112
def test_output_with_prefix_isolated_correctly (self ):
114
113
log_path = get_absolute_path (
@@ -143,55 +142,51 @@ def test_output_with_prefix_isolated_correctly(self):
143
142
def test_parse_successful_test_log (self ):
144
143
all_passed_log = get_absolute_path (
145
144
'test_data/test_is_test_passed-all_passed.log' )
146
- file = open (all_passed_log )
147
- result = kunit_parser .parse_run_tests (file .readlines ())
145
+ with open (all_passed_log ) as file :
146
+ result = kunit_parser .parse_run_tests (file .readlines ())
148
147
self .assertEqual (
149
148
kunit_parser .TestStatus .SUCCESS ,
150
149
result .status )
151
- file .close ()
152
150
153
151
def test_parse_failed_test_log (self ):
154
152
failed_log = get_absolute_path (
155
153
'test_data/test_is_test_passed-failure.log' )
156
- file = open (failed_log )
157
- result = kunit_parser .parse_run_tests (file .readlines ())
154
+ with open (failed_log ) as file :
155
+ result = kunit_parser .parse_run_tests (file .readlines ())
158
156
self .assertEqual (
159
157
kunit_parser .TestStatus .FAILURE ,
160
158
result .status )
161
- file .close ()
162
159
163
160
def test_no_tests (self ):
164
161
empty_log = get_absolute_path (
165
162
'test_data/test_is_test_passed-no_tests_run.log' )
166
- file = open (empty_log )
167
- result = kunit_parser .parse_run_tests (
168
- kunit_parser .isolate_kunit_output (file .readlines ()))
163
+ with open (empty_log ) as file :
164
+ result = kunit_parser .parse_run_tests (
165
+ kunit_parser .isolate_kunit_output (file .readlines ()))
169
166
self .assertEqual (0 , len (result .suites ))
170
167
self .assertEqual (
171
168
kunit_parser .TestStatus .NO_TESTS ,
172
169
result .status )
173
- file .close ()
174
170
175
171
def test_no_kunit_output (self ):
176
172
crash_log = get_absolute_path (
177
173
'test_data/test_insufficient_memory.log' )
178
- file = open (crash_log )
179
174
print_mock = mock .patch ('builtins.print' ).start ()
180
- result = kunit_parser .parse_run_tests (
181
- kunit_parser .isolate_kunit_output (file .readlines ()))
175
+ with open (crash_log ) as file :
176
+ result = kunit_parser .parse_run_tests (
177
+ kunit_parser .isolate_kunit_output (file .readlines ()))
182
178
print_mock .assert_any_call (StrContains ('no tests run!' ))
183
179
print_mock .stop ()
184
180
file .close ()
185
181
186
182
def test_crashed_test (self ):
187
183
crashed_log = get_absolute_path (
188
184
'test_data/test_is_test_passed-crash.log' )
189
- file = open (crashed_log )
190
- result = kunit_parser .parse_run_tests (file .readlines ())
185
+ with open (crashed_log ) as file :
186
+ result = kunit_parser .parse_run_tests (file .readlines ())
191
187
self .assertEqual (
192
188
kunit_parser .TestStatus .TEST_CRASHED ,
193
189
result .status )
194
- file .close ()
195
190
196
191
def test_ignores_prefix_printk_time (self ):
197
192
prefix_log = get_absolute_path (
0 commit comments