def test_table_csv_escaping(): dialect = dialects.CsvDialect(escape_char="\\") with Table("data/escaping.csv", dialect=dialect) as table: assert table.header == ["ID", "Test"] assert table.read_data() == [ ["1", "Test line 1"], ["2", 'Test " line 2'], ["3", 'Test " line 3'], ]
def test_table_csv_dialect_should_not_persist_if_sniffing_fails_issue_goodtables_228( ): source1 = "a;b;c\n#comment" source2 = "a,b,c\n#comment" dialect = dialects.CsvDialect(delimiter=";") with Table(source1, scheme="text", format="csv", dialect=dialect) as table: assert table.header == ["a", "b", "c"] with Table(source2, scheme="text", format="csv") as table: assert table.header == ["a", "b", "c"]
def test_table_csv_write_delimiter(tmpdir): source = "data/table.csv" target = str(tmpdir.join("table.csv")) dialect = dialects.CsvDialect(delimiter=";") with Table(source) as table: table.write(target, dialect=dialect) with Table(target, dialect=dialect) as table: assert table.header == ["id", "name"] assert table.read_data() == [["1", "english"], ["2", "中国人"]] assert table.dialect == {"delimiter": ";"}
def test_describe_whitespace_cells_with_skip_initial_space_issue_7(): source = "header1,header2\n1, \n2, \n3, \n" dialect = dialects.CsvDialect(skip_initial_space=True) resource = describe(source, scheme="text", format="csv", dialect=dialect) assert resource.schema == { "fields": [ { "name": "header1", "type": "integer" }, { "name": "header2", "type": "any" }, ] }
def test_table_csv_quotechar_is_empty_string(): source = 'header1,header2",header3\nvalue1,value2",value3' dialect = dialects.CsvDialect(quote_char="") with Table(source, scheme="text", format="csv", dialect=dialect) as table: table.header == ["header1", 'header2"', "header3"] table.read_data() == [["value1", 'value2"', "value3"]]
def test_table_csv_quotechar(): source = "%header1,header2%\n%value1,value2%\n%value3,value4%" dialect = dialects.CsvDialect(quote_char="%") with Table(source, scheme="text", format="csv", dialect=dialect) as table: assert table.header == ["header1,header2"] assert table.read_data() == [["value1,value2"], ["value3,value4"]]
def test_table_csv_escapechar(): source = "header1%,header2\nvalue1%,value2\nvalue3%,value4" dialect = dialects.CsvDialect(escape_char="%") with Table(source, scheme="text", format="csv", dialect=dialect) as table: assert table.header == ["header1,header2"] assert table.read_data() == [["value1,value2"], ["value3,value4"]]