コード例 #1
0
def test_resource_to_zip(tmpdir):

    # Write
    target = os.path.join(tmpdir, "dataresource.zip")
    resource = Resource("data/resource.json")
    resource.to_zip(target)

    # Read
    resource = Resource(target)
    assert resource == {"name": "name", "path": "table.csv"}
    assert resource.read_rows() == [
        {"id": 1, "name": "english"},
        {"id": 2, "name": "中国人"},
    ]
コード例 #2
0
def test_resource_to_zip_source_inline(tmpdir):

    # Write
    target = os.path.join(tmpdir, "dataresource.zip")
    data = [["id", "name"], ["1", "english"], ["2", "中国人"]]
    resource = Resource(name="name", data=data)
    resource.to_zip(target)

    # Read
    resource = Resource(target)
    assert resource == {"name": "name", "data": data}
    assert resource.read_rows() == [
        {"id": 1, "name": "english"},
        {"id": 2, "name": "中国人"},
    ]
コード例 #3
0
def test_resource_to_zip_source_remote(tmpdir):

    # Write
    path = BASE_URL % "data/table.csv"
    target = os.path.join(tmpdir, "datapackage.zip")
    resource = Resource(name="name", path=path)
    resource.to_zip(target)

    # Read
    resource = Resource(target)
    assert resource == {"name": "name", "path": path}
    assert resource.read_rows() == [
        {"id": 1, "name": "english"},
        {"id": 2, "name": "中国人"},
    ]
コード例 #4
0
def test_resource_to_zip_withdir_path(tmpdir):

    # Write
    target = os.path.join(tmpdir, "resource.zip")
    resource = Resource(path="data/table.csv")
    resource.to_zip(target)

    # Read
    resource = Resource(target)
    assert resource == {"path": "data/table.csv"}
    assert resource.read_rows() == [
        {
            "id": 1,
            "name": "english"
        },
        {
            "id": 2,
            "name": "中国人"
        },
    ]
コード例 #5
0
def test_resource_to_zip_absolute_path(tmpdir):

    # Write
    target = os.path.join(tmpdir, "resource.zip")
    resource = Resource(path=os.path.abspath("data/table.csv"), trusted=True)
    resource.to_zip(target)

    # Read
    resource = Resource(target)
    assert resource == {"path": "table.csv"}
    assert resource.read_rows() == [
        {
            "id": 1,
            "name": "english"
        },
        {
            "id": 2,
            "name": "中国人"
        },
    ]
コード例 #6
0
def test_resource_to_zip_resolve_remote(tmpdir):

    # Write
    target = os.path.join(tmpdir, "resource.zip")
    resource = Resource(path=BASE_URL % "data/table.csv")
    resource.to_zip(target, resolve=["remote"])

    # Read
    resource = Resource(target)
    assert resource.name == "table"
    assert resource.path == "table.csv"
    assert resource.read_rows() == [
        {
            "id": 1,
            "name": "english"
        },
        {
            "id": 2,
            "name": "中国人"
        },
    ]
コード例 #7
0
def test_resource_to_zip_resolve_inline(tmpdir):

    # Write
    target = os.path.join(tmpdir, "resource.zip")
    resource = Resource(name="table",
                        data=[["id", "name"], [1, "english"], [2, "中国人"]])
    resource.to_zip(target, resolve=["inline"])

    # Read
    resource = Resource(target)
    assert resource.name == "table"
    assert resource.path == "table.csv"
    assert resource.read_rows() == [
        {
            "id": 1,
            "name": "english"
        },
        {
            "id": 2,
            "name": "中国人"
        },
    ]