示例#1
0
def test_table_hashing_error_bad_hashing():
    table = Table("data/table.csv", hashing="bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "hashing-error"
    assert error.note == "unsupported hash type bad"
示例#2
0
def test_table_control_bad_property():
    table = Table("data/table.csv", control={"bad": True})
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "control-error"
    assert error.note.count("bad")
示例#3
0
def test_table_format_error_non_matching_format():
    table = Table("data/table.csv", format="xlsx")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert error.note == 'invalid excel file "data/table.csv"'
示例#4
0
def test_table_scheme_error_file_not_found_remote():
    table = Table("https://example.com/bad.csv")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "scheme-error"
    assert error.note[18:] == "Not Found for url: https://example.com/bad.csv"
示例#5
0
def test_table_scheme_error_file_not_found_bad_compression():
    table = Table("bad.csv", compression="bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "scheme-error"
    assert error.note == "[Errno 2] No such file or directory: 'bad.csv'"
示例#6
0
def test_table_source_error_data():
    table = Table("[1,2]", scheme="text", format="json")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "source-error"
    assert error.note == "all data items must be lists"
示例#7
0
def test_table_scheme_error_bad_scheme_and_format():
    table = Table("bad://bad.bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "scheme-error"
    assert error.note == 'cannot create loader "bad". Try installing "frictionless-bad"'
示例#8
0
def test_table_not_existent_local_file_with_no_format_issue_287():
    table = Table("bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "scheme-error"
    assert error.note == "[Errno 2] No such file or directory: 'bad'"
示例#9
0
def test_table_not_existent_remote_file_with_no_format_issue_287():
    table = Table("http://example.com/bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "scheme-error"
    assert error.note == "404 Client Error: Not Found for url: http://example.com/bad"
示例#10
0
def test_table_compression_error_bad():
    table = Table("data/table.csv", compression="bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "compression-error"
    assert error.note == 'compression "bad" is not supported'
示例#11
0
def test_table_encoding_error_non_matching_encoding():
    table = Table("data/table.csv", encoding="ascii")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "encoding-error"
    assert error.note[:51] == "'ascii' codec can't decode byte 0xe4 in position 20"
示例#12
0
def test_table_dialect_bad_property():
    table = Table("data/table.csv", dialect={"bad": True})
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "dialect-error"
    assert error.note.count("bad")
示例#13
0
def test_table_sql_table_is_required_error(database_url):
    table = Table(database_url)
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "dialect-error"
    assert error.note.count("'table' is a required property")
示例#14
0
def test_table_gsheet_bad_url():
    table = Table("https://docs.google.com/spreadsheets/d/bad")
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "scheme-error"
    assert error.note.count("404 Client Error: Not Found for url")
示例#15
0
def test_table_encoding_error_bad_encoding():
    table = Table("data/table.csv", encoding="bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "encoding-error"
    assert error.note == "unknown encoding: bad"
示例#16
0
def test_table_format_error_bad_format():
    table = Table("data/table.bad")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert error.note == 'cannot create parser "bad". Try installing "frictionless-bad"'
示例#17
0
def test_table_ods_sheet_by_index_not_existent():
    dialect = OdsDialect(sheet=3)
    table = Table("data/table.ods", dialect=dialect)
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert error.note == 'OpenOffice document "data/table.ods" does not have a sheet "3"'
示例#18
0
def test_table_compression_error_invalid_gz():
    source = "id,filename\n\1,dump.tar.gz"
    table = Table(source, scheme="text", format="csv")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "compression-error"
    assert error.note == "Not a gzipped file (b'id')"
示例#19
0
def test_table_compression_error_invalid_zip():
    source = "id,filename\n1,archive.zip"
    table = Table(source, scheme="text", format="csv")
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "compression-error"
    assert error.note == "File is not a zip file"
示例#20
0
def test_table_limit_fields_error_zero_issue_521():
    source = "data/long.csv"
    query = Query(limit_fields=0)
    table = Table(source, query=query)
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "query-error"
    assert error.note.count('minimum of 1" at "limitFields')
示例#21
0
def test_table_xlsx_format_error_sheet_by_index_not_existent():
    source = "data/sheet2.xlsx"
    dialect = dialects.ExcelDialect(sheet=3)
    table = Table(source, dialect=dialect)
    with pytest.raises(exceptions.FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert error.note == 'Excel document "data/sheet2.xlsx" does not have a sheet "3"'
示例#22
0
def test_table_offset_rows_error_zero_issue_521():
    source = "data/long.csv"
    query = Query(offset_rows=0)
    table = Table(source, query=query)
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "query-error"
    assert error.note.count('minimum of 1" at "offsetRows')
示例#23
0
def test_xlsx_parser_format_errors_sheet_by_name_not_existent():
    source = "data/sheet2.xlsx"
    dialect = ExcelDialect(sheet="bad")
    table = Table(source, dialect=dialect)
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert error.note == 'Excel document "data/sheet2.xlsx" does not have a sheet "bad"'
示例#24
0
def test_table_reset_on_close_issue_190():
    query = Query(limit_rows=1)
    source = [["1", "english"], ["2", "中国人"]]
    table = Table(source, headers=False, query=query)
    table.open()
    table.read_data() == [["1", "english"]]
    table.open()
    table.read_data() == [["1", "english"]]
    table.close()
示例#25
0
def test_ods_parser_sheet_by_name_not_existent():
    dialect = OdsDialect(sheet="bad")
    table = Table("data/table.ods", dialect=dialect)
    with pytest.raises(FrictionlessException) as excinfo:
        table.open()
    error = excinfo.value.error
    assert error.code == "format-error"
    assert (
        error.note == 'OpenOffice document "data/table.ods" does not have a sheet "bad"'
    )
示例#26
0
def test_table_compression_local_csv_zip_multiple_open():
    # That's how `tableschema.iter()` acts
    table = Table("data/table.csv.zip")
    table.open()
    assert table.header == ["id", "name"]
    assert table.read_data() == [["1", "english"], ["2", "中国人"]]
    table.close()
    table.open()
    assert table.header == ["id", "name"]
    assert table.read_data() == [["1", "english"], ["2", "中国人"]]
    table.close()