Skip to content

Commit 234bb6a

Browse files
Update response_test.py (#311)
refactor with With statement to open file to make code more Pythonic
1 parent e382d1f commit 234bb6a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tests/src/OneLogin/saml2_tests/response_test.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ class OneLogin_Saml2_Response_Test(unittest.TestCase):
2424
def loadSettingsJSON(self, name='settings1.json'):
2525
filename = join(self.settings_path, name)
2626
if exists(filename):
27-
stream = open(filename, 'r')
28-
settings = json.load(stream)
29-
stream.close()
30-
return settings
27+
with open(filename, 'r') as stream:
28+
settings = json.load(stream)
29+
return settings
3130

3231
def file_contents(self, filename):
33-
f = open(filename, 'r')
34-
content = f.read()
35-
f.close()
36-
return content
32+
with open(filename, 'r') as f:
33+
content = f.read()
34+
return content
3735

3836
def get_request_data(self):
3937
return {

0 commit comments

Comments
 (0)