astropy / astropy/astroquery

BUG: cache path should work for windows

Open
#2,799 0 comments 1 reaction 1 assignee Claimed by @ceb8 View on GitHub
alma bug cache windows
Dominant language
Python
Stars
791
Forks
451
Avg merge
1d 3h
Merged PRs (30d)
4

Description

I see these in the online windows tests. The traceback somehow points to unittest's mock(), but we don't have the same issue with any of the other modules, so a fix should be possible within astroquery.

cc @ceb8

https://github.com/astropy/astroquery/actions/runs/5767241327/job/15636621368#step:5:2920
```

During handling of the above exception, another exception occurred:

self =
tmp_path = WindowsPath('C:/Users/runneradmin/AppData/Local/Temp/pytest-of-unknown/pytest-0/test_download_and_extract1')
alma =

def test_download_and_extract(self, tmp_path, alma):
# TODO: slowish, runs for ~90s

alma.cache_location = tmp_path
alma._cycle0_tarfile_content_table = {'ID': ''}

uid = 'uid://A001/X12a3/Xe9'
data_info = alma.get_data_info(uid, expand_tarfiles=False)
aux_tar_file = [x for x in data_info['access_url'] if 'auxiliary' in x]
assert 1 == len(aux_tar_file)
download_mock = MagicMock()
# following line is required to make alma picklable
download_mock.__reduce__ = lambda self: (MagicMock, ())
alma._download_file = download_mock

# there are no FITS files in the auxiliary file
assert not alma.download_and_extract_files(aux_tar_file)

# download python scripts now
downloaded = alma.download_and_extract_files(aux_tar_file,
regex=r'.*\.py')
assert len(downloaded) > 1
assert download_mock.call_count == len(downloaded)

# ASDM files cannot be expanded.
asdm_url = [x for x in data_info['access_url'] if 'asdm' in x][0]
tarfile_handle_mock = Mock()
mock_content_file1 = Mock(path='/tmp/')
# mocking attribute name is trickier and it requires the name to
# be set separately.
mock_content_file1.name = 'foo.py'
mock_content_file2 = Mock(path='/tmp/')
mock_content_file2.name = 'blah.txt'
tarfile_handle_mock.getmembers.return_value = \
[mock_content_file1, mock_content_file2]
tarfile_pkg_mock = Mock()
tarfile_pkg_mock.open.return_value = tarfile_handle_mock
with patch('astroquery.alma.core.tarfile', tarfile_pkg_mock):
with patch('astroquery.alma.core.os.remove') as delete_mock:
downloaded_asdm = alma.download_and_extract_files(
[asdm_url], include_asdm=True, regex=r'.*\.py')
> delete_mock.assert_called_once_with(
'cache_path/' + asdm_url.split('/')[-1])
E AssertionError: expected call not found.
E Expected: remove('cache_path/2017.1.01185.S_uid___A002_Xd28a9e_X71b8.asdm.sdm.tar')
E Actual: remove('cache_path\\2017.1.01185.S_uid___A002_Xd28a9e_X71b8.asdm.sdm.tar')
E
E pytest introspection follows:
E
E Args:
E assert ('cache_path\...sdm.sdm.tar',) == ('cache_path/...sdm.sdm.tar',)
E At index 0 diff: 'cache_path\\2017.1.01185.S_uid___A002_Xd28a9e_X71b8.asdm.sdm.tar' != 'cache_path/2017.1.01185.S_uid___A002_Xd28a9e_X71b8.asdm.sdm.tar'
E Full diff:
E - ('cache_path/2017.1.01185.S_uid___A002_Xd28a9e_X71b8.asdm.sdm.tar',)
E ? ^
E + ('cache_path\\2017.1.01185.S_uid___A002_Xd28a9e_X71b8.asdm.sdm.tar',)
E ? ^^

..\..\.tox\py39-test-alldeps-online\lib\site-packages\astroquery\alma\tests\test_alma_remote.py:267: AssertionError
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.