Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_schema_raises_registryerror_if_registry_raised(self,
registry_mock):
registry_mock.side_effect = datapackage.exceptions.RegistryError
with pytest.raises(datapackage.exceptions.RegistryError):
datapackage.DataPackage()
def test_init_raises_if_registry_isnt_a_csv():
url = 'http://some-place.com/registry.txt'
httpretty.register_uri(httpretty.GET, url, body="foo")
with pytest.raises(RegistryError):
datapackage.registry.Registry(url)
def test_schema_raises_registryerror_if_registry_raised(registry_mock):
registry_mock.side_effect = exceptions.RegistryError
with pytest.raises(exceptions.RegistryError):
Package()
def test_schema_raises_registryerror_if_registry_raised(self,
registry_mock):
registry_mock.side_effect = datapackage.exceptions.RegistryError
with pytest.raises(datapackage.exceptions.RegistryError):
datapackage.DataPackage()
"id": "data-package",
"title": "Data Package",
"schema": "http://example.com/one.json",
"schema_path": "inexistent.json",
"specification": "http://example.com"
}
]
"""
with tempfile.NamedTemporaryFile(suffix='.csv') as tmpfile:
tmpfile.write(registry_body.encode('utf-8'))
tmpfile.flush()
registry = datapackage.registry.Registry(tmpfile.name)
profile_url = 'http://example.com/one.json'
httpretty.register_uri(httpretty.GET, profile_url, status=404)
with pytest.raises(RegistryError):
registry.get('data-package')
def test_schema_raises_registryerror_if_registry_raised(registry_mock):
registry_mock.side_effect = exceptions.RegistryError
with pytest.raises(exceptions.RegistryError):
Package()
def __init__(self, registry_path_or_url=DEFAULT_REGISTRY_PATH):
if os.path.isfile(registry_path_or_url):
self._BASE_PATH = os.path.dirname(
os.path.abspath(registry_path_or_url)
)
try:
self._profiles = {}
self._registry = self._get_registry(registry_path_or_url)
except (IOError, ValueError) as e:
six.raise_from(RegistryError(e), e)
be downloaded from the web. The results are cached, so any subsequent
calls won't hit the filesystem or the web.
Args:
profile_id (str): The ID of the profile you want.
Raises:
RegistryError: If there was some problem opening the profile file
or its format was incorrect.
'''
if profile_id not in self._profiles:
try:
self._profiles[profile_id] = self._get_profile(profile_id)
except (ValueError,
IOError) as e:
six.raise_from(RegistryError(e), e)
return self._profiles[profile_id]