Skip to content

Commit 36771a9

Browse files
max_iterations default arg for testing
1 parent 6ae4062 commit 36771a9

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

mfr/extensions/tabular/libs/xlrd_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from mfr.extensions.tabular.exceptions import TableTooBigError
99

1010

11-
def xlsx_xlrd(fp):
11+
def xlsx_xlrd(fp, max_iterations=5000):
1212
"""Read and convert a xlsx file to JSON format using the xlrd library.
1313
:param fp: File pointer object
1414
:return: tuple of table headers and data
@@ -53,7 +53,7 @@ def xlsx_xlrd(fp):
5353
iteration = 0
5454
while increased_name in fields:
5555
iteration += 1
56-
if iteration > 5000:
56+
if iteration > max_iterations:
5757
increased_name = name + ' ({})'.format(uuid.uuid4())
5858
else:
5959
counts[name] += 1

tests/extensions/tabular/test_xlsx_tools.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ def test_xlsx_xlrd_duplicate_fields(self):
4040
assert sheet[1][0] == {'Name': 1.0, 'Dup (1)': 2.0, 'Dup (2)': 3.0,
4141
'Dup (3)': 4.0, 'Dup (4)': 5.0, 'Not Dup': 6.0}
4242

43-
# After demo it was suggested the iteration cap be raised. The value ended up to be about 5,000
44-
# Unsure best way to test this case with such a high cap. Going to leave the test for now
45-
# def test_xlsx_xlrd_duplicate_fields_handle_naming(self):
46-
# with open(os.path.join(BASE, 'files', 'test_duplicate_uuid.xlsx')) as fp:
47-
# sheets = xlrd_tools.xlsx_xlrd(fp)
48-
# print(sheets)
49-
# sheet = sheets.popitem()[1]
50-
51-
# assert sheet[0][1]['field'] != 'dup (12)'
52-
# assert len(sheet[0][1]['field']) > 24
43+
def test_xlsx_xlrd_duplicate_fields_handle_naming(self):
44+
with open(os.path.join(BASE, 'files', 'test_duplicate_uuid.xlsx')) as fp:
45+
sheets = xlrd_tools.xlsx_xlrd(fp, max_iterations=10)
46+
47+
sheet = sheets.popitem()[1]
48+
49+
# this if you raise max iterations, it will be named dup (13) instead of dup (<uuid>)
50+
assert sheet[0][1]['field'] != 'dup (13)'
51+
# using `len` is an easy way to see the uuid has been appended
52+
assert len(sheet[0][1]['field']) > 24

0 commit comments

Comments
 (0)