Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Fixed csv dialect bug with sniffing (#215)
Browse files Browse the repository at this point in the history
* Fixed csv dialect bug

* Fixed linting
  • Loading branch information
roll committed Oct 30, 2017
1 parent 0fa4e66 commit 7af33c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tabulator/parsers/csv.py
Expand Up @@ -119,7 +119,8 @@ def __prepare_dialect(self, stream):
if not dialect.escapechar:
dialect.doublequote = True
except csv.Error:
dialect = csv.excel
class dialect(csv.excel):
pass
for key, value in self.__options.items():
setattr(dialect, key, value)

Expand Down
10 changes: 10 additions & 0 deletions tests/formats/test_csv.py
Expand Up @@ -5,6 +5,7 @@
from __future__ import unicode_literals

import io
import pytest
from mock import Mock
from tabulator import Stream
from tabulator.parsers.csv import CSVParser
Expand Down Expand Up @@ -137,6 +138,15 @@ def test_stream_csv_detect_delimiter_pipe():
assert stream.read() == [['a1', 'b1'], ['a2', 'b2']]


def test_stream_csv_dialect_should_not_persist_if_sniffing_fails_issue_goodtables_228():
source1 = 'a;b;c\n#comment'
source2 = 'a,b,c\n#comment'
with Stream(source1, scheme='text', format='csv', headers=1, delimiter=';') as stream:
assert stream.headers == ['a', 'b', 'c']
with Stream(source2, scheme='text', format='csv', headers=1) as stream:
assert stream.headers == ['a', 'b', 'c']


# Parser

def test_parser_csv():
Expand Down

0 comments on commit 7af33c5

Please sign in to comment.