Skip to content

Commit

Permalink
fix(tests): new code for tests;
Browse files Browse the repository at this point in the history
- Align test with new strip code.
- Write headers to stream for `load_csv`.
  • Loading branch information
JVickery-TBS committed May 8, 2024
1 parent 341ec1e commit 21a1ece
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ckanext/xloader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def load_csv(csv_filepath, resource_id, mimetype='text/csv', logger=None):
try:
with UnknownEncodingStream(csv_filepath, file_format, decoding_result,
skip_rows=skip_rows) as stream:
stream.save(**save_args) # have to save headers
for row in stream:
for _index, _cell in enumerate(row):
if isinstance(_cell, str):
Expand All @@ -184,6 +185,7 @@ def load_csv(csv_filepath, resource_id, mimetype='text/csv', logger=None):
except (EncodingError, UnicodeDecodeError):
with Stream(csv_filepath, format=file_format, encoding=SINGLE_BYTE_ENCODING,
skip_rows=skip_rows) as stream:
stream.save(**save_args) # have to save headers
for row in stream:
for _index, _cell in enumerate(row):
if isinstance(_cell, str):
Expand Down
10 changes: 5 additions & 5 deletions ckanext/xloader/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def test_boston_311(self, Session):
u"",
u"ONTIME",
u"Open",
u" ",
u"", # " " transforms to ""
u"Street Light Outages",
u"Public Works Department",
u"Street Lights",
Expand Down Expand Up @@ -1081,14 +1081,14 @@ def test_boston_311(self, Session):
u"",
u"ONTIME",
u"Open",
u" ",
u"", # " " transforms to ""
u"Graffiti Removal",
u"Property Management",
u"Graffiti",
u"Graffiti Removal",
u"PROP_GRAF_GraffitiRemoval",
u"PROP",
u" https://mayors24.cityofboston.gov/media/boston/report/photos/595f0000048560f46d94b9fa/report.jpg",
u"https://mayors24.cityofboston.gov/media/boston/report/photos/595f0000048560f46d94b9fa/report.jpg", # strip white spaces
u"",
u"522 Saratoga St East Boston MA 02128",
Decimal("1"),
Expand All @@ -1113,14 +1113,14 @@ def test_boston_311(self, Session):
u"",
u"ONTIME",
u"Open",
u" ",
u"", # " " transforms to ""
u"Graffiti Removal",
u"Property Management",
u"Graffiti",
u"Graffiti Removal",
u"PROP_GRAF_GraffitiRemoval",
u"PROP",
u" https://mayors24.cityofboston.gov/media/boston/report/photos/595efedb048560f46d94b9ef/report.jpg",
u"https://mayors24.cityofboston.gov/media/boston/report/photos/595efedb048560f46d94b9ef/report.jpg", # strip white spaces
u"",
u"965 Bennington St East Boston MA 02128",
Decimal("1"),
Expand Down

0 comments on commit 21a1ece

Please sign in to comment.