Fix calling `from_xls` passing custom options. #355

This commit is contained in:
Fabio Caccamo 2023-12-27 11:06:42 +01:00
parent daf80ddeee
commit 704ee5936e
3 changed files with 62 additions and 4 deletions

View File

@ -52,10 +52,15 @@ class XLSSerializer(AbstractSerializer):
return list(range(columns_count))
def _decode_legacy(self, s, **kwargs):
filepath = s
options = {}
options["filename"] = s
options["logfile"] = kwargs.pop("logfile", None)
options["verbosity"] = kwargs.pop("verbosity", 0) or 0
options["use_mmap"] = kwargs.pop("use_mmap", False) or False
options["file_contents"] = kwargs.pop("file_contents", None)
# load the worksheet
workbook = open_workbook(filename=filepath)
workbook = open_workbook(**options)
# get sheet by index or by name
sheet_index, sheet_name = self._get_sheet_index_and_name_from_options(**kwargs)
@ -100,10 +105,15 @@ class XLSSerializer(AbstractSerializer):
return items
def _decode(self, s, **kwargs):
filepath = s
options = {}
options["filename"] = s
options["read_only"] = True
options["data_only"] = kwargs.pop("data_only", False)
options["keep_links"] = kwargs.pop("keep_links", True)
options["keep_vba"] = kwargs.pop("keep_vba", True)
# load the worksheet
workbook = load_workbook(filename=filepath, read_only=True)
workbook = load_workbook(**options)
# get sheet by index or by name
sheet_index, sheet_name = self._get_sheet_index_and_name_from_options(**kwargs)

View File

@ -0,0 +1,48 @@
import pathlib
import unittest
from benedict import benedict
class github_issue_0355_test_case(unittest.TestCase):
"""
This class describes a github issue 0355 test case.
https://github.com/fabiocaccamo/python-benedict/issues/355
To run this specific test:
- Run python -m unittest tests.github.test_issue_0355
"""
def test_from_xls_with_options(self):
# print(pathlib.Path("./test_issue_0144.json"))
filepath = pathlib.Path("tests/github/test_issue_0355.xlsx")
d = benedict.from_xls(filepath)
# print(d.dump())
self.assertEqual(
d,
{
"values": [
{
"formula": '="A2 value is: "&A2',
"integer": 123,
"text": "abc",
}
]
},
)
d = benedict.from_xls(filepath, data_only=True)
# print(d.dump())
self.assertEqual(
d,
{
"values": [
{
"formula": "A2 value is: abc",
"integer": 123,
"text": "abc",
}
]
},
)

Binary file not shown.