Skip to content

Commit

Permalink
Merge branch 'release/v0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Mennella committed Apr 30, 2022
2 parents bc723c7 + 5112a0c commit 3cbeb33
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion csv_reconcile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
except:
from importlib import metadata

__version__ = '0.3.1'
__version__ = '0.3.2'
#------------------------------------------------------------------
# Implement reconciliation API
# [[https://reconciliation-api.github.io/specs/latest/]]
Expand Down
9 changes: 7 additions & 2 deletions csv_reconcile/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ def init_db(db,
with db:
# Create a table with ids (as PRIMARY ID), words and bigrams
with open(csvfilenm, newline='', **enckwarg) as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
dialect = None
try:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
except:
pass

csvfile.seek(0)
reader = csv.reader(csvfile, dialect, **csvkwargs)
reader = csv.reader(csvfile, dialect=dialect, **csvkwargs)
header = next(reader)

# Throws if col doesn't exist
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "csv-reconcile"
version = "0.3.1"
version = "0.3.2"
description = "OpenRefine reconciliation service backed by csv resource"
authors = ["Douglas Mennella <[email protected]>"]
license = "MIT"
Expand Down
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def ambiguous_csvcontents():
However, above all, columns matter most
'''.strip()

@pytest.fixture
def sniffer_throwing_csvcontents():
'''Try to throw off csv.Sniffer() to test overrides'''
return '''
a,b,c\n1,2
'''.strip()


@pytest.fixture
def formContentHeader():
Expand Down Expand Up @@ -78,6 +85,17 @@ def getSetup(idnm):

return getSetup

@pytest.fixture
def sniffer_throwing_setup(tmp_path, sniffer_throwing_csvcontents):
'''mock csv file with id and name columns indicated'''

def getSetup(idnm):
p = tmp_path / "snfthrw_csvfile"
p.write_text(sniffer_throwing_csvcontents)
return (p, *idnm)

return getSetup

@pytest.fixture
def cfgContents():
return '''
Expand Down
21 changes: 20 additions & 1 deletion tests/main/test_csv_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def test_version():
assert __version__ == '0.3.1'
assert __version__ == '0.3.2'


def test_manifest(basicClient):
Expand Down Expand Up @@ -305,3 +305,22 @@ def test_csv_sniffer_overrides(app, ambiguous_setup, ambiguous_csvcontents, conf
with chk.app_context():
headernms = [name for _,name in getCSVCols()]
assert headernms == items(SEP)

def test_csv_sniffer_throwing(app, sniffer_throwing_setup, sniffer_throwing_csvcontents, config, mkConfig):

topline = sniffer_throwing_csvcontents.splitlines()[0]
items = lambda sep: [ h.strip() for h in topline.split(sep)]

# First guess is that the , is a separator
SEP = ','
chk = app(sniffer_throwing_setup(items(SEP)[:2]), config)
with chk.app_context():
headernms = [name for _,name in getCSVCols()]
assert headernms == items(SEP)

# Now parse with override
cfg = mkConfig('CSVKWARGS = {"delimiter": ","}')
chk = app(sniffer_throwing_setup(items(SEP)[:2]), cfg)
with chk.app_context():
headernms = [name for _,name in getCSVCols()]
assert headernms == items(SEP)

0 comments on commit 3cbeb33

Please sign in to comment.