Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
The way this setup works is that for functionality that usually requires
internet access, but has mocks in place, it is possible to write the test
without adding a `@remote_data` decorator, and `py.test` will do the right
thing when running the tests:
1. Access the internet and use the normal code if `--remote-data` is used
2. Not access the internet and use the mock code if `--remote-data` is not used
Both of these cases are tested on travis-ci.
"""
from .target import FixedTarget
from astropy.coordinates import EarthLocation
if not hasattr(FixedTarget, '_real_from_name'):
FixedTarget._real_from_name = FixedTarget.from_name
FixedTarget.from_name = FixedTarget._from_name_mock
if not hasattr(EarthLocation, '_real_of_site'):
EarthLocation._real_of_site = EarthLocation.of_site
EarthLocation.of_site = EarthLocation_mock.of_site_mock
The way this setup works is that for functionality that usually requires
internet access, but has mocks in place, it is possible to write the test
without adding a `@remote_data` decorator, and `py.test` will do the right
thing when running the tests:
1. Access the internet and use the normal code if `--remote-data` is used
2. Not access the internet and use the mock code if `--remote-data` is not used
Both of these cases are tested on travis-ci.
"""
from .target import FixedTarget
from astropy.coordinates import EarthLocation
if not hasattr(FixedTarget, '_real_from_name'):
FixedTarget._real_from_name = FixedTarget.from_name
FixedTarget.from_name = FixedTarget._from_name_mock
if not hasattr(EarthLocation, '_real_of_site'):
EarthLocation._real_of_site = EarthLocation.of_site
EarthLocation.of_site = EarthLocation_mock.of_site_mock
def _unmock_remote_data():
"""
undo _mock_remote_data
currently unused
"""
from .target import FixedTarget
if hasattr(FixedTarget, '_real_from_name'):
FixedTarget.from_name = FixedTarget._real_from_name
del FixedTarget._real_from_name
if hasattr(EarthLocation, '_real_of_site'):
EarthLocation.of_site = EarthLocation._real_of_site
del EarthLocation._real_of_site
# otherwise assume it's already correct