Skip to content

Commit 5c53687

Browse files
committed
Fixed bug in .copy(). Closes #98.
1 parent c06f055 commit 5c53687

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

highcharts_core/metaclasses.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,14 @@ def _copy_dict_key(cls,
664664
665665
:returns: The value that should be placed in ``other`` for ``key``.
666666
"""
667+
if not isinstance(original, (dict, UserDict)):
668+
return original
669+
667670
original_value = original[key]
668-
other_value = other.get(key, None)
671+
if other is None:
672+
other_value = None
673+
else:
674+
other_value = other.get(key, None)
669675

670676
if isinstance(original_value, (dict, UserDict)):
671677
new_value = {}

tests/test_metaclasses.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,26 @@ def test_trim_iterable(untrimmed, expected_type, expected_length, error):
232232
with pytest.raises(error):
233233
result = TestClass.trim_iterable(untrimmed)
234234

235+
236+
@pytest.mark.parametrize('instance, error', [
237+
(test_class_instance, None),
238+
(test_class_trimmed_instance, None),
239+
(test_class_iterable, None),
240+
(test_class_none_iterable, None),
241+
])
242+
def test_copy(instance, error):
243+
if not error:
244+
result = instance.copy()
245+
assert result is not None
246+
assert isinstance(result, instance.__class__) is True
247+
result_as_dict = result.to_dict()
248+
instance_as_dict = instance.to_dict()
249+
assert checkers.are_dicts_equivalent(result_as_dict, instance_as_dict) is True
250+
else:
251+
with pytest.raises(error):
252+
result = instance.copy()
253+
254+
235255
"""
236256
@pytest.mark.parametrize('error', [
237257
(None),

0 commit comments

Comments
 (0)