Skip to content

Commit a750c43

Browse files
authored
Merge pull request #2522 from bsipocz/TST_closing_files
TST: Closing files in tests
2 parents 1ff3b7f + 92e9070 commit a750c43

File tree

27 files changed

+82
-45
lines changed

27 files changed

+82
-45
lines changed

astroquery/alfalfa/tests/test_alfalfa.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def get_readable_fileobj_mockreturn(filename, **kwargs):
4949

5050
def get_mockreturn(url, params=None, timeout=10):
5151
filename = data_path(DATA_FILES['catalog'])
52-
content = open(filename, 'rb').read()
52+
with open(filename, 'rb') as infile:
53+
content = infile.read()
5354
return MockResponseAlfalfa(content)
5455

5556

astroquery/besancon/tests/test_besancon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def get_readable_fileobj_mockreturn(filename, **kwargs):
8080

8181
def post_mockreturn(method, url, data, timeout=10, stream=True, **kwargs):
8282
filename = data_path('query_return.iframe.html')
83-
content = open(filename, 'rb').read()
83+
with open(filename, 'rb') as infile:
84+
content = infile.read()
8485
return MockResponseBesancon(content, filename, **kwargs)
8586

8687

astroquery/casda/tests/test_casda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def get_mockreturn(self, method, url, data=None, timeout=10,
8383
key = params['POS'].split()[0] if params['POS'] else None
8484
filename = data_path(DATA_FILES[key])
8585
log.debug('providing ' + filename)
86-
content = open(filename, 'rb').read()
86+
with open(filename, 'rb') as infile:
87+
content = infile.read()
8788
return MockResponse(content)
8889

8990

astroquery/cds/tests/test_mocserver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def patch_get(request):
4141
def get_mockreturn(self, method, url, data=None, timeout=10,
4242
files=None, params=None, headers=None, **kwargs):
4343
filename = data_path(DATA_FILES[data])
44-
content = open(filename, 'rb').read()
44+
with open(filename, 'rb') as infile:
45+
content = infile.read()
4546
return MockResponse(content)
4647

4748

astroquery/heasarc/tests/parametrization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def get_mockreturn(session, method, url, params=None, timeout=10, **kwargs):
5252

5353
filename = filename_for_request(url, params)
5454
try:
55-
content = open(filename, "rt").read()
55+
with open(filename, 'rt') as infile:
56+
content = infile.read()
5657
except FileNotFoundError:
5758
log.error(
5859
f'no stored mock data in {filename} for url="{url}" and params="{params}", '

astroquery/image_cutouts/first/tests/test_first.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def patch_post(request):
3535

3636
def post_mockreturn(method, url, data, timeout, **kwargs):
3737
filename = data_path(DATA_FILES['image'])
38-
content = open(filename, 'rb').read()
38+
with open(filename, 'rb') as infile:
39+
content = infile.read()
3940
return MockResponse(content, **kwargs)
4041

4142

astroquery/ipac/irsa/ibe/tests/test_ibe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def get_mockreturn(self, method, url,
5656
json=None):
5757
filename = data_path(DATA_FILES[(url,
5858
params and frozenset(params.items()))])
59-
content = open(filename, 'rb').read()
59+
with open(filename, 'rb') as infile:
60+
content = infile.read()
6061
return MockResponse(
6162
content, url=url, headers=headers, stream=stream, auth=auth)
6263

astroquery/ipac/irsa/sha/tests/test_sha.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def get_mockreturn(url, params=None, stream=False, timeout=10, **kwargs):
3535
else:
3636
raise ValueError("Query not pre-loaded.")
3737

38-
content = open(filename, 'rb').read()
38+
with open(filename, 'rb') as infile:
39+
content = infile.read()
3940
return MockResponse(content, **kwargs)
4041

4142

astroquery/ipac/irsa/tests/test_irsa.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def patch_get(request):
3838

3939
def get_mockreturn(method, url, params=None, timeout=10, cache=False, **kwargs):
4040
filename = data_path(DATA_FILES[params['spatial']])
41-
content = open(filename, 'rb').read()
41+
with open(filename, 'rb') as infile:
42+
content = infile.read()
4243
return MockResponse(content, **kwargs)
4344

4445

astroquery/ipac/ned/tests/test_ned.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def get_mockreturn(method, url, params=None, timeout=10, **kwargs):
6969
filename = data_path(DATA_FILES['extract_urls'])
7070
else:
7171
filename = data_path(DATA_FILES['object'])
72-
content = open(filename, "rb").read()
72+
with open(filename, 'rb') as infile:
73+
content = infile.read()
7374
return MockResponse(content, **kwargs)
7475

7576

@@ -261,7 +262,8 @@ def test_get_object_notes(patch_get):
261262

262263

263264
def test_parse_result(capsys):
264-
content = open(data_path(DATA_FILES['error']), 'rb').read()
265+
with open(data_path(DATA_FILES['error']), 'rb') as infile:
266+
content = infile.read()
265267
response = MockResponse(content)
266268
with pytest.raises(RemoteServiceError) as exinfo:
267269
ned.core.Ned._parse_result(response)

0 commit comments

Comments
 (0)