Skip to content

Commit 7ac08b8

Browse files
authored
Merge pull request #3297 from keflavich/issue3296
Fix issue3296: prevent writing when running tests in CDMS
2 parents 1ebd810 + 213a0cd commit 7ac08b8

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ alma
1919

2020
- Bug fix in ``footprint_to_reg`` that did not allow regions to be plotted. [#3285]
2121

22+
linelists.cdms
23+
^^^^^^^^^^^^^^
24+
25+
- Add a keyword to control writing of new species cache files. This is needed to prevent tests from overwriting those files. [#3300]
26+
2227
heasarc
2328
^^^^^^^
2429

astroquery/linelists/cdms/core.py

Lines changed: 15 additions & 4 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_new_species_cache=False):
298299
"""
299300
A directory of the catalog is found in a file called 'catdir.cat.'
300301
@@ -304,6 +305,15 @@ 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
311+
``write_new_species_cache`` is set.
312+
write_new_species_cache : bool, optional
313+
*Overrides ``use_cached=True``*.
314+
If True, write the species data table files to the CDMS data
315+
directory. Use this option if you need to update the index from
316+
CDMS; this should be set to False for testing.
307317
308318
Returns
309319
-------
@@ -316,7 +326,7 @@ def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
316326
317327
"""
318328

319-
if use_cached:
329+
if use_cached and not write_new_species_cache:
320330
try:
321331
result = ascii.read(data_path(catfile), format='fixed_width', delimiter='|')
322332
result2 = ascii.read(data_path(catfile2), format='fixed_width', delimiter='|')
@@ -332,8 +342,9 @@ def get_species_table(self, *, catfile='partfunc.cat', use_cached=True,
332342
else:
333343
result = retrieve_catfile(catfile_url)
334344
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)
345+
if write_new_species_cache:
346+
result.write(data_path(catfile), format='ascii.fixed_width', delimiter='|', overwrite=True)
347+
result2.write(data_path(catfile2), format='ascii.fixed_width', delimiter='|', overwrite=True)
337348

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

astroquery/linelists/cdms/tests/test_cdms_remote.py

Lines changed: 2 additions & 2 deletions
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_new_species_cache=False)
117117
# as of 2025/01/16
118118
assert len(species_table) >= 1293
119119
assert 'int' in species_table['tag'].dtype.name
@@ -127,7 +127,7 @@ def test_regression_allcats():
127127
"""
128128
Expensive test - try all the molecules
129129
"""
130-
species_table = CDMS.get_species_table()
130+
species_table = CDMS.get_species_table(write_new_species_cache=False)
131131
for row in species_table:
132132
tag = f"{row['tag']:06d}"
133133
result = CDMS.get_molecule(tag)

0 commit comments

Comments
 (0)