Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import data only (no formulas) from XLSX #390

Merged
merged 1 commit into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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