Skip to content

Commit

Permalink
Merge pull request #390 from sebhub/fix-380
Browse files Browse the repository at this point in the history
Import data only (no formulas) from XLSX
  • Loading branch information
jacebrowning committed Jul 28, 2019
2 parents 1af55c1 + 02d4878 commit ded20ec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doorstop/core/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _file_xlsx(path, document, mapping=None):

# Parse the file
log.debug("reading rows in {}...".format(path))
workbook = openpyxl.load_workbook(path)
workbook = openpyxl.load_workbook(path, data_only=True)
worksheet = workbook.active

index = 0
Expand Down
Binary file added doorstop/core/tests/files/formula.xlsx
Binary file not shown.
33 changes: 33 additions & 0 deletions doorstop/core/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,39 @@ def test_file_xlsx(self, mock_itemize):
self.assertEqual(expected_data, data)
self.assertIs(mock_document, document)

@patch('doorstop.core.importer._itemize')
def test_file_xlsx_formula(self, mock_itemize):
"""Verify a XLSX file with formula can be imported."""
path = os.path.join(FILES, 'formula.xlsx')
mock_document = Mock()
# Act
with catch_warnings():
importer._file_xlsx(path, mock_document)
# Assert
args, kwargs = mock_itemize.call_args
logging.debug("args: {}".format(args))
logging.debug("kwargs: {}".format(kwargs))
header, data, document = args
expected_header = [
'uid',
'level',
'text',
'ref',
'links',
'active',
'derived',
'header',
'normative',
'reviewed',
]
self.assertEqual(expected_header, header)
expected_data = [
['REQ001', '1.2.3', 'active', None, None, 1, 0, None, 1, None],
['REQ002', '1.2.4', 'inactive', None, None, 0, 0, None, 1, None],
]
self.assertEqual(expected_data, data)
self.assertIs(mock_document, document)

@patch('doorstop.core.importer.add_item')
def test_itemize(self, mock_add_item):
"""Verify item data can be converted to items."""
Expand Down

0 comments on commit ded20ec

Please sign in to comment.