Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

Release 1.3.7
=========================================

* **BUGFIX:** Fixed bug in ``HighchartsMeta.copy()`` (#98).
* **BUGFIX:** Fixed bug in data point serialization to primitive array.

---------------------

Release 1.3.6
=========================================

Expand Down
2 changes: 1 addition & 1 deletion highcharts_core/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.6'
__version__ = '1.3.7'
2 changes: 1 addition & 1 deletion highcharts_core/js_literal_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def serialize_to_js_literal(item, encoding = 'utf-8') -> Optional[str]:
:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
"""
if checkers.is_iterable(item, forbid_literals = (str, bytes, dict, UserDict)):
requires_js_objects = all([getattr(x, 'requires_js_object', True)
requires_js_objects = any([getattr(x, 'requires_js_object', True)
for x in item])
if requires_js_objects:
return [serialize_to_js_literal(x, encoding = encoding)
Expand Down
8 changes: 7 additions & 1 deletion highcharts_core/metaclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,14 @@ def _copy_dict_key(cls,

:returns: The value that should be placed in ``other`` for ``key``.
"""
if not isinstance(original, (dict, UserDict)):
return original

original_value = original[key]
other_value = other.get(key, None)
if other is None:
other_value = None
else:
other_value = other.get(key, None)

if isinstance(original_value, (dict, UserDict)):
new_value = {}
Expand Down
30 changes: 29 additions & 1 deletion tests/options/series/data/test_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for ``highcharts.no_data``."""

import pytest
from typing import List

from json.decoder import JSONDecodeError

Expand All @@ -17,13 +18,38 @@ class NonAbstractDataBase(DataBase):
def from_array(cls, value):
pass

def _get_props_from_array(self) -> List[str]:
"""Returns a list of the property names that can be set using the
:meth:`.from_array() <highcharts_core.options.series.data.base.DataBase.from_array>`
method.

:rtype: :class:`list <python:list>` of :class:`str <python:str>`
"""
return ['fromArrayProp1', 'fromArrayProp2']



cls = NonAbstractDataBase


class RequiringJSObject(NonAbstractDataBase):
def _to_untrimmed_dict(self):
return {'someKey': 123}

class NotRequiringJSObject(NonAbstractDataBase):
def _to_untrimmed_dict(self):
return {
'fromArrayProp1': 456,
'fromArrayProp2': 789
}


class RequiringJSObject2(NonAbstractDataBase):
def _to_untrimmed_dict(self):
return {'someKey': 123,
'fromArrayProp1': 456,
'fromArrayProp2': 789}


STANDARD_PARAMS = [
({}, None),
Expand Down Expand Up @@ -102,8 +128,10 @@ def test_from_js_literal(input_files, filename, as_file, error):

@pytest.mark.parametrize('cls, expected', [
(NonAbstractDataBase, False),
(NotRequiringJSObject, False),
(RequiringJSObject, True),

(RequiringJSObject2, True)

])
def test_requires_js_object(cls, expected):
obj = cls()
Expand Down
20 changes: 20 additions & 0 deletions tests/test_metaclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,26 @@ def test_trim_iterable(untrimmed, expected_type, expected_length, error):
with pytest.raises(error):
result = TestClass.trim_iterable(untrimmed)


@pytest.mark.parametrize('instance, error', [
(test_class_instance, None),
(test_class_trimmed_instance, None),
(test_class_iterable, None),
(test_class_none_iterable, None),
])
def test_copy(instance, error):
if not error:
result = instance.copy()
assert result is not None
assert isinstance(result, instance.__class__) is True
result_as_dict = result.to_dict()
instance_as_dict = instance.to_dict()
assert checkers.are_dicts_equivalent(result_as_dict, instance_as_dict) is True
else:
with pytest.raises(error):
result = instance.copy()


"""
@pytest.mark.parametrize('error', [
(None),
Expand Down