Skip to content

Commit af2d6f4

Browse files
committed
add a test for filtering out rows with errors
1 parent 930f213 commit af2d6f4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

astroquery/heasarc/tests/test_heasarc.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,28 @@ def test_download_data__table_row():
365365
assert os.path.exists(f'{downloaddir}/data/file.txt')
366366

367367

368+
def test_download_data__exclude_rows_with_errors():
369+
with tempfile.TemporaryDirectory() as tmpdir:
370+
datadir = f'{tmpdir}/data'
371+
downloaddir = f'{tmpdir}/download'
372+
os.makedirs(datadir, exist_ok=True)
373+
with open(f'{datadir}/file.txt', 'w') as fp:
374+
fp.write('data')
375+
# include both a file and a directory
376+
tab = Table({
377+
'sciserver': [f'{tmpdir}/data/file.txt', f'{tmpdir}/data'],
378+
'error_message': ['', 'Error']
379+
})
380+
# The patch is to avoid the test that we are on sciserver
381+
with patch('os.path.exists') as exists:
382+
exists.return_value = True
383+
Heasarc.download_data(tab, host="sciserver", location=downloaddir)
384+
assert os.path.exists(f'{downloaddir}/file.txt')
385+
# data/ should be excluded because it has an error
386+
assert not os.path.exists(f'{downloaddir}/data')
387+
assert not os.path.exists(f'{downloaddir}/data/file.txt')
388+
389+
368390
# S3 mock tests
369391
s3_bucket = "nasa-heasarc"
370392
s3_key1 = "some/location/file1.txt"

0 commit comments

Comments
 (0)