Skip to content

Commit

Permalink
Add test for Github issue 130
Browse files Browse the repository at this point in the history
  • Loading branch information
GjjvdBurg committed Sep 25, 2024
1 parent 80b7fc5 commit 4b4082a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ clean: clean_venv ## Clean build dist and egg directories left after install
rm -f ./man/*
find . -type f -iname '*.pyc' -delete
find . -type d -name '__pycache__' -empty -delete


# Testing
#
gh130: venv
source $(VENV_DIR)/bin/activate && \
python -m unittest -k '*github_issue_130' tests/test_unit/test_reader.py
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
# "pythonfuzz",
"pytest>=2.6",
"termcolor",
"mypy",
]

# What packages are optional?
Expand Down
45 changes: 45 additions & 0 deletions tests/test_unit/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"""

import csv
import json
import unittest

from io import StringIO

from typing import Any
from typing import Iterable
from typing import Iterator
Expand Down Expand Up @@ -172,6 +176,47 @@ def test_no_delim(self) -> None:
quotechar='"',
)

def test_github_issue_130(self) -> None:
# fmt: off
data = """sku,features,attributes
22221,"[{""key"":""heel_height"",""value"":""Ulttra High (4\\""+)""}]","11,room"
"""
# fmt: on

# NOTE we set the escapechar to None to correctly carry over the `\`
# escape character
rows_csv = list(
csv.reader(
StringIO(data), delimiter=",", quotechar='"', escapechar=None
)
)
expected = [
[
"sku",
"features",
"attributes",
],
[
"22221",
'[{"key":"heel_height","value":"Ulttra High (4\\"+)"}]',
"11,room",
],
]
self.assertSequenceEqual(expected, rows_csv)

rows_clevercsv = list(
clevercsv.reader(
StringIO(data), delimiter=",", quotechar='"', escapechar=""
)
)
self.assertSequenceEqual(expected, rows_clevercsv)

# Ensure we can parse the JSON as intended.
cell = json.loads(expected[1][1])
self.assertEqual(
cell, [{"key": "heel_height", "value": 'Ulttra High (4"+)'}]
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 4b4082a

Please sign in to comment.