Skip to content

Commit eb8459f

Browse files
Fix html extra, add fsutil_installed=False tests for io_util and xls serializer
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/841a9dfb-c101-4f41-b8d3-552ef909284b Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
1 parent 558530c commit eb8459f

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ Twitter = "https://twitter.com/fabiocaccamo"
118118
all = [
119119
"python-benedict[io,parse,s3]",
120120
]
121+
html = [
122+
"beautifulsoup4 >= 4.12.0, < 5.0.0",
123+
"python-benedict[xml]",
124+
]
121125
io = [
122126
"python-fsutil >= 0.16.1, < 1.0.0",
123127
"requests >= 2.33.0, < 3.0.0",

tests/dicts/io/test_io_dict_xls.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ def test_from_xls_with_valid_file_valid_content_but_xls_extra_not_installed(
9191
with self.assertRaises(ExtrasRequireModuleNotFoundError):
9292
_ = IODict(filepath)
9393

94+
@patch("benedict.serializers.xls.fsutil_installed", False)
95+
def test_from_xls_with_valid_file_valid_content_but_io_extra_not_installed(
96+
self,
97+
) -> None:
98+
for extension in self._extensions:
99+
with self.subTest(
100+
msg=f"test_from_xls_({extension})_with_valid_file_valid_content_but_io_extra_not_installed"
101+
):
102+
filepath = self.input_path(f"valid-content.{extension}")
103+
# static method
104+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
105+
_ = IODict.from_xls(filepath)
106+
# constructor explicit format
107+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
108+
_ = IODict(filepath, format=extension)
109+
# constructor implicit format
110+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
111+
_ = IODict(filepath)
112+
94113
def test_from_xls_with_valid_url_valid_content(self) -> None:
95114
expected_dict = {
96115
"values": [

tests/dicts/io/test_io_util.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ def test_parse_s3_url_with_special_characters(self) -> None:
136136
}
137137
self.assertEqual(result, expected_result)
138138

139+
@patch("benedict.dicts.io.io_util.fsutil_installed", False)
140+
def test_read_content_from_file_with_io_extra_not_installed(self) -> None:
141+
filepath = "/tmp/test-file.json"
142+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
143+
io_util.read_content_from_file(filepath, format="json")
144+
145+
@patch("benedict.dicts.io.io_util.fsutil_installed", False)
146+
def test_read_content_from_url_with_io_extra_not_installed(self) -> None:
147+
url = "https://example.com/data.json"
148+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
149+
io_util.read_content_from_url(url, {}, format="json")
150+
151+
@patch("benedict.dicts.io.io_util.fsutil_installed", False)
152+
def test_read_content_from_s3_with_io_extra_not_installed(self) -> None:
153+
s3_options = {
154+
"aws_access_key_id": "",
155+
"aws_secret_access_key": "",
156+
}
157+
s3_url = "s3://my-bucket/my-key.txt"
158+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
159+
io_util.read_content_from_s3(s3_url, s3_options)
160+
161+
@patch("benedict.dicts.io.io_util.fsutil_installed", False)
162+
def test_write_content_to_file_with_io_extra_not_installed(self) -> None:
163+
filepath = "/tmp/test-file.json"
164+
with self.assertRaises(ExtrasRequireModuleNotFoundError):
165+
io_util.write_content_to_file(filepath, '{"a": 1}')
166+
139167
@patch("benedict.dicts.io.io_util.s3_installed", False)
140168
def test_read_content_from_s3_with_s3_extra_not_installed(self) -> None:
141169
s3_options = {

0 commit comments

Comments
 (0)