Skip to content

Commit cdc13c0

Browse files
committed
fix issue3296: prevent writing when running tests
1 parent 1ebd810 commit cdc13c0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

astroquery/linelists/cdms/core.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ def _parse_result(self, response, *, verbose=False):
294294

295295
def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
296296
catfile_url=conf.catfile_url,
297-
catfile2='catdir.cat', catfile_url2=conf.catfile_url2):
297+
catfile2='catdir.cat', catfile_url2=conf.catfile_url2,
298+
write=True):
298299
"""
299300
A directory of the catalog is found in a file called 'catdir.cat.'
300301
@@ -304,6 +305,13 @@ def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
304305
----------
305306
catfile : str, name of file, default 'catdir.cat'
306307
The catalog file, installed locally along with the package
308+
use_cached : bool, optional
309+
If True, use the cached file if it exists. If False, download the
310+
file from the CDMS server and save it to the cache (if ``write`` is set).
311+
write : bool, optional
312+
If True, and if ``use_cached`` is set, write the file to the cache. Use this
313+
option if you need to update the index from CDMS; this should be set to False
314+
for testing.
307315
308316
Returns
309317
-------
@@ -332,8 +340,9 @@ def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
332340
else:
333341
result = retrieve_catfile(catfile_url)
334342
result2 = retrieve_catfile2(catfile_url2)
335-
result.write(data_path(catfile), format='ascii.fixed_width', delimiter='|', overwrite=True)
336-
result2.write(data_path(catfile2), format='ascii.fixed_width', delimiter='|', overwrite=True)
343+
if write:
344+
result.write(data_path(catfile), format='ascii.fixed_width', delimiter='|', overwrite=True)
345+
result2.write(data_path(catfile2), format='ascii.fixed_width', delimiter='|', overwrite=True)
337346

338347
merged = table.join(result, result2, keys=['tag'])
339348
if not all(merged['#lines'] == merged['# lines']):

astroquery/linelists/cdms/tests/test_cdms_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_complex_molecule_remote():
113113

114114
@pytest.mark.remote_data
115115
def test_retrieve_species_table():
116-
species_table = CDMS.get_species_table(use_cached=False)
116+
species_table = CDMS.get_species_table(use_cached=False, write=False)
117117
# as of 2025/01/16
118118
assert len(species_table) >= 1293
119119
assert 'int' in species_table['tag'].dtype.name

0 commit comments

Comments
 (0)