Skip to content

Commit 07408d6

Browse files
committed
Return '' for unsupported export type
Fixed the bug where unsupported export types throw 400 assertion error instead of 400 exporter error. Remove the misleading comment which wrongly claims that `get_exporter_name()` is always called with a supported exporter. Update tests accordingly.
1 parent 5838fd6 commit 07408d6

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

mfr/core/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ def get_renderer_name(name: str) -> str:
112112
ep_iterator = pkg_resources.iter_entry_points(group='mfr.renderers', name=name.lower())
113113
ep_list = list(ep_iterator)
114114

115-
# Empty list indicates unsupported file type.
116-
# Return a blank string and let `make_renderer()` handle it.
115+
# Empty list indicates unsupported file type. Return '' and let `make_renderer()` handle it.
117116
if len(ep_list) == 0:
118117
return ''
119118

120-
# If file type is supported, there must be only one element in the list.
119+
# If the file type is supported, there must be only one element in the list.
121120
assert len(ep_list) == 1
122121
return ep_list[0].attrs[0]
123122

@@ -135,7 +134,11 @@ def get_exporter_name(name: str) -> str:
135134
ep_iterator = pkg_resources.iter_entry_points(group='mfr.exporters', name=name.lower())
136135
ep_list = list(ep_iterator)
137136

138-
# `make_renderer()` is called before `make_exporter()` to ensure the file type is supported
137+
# Empty list indicates unsupported export type. Return '' and let `make_exporter()` handle it.
138+
if len(ep_list) == 0:
139+
return ''
140+
141+
# If the export type is supported, there must be only one element in the list.
139142
assert len(ep_list) == 1
140143
return ep_list[0].attrs[0]
141144

tests/core/test_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ def test_get_exporter_name(self):
3636
assert mfr_utils.get_exporter_name(ep.name) == expected
3737

3838
def test_get_exporter_name_no_entry_point(self):
39-
with pytest.raises(AssertionError):
40-
mfr_utils.get_exporter_name('jpg')
39+
assert mfr_utils.get_exporter_name('jpg') == ''

0 commit comments

Comments
 (0)