コード例 #1
0
ファイル: test_resource.py プロジェクト: kant/frictionless-py
def test_resource_to_table_source_non_tabular():
    resource = Resource(path="data/text.txt")
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        resource.to_table().open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert error.note == 'cannot create parser "txt". Try installing "frictionless-txt"'
コード例 #2
0
def test_resource_to_table_source_remote():
    resource = Resource(path=BASE_URL % "data/table.csv")
    with resource.to_table() as table:
        assert table.header == ["id", "name"]
        assert table.read_rows() == [
            {"id": 1, "name": "english"},
            {"id": 2, "name": "中国人"},
        ]
コード例 #3
0
def test_resource_to_table_source_data():
    data = [["id", "name"], ["1", "english"], ["2", "中国人"]]
    resource = Resource(data=data)
    with resource.to_table() as table:
        assert table.header == ["id", "name"]
        assert table.read_rows() == [
            {"id": 1, "name": "english"},
            {"id": 2, "name": "中国人"},
        ]
コード例 #4
0
ファイル: test_resource.py プロジェクト: kant/frictionless-py
def test_resource_to_table_respect_query_issue_503():
    resource = Resource(path="data/table.csv", query=Query(limit_rows=1))
    with resource.to_table() as table:
        assert table.header == ["id", "name"]
        assert table.read_rows() == [{"id": 1, "name": "english"}]