Skip to content

Commit af72e05

Browse files
committed
add test_warning_on_missing_codec_config
1 parent a7714c7 commit af72e05

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,29 @@ def test_config_buffer_implementation() -> None:
232232
)
233233
arr_Crc32c[:] = data2d
234234
assert np.array_equal(arr_Crc32c[:], data2d)
235+
236+
237+
@pytest.mark.filterwarnings("error")
238+
def test_warning_on_missing_codec_config() -> None:
239+
class NewCodec(BytesCodec):
240+
pass
241+
242+
class NewCodec2(BytesCodec):
243+
pass
244+
245+
# error if codec is not registered
246+
with pytest.raises(KeyError):
247+
get_codec_class("missing_codec")
248+
249+
# no warning if only one implementation is available
250+
register_codec("new_codec", NewCodec)
251+
get_codec_class("new_codec")
252+
253+
# warning because multiple implementations are available but none is selected in the config
254+
register_codec("new_codec", NewCodec2)
255+
with pytest.warns(UserWarning):
256+
get_codec_class("new_codec")
257+
258+
# no warning if multiple implementations are available and one is selected in the config
259+
with config.set({"codecs.new_codec": fully_qualified_name(NewCodec)}):
260+
get_codec_class("new_codec")

0 commit comments

Comments
 (0)