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"
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")
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"'
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"
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'"
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"
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"'
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'"
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"
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'
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"
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")
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")
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")
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"
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"'
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"'
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')"
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"
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')
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"'
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')
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"'
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()
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"' )
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()