Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that tests do not interact with the users remote data manager and cache #3554

Open
Cadair opened this issue Nov 29, 2019 · 2 comments
Labels
data Affects the data submodule Effort High Requires a large time investment Infrastructure Issues or PRs that affect the CI or packaging of SunPy Package Expert Requires alot of knowledge of the internal structure of SunPy Priority Low Slow action required Tests Affects tests in some measure

Comments

@Cadair
Copy link
Member

Cadair commented Nov 29, 2019

Following on from #3124 and #3550 we should really come up with a nice way to ensure that when tests are run locally we are not interacting with the users local cache.

@Cadair Cadair added data Affects the data submodule Infrastructure Issues or PRs that affect the CI or packaging of SunPy labels Nov 29, 2019
@vn-ki vn-ki added Effort Medium Requires a moderate time investment Package Novice Requires little knowledge of the internal structure of SunPy labels Jan 12, 2020
@sashank27
Copy link
Contributor

I believe this issue still persists. Any insights on how to proceed?

@vn-ki
Copy link
Member

vn-ki commented Jan 15, 2020

@sashank27 If you look at the changes made in #3550 you can see that there was already some code to do just this. But this was removed because it would have test related code in the actual codebase itself. This is not ideal.

So the essense of this issue is to figure out a good way to make the data manager tests not actually touch the local cache in some way. You could use the code removed in #3550 as a starting point as well as this fixture.

sunpy/sunpy/conftest.py

Lines 62 to 90 in 2eb3494

@pytest.fixture()
def sunpy_cache(mocker, tmp_path):
"""
Provide a way to add local files to the cache. This can be useful when mocking
remote requests.
"""
from types import MethodType
from sunpy.data.data_manager.cache import Cache
from sunpy.data.data_manager.storage import InMemStorage
from sunpy.data.data_manager.downloader import ParfiveDownloader
cache = Cache(
ParfiveDownloader(),
InMemStorage(),
tmp_path,
None
)
def add(self, url, path):
self._storage.store({
'url': url,
'file_path': path,
'file_hash': 'none', # hash doesn't matter
})
cache.add = MethodType(add, cache)
def func(mocked):
mocker.patch(mocked, cache)
return cache
yield func

But I have to warn you this might be time consuming to pursue as it is more thinking and less coding.

In hindsight this might be a effort high issue.

@vn-ki vn-ki added Effort High Requires a large time investment and removed Effort Medium Requires a moderate time investment labels Jan 15, 2020
@nabobalis nabobalis added the Priority Low Slow action required label Jan 15, 2020
@nabobalis nabobalis added the Tests Affects tests in some measure label Jul 11, 2020
@nabobalis nabobalis added Package Expert Requires alot of knowledge of the internal structure of SunPy and removed Package Novice Requires little knowledge of the internal structure of SunPy labels Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data Affects the data submodule Effort High Requires a large time investment Infrastructure Issues or PRs that affect the CI or packaging of SunPy Package Expert Requires alot of knowledge of the internal structure of SunPy Priority Low Slow action required Tests Affects tests in some measure
Projects
None yet
Development

No branches or pull requests

4 participants