Beispiel #1
0
def test_pydata_uri_creation():
    assert type(data_data_data_uri) == six.text_type
    package, path = "rnginline.test", "data/data-ɐʇɐp-data.txt"
    created_url = pydata.makeurl(package, path)

    assert type(created_url) == six.text_type
    assert data_data_data_uri == created_url
    assert pydata.breakurl(created_url) == (package, path)
Beispiel #2
0
def test_pydata_uri_creation_allows_package_as_bytes():
    # On py2 __name__ is a byte string, so it makes sense to accept bytes for
    # the package
    pydata.makeurl("foo".encode("ascii"), "bar.txt")
Beispiel #3
0
def test_pydata_package_name_must_be_python_name():
    with pytest.raises(ValueError):
        pydata.makeurl("ƒancy-name", "foo/bar")
Beispiel #4
0
def test_pydata_path_must_be_relative():
    with pytest.raises(ValueError):
        pydata.makeurl("foo", "/abs/path")
Beispiel #5
0
def test_pydata_package_name_must_be_python_name():
    with pytest.raises(ValueError):
        pydata.makeurl("ƒancy-name", "foo/bar")


@pytest.mark.skipif(six.PY3, reason="Python 2 specific behaviour")
def test_pydata_uri_creation_allows_package_as_bytes():
    # On py2 __name__ is a byte string, so it makes sense to accept bytes for
    # the package
    pydata.makeurl("foo".encode("ascii"), "bar.txt")


def test_pydata_url_deconstruct_requries_pydata_scheme():
    with pytest.raises(ValueError):
        pydata.breakurl("foo://bar/baz")


def test_pydata_handler_handles_pydata_uris():
    assert pydata.can_handle(parse.urlsplit(data_data_data_uri))


@pytest.mark.parametrize(
    "url",
    [
        pydata.makeurl("rnginline.tset", "data"),  # dir, not file
        pydata.makeurl("rnginline.tset", "data/jfklsjflsdf.txt")
    ])
def test_pydata_handler_raises_dereference_error_on_missing_file(url):
    with pytest.raises(DereferenceError):
        pydata.dereference(url)