From 9be5d941064d4c9a51e2e9e9748ad176072059f1 Mon Sep 17 00:00:00 2001 From: Jerome Kelleher Date: Fri, 4 May 2018 11:32:14 +0100 Subject: [PATCH 1/2] Ensures that get_codec doesn't modify its argument. Closes #78. --- numcodecs/registry.py | 1 + numcodecs/tests/test_registry.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/numcodecs/registry.py b/numcodecs/registry.py index 64dca304..c11a1b36 100644 --- a/numcodecs/registry.py +++ b/numcodecs/registry.py @@ -29,6 +29,7 @@ def get_codec(config): Zlib(level=1) """ + config = dict(config) codec_id = config.pop('id', None) cls = codec_registry.get(codec_id, None) if cls is None: diff --git a/numcodecs/tests/test_registry.py b/numcodecs/tests/test_registry.py index 476388ba..3322e975 100644 --- a/numcodecs/tests/test_registry.py +++ b/numcodecs/tests/test_registry.py @@ -11,3 +11,11 @@ def test_registry_errors(): with pytest.raises(ValueError): get_codec({'id': 'foo'}) + + +def test_get_codec_argument(): + # Check that get_codec doesn't modify its argument. + arg = {"id": "json"} + before = dict(arg) + get_codec(arg) + assert before == arg From ba7c82e50df3015e91a50ee6c096baf2dab98712 Mon Sep 17 00:00:00 2001 From: Jerome Kelleher Date: Fri, 4 May 2018 11:39:24 +0100 Subject: [PATCH 2/2] Removed minor spam from test output. --- numcodecs/tests/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numcodecs/tests/common.py b/numcodecs/tests/common.py index b3f080e0..76068564 100644 --- a/numcodecs/tests/common.py +++ b/numcodecs/tests/common.py @@ -241,7 +241,6 @@ def check_err_decode_object_buffer(compressor): out = np.empty(10, dtype=object) with pytest.raises(ValueError): compressor.decode(enc, out=out) - print(out[:]) def check_err_encode_object_buffer(compressor):