Skip to content

Commit

Permalink
Sniffer now handles ; delimited files, closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Oct 16, 2020
1 parent 09409e3 commit 0cf7d3c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion csv_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def load_csv(fp, key=None, dialect=None):
peek = fp.read(1024 ** 2)
fp.seek(0)
try:
dialect = csv.Sniffer().sniff(peek, delimiters=",\t")
dialect = csv.Sniffer().sniff(peek, delimiters=",\t;")
except csv.Error:
# Oh well, we tried. Fallback to the default.
pass
Expand Down
33 changes: 33 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,36 @@ def test_column_containing_dot(tmpdir):
"columns_added": [],
"columns_removed": [],
} == json.loads(result.output.strip())


def test_semicolon_delimited(tmpdir):
# https://github.com/simonw/csv-diff/issues/6
one = tmpdir / "one.csv"
two = tmpdir / "two.csv"
one.write(
dedent(
"""
id;name
1;Mark
"""
).strip()
)
two.write(
dedent(
"""
id;name
1;Brian
"""
).strip()
)
result = CliRunner().invoke(
cli.cli, [str(one), str(two), "--key", "id", "--json"], catch_exceptions=False
)
assert 0 == result.exit_code
assert {
"added": [],
"removed": [],
"changed": [{"key": "1", "changes": {"name": ["Mark", "Brian"]}}],
"columns_added": [],
"columns_removed": [],
} == json.loads(result.output.strip())

0 comments on commit 0cf7d3c

Please sign in to comment.