How to use the datapackage.registry.Registry function in datapackage

To help you get started, we’ve selected a few datapackage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
def test_get_memoize_the_profiles():
    registry_path = BASE_AND_TABULAR_REGISTRY_PATH
    registry = datapackage.registry.Registry(registry_path)
    registry.get('data-package')
    m = mock.mock_open(read_data='{}')
    with mock.patch('datapackage.registry.open', m):
        registry.get('data-package')
    assert not m.called, '.get() should memoize the profiles'
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
def test_get_raises_if_profile_isnt_a_json():
    registry_path = fixture_path('registry_with_notajson_profile.json')
    registry = datapackage.registry.Registry(registry_path)
    with pytest.raises(RegistryError):
        registry.get('notajson-data-package')
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
def test_available_profiles_cant_be_set():
    registry = datapackage.registry.Registry()
    with pytest.raises(AttributeError):
        registry.available_profiles = {}
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
def test_base_path_is_none_if_registry_is_remote():
    url = 'http://some-place.com/registry.json'
    httpretty.register_uri(httpretty.GET, url, body='[]')
    registry = datapackage.registry.Registry(url)
    assert registry.base_path is None
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
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)
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
def test_available_profiles_returns_list_of_profiles_dicts():
    registry_path = BASE_AND_TABULAR_REGISTRY_PATH
    registry = datapackage.registry.Registry(registry_path)
    assert len(registry.available_profiles) == 2
    assert registry.available_profiles.get('data-package') == {
        'id': 'data-package',
        'title': 'Data Package',
        'schema': 'https://specs.frictionlessdata.io/schemas/data-package.json',
        'schema_path': 'data-package.json',
        'specification': 'https://specs.frictionlessdata.io/data-package/',
    }
    assert registry.available_profiles.get('tabular-data-package') == {
        'id': 'tabular-data-package',
        'title': 'Tabular Data Package',
        'schema': 'https://specs.frictionlessdata.io/schemas/tabular-data-package.json',
        'schema_path': 'tabular-data-package.json',
        'specification': 'http://specs.frictionlessdata.io/tabular-data-package/',
    }
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
{
        "id": "data-package",
        "title": "Data Package",
        "schema": "http://example.com/one.json",
        "schema_path": "data-package.json",
        "specification": "https://specs.frictionlessdata.io/data-package/"
      }
    ]
    """
    profile_url = 'http://example.com/one.json'
    profile_body = '{ "profile": "data-package" }'
    httpretty.register_uri(httpretty.GET, profile_url, body=profile_body)
    with tempfile.NamedTemporaryFile(suffix='.csv') as tmpfile:
        tmpfile.write(registry_body.encode('utf-8'))
        tmpfile.flush()
        registry = datapackage.registry.Registry(tmpfile.name)
    base_profile = registry.get('data-package')
    assert base_profile is not None
    assert base_profile == {'profile': 'data-package'}
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
def test_get_returns_none_if_profile_doesnt_exist():
    registry = datapackage.registry.Registry()
    assert registry.get('non-existent-profile') is None
github frictionlessdata / datapackage-py / tests / test_registry.py View on Github external
registry_body = """
    [
      {
        "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')
github frictionlessdata / datapackage-py / datapackage / profile.py View on Github external
def _load_registry(self):
        return datapackage.registry.Registry()