Skip to content

Commit d71170e

Browse files
committed
Fixed bug in primitive array serialization.
1 parent 5c53687 commit d71170e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

highcharts_core/js_literal_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def serialize_to_js_literal(item, encoding = 'utf-8') -> Optional[str]:
2525
:rtype: :class:`str <python:str>` or :obj:`None <python:None>`
2626
"""
2727
if checkers.is_iterable(item, forbid_literals = (str, bytes, dict, UserDict)):
28-
requires_js_objects = all([getattr(x, 'requires_js_object', True)
28+
requires_js_objects = any([getattr(x, 'requires_js_object', True)
2929
for x in item])
3030
if requires_js_objects:
3131
return [serialize_to_js_literal(x, encoding = encoding)

tests/options/series/data/test_base.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for ``highcharts.no_data``."""
22

33
import pytest
4+
from typing import List
45

56
from json.decoder import JSONDecodeError
67

@@ -17,13 +18,38 @@ class NonAbstractDataBase(DataBase):
1718
def from_array(cls, value):
1819
pass
1920

21+
def _get_props_from_array(self) -> List[str]:
22+
"""Returns a list of the property names that can be set using the
23+
:meth:`.from_array() <highcharts_core.options.series.data.base.DataBase.from_array>`
24+
method.
25+
26+
:rtype: :class:`list <python:list>` of :class:`str <python:str>`
27+
"""
28+
return ['fromArrayProp1', 'fromArrayProp2']
29+
30+
31+
2032
cls = NonAbstractDataBase
2133

2234

2335
class RequiringJSObject(NonAbstractDataBase):
2436
def _to_untrimmed_dict(self):
2537
return {'someKey': 123}
2638

39+
class NotRequiringJSObject(NonAbstractDataBase):
40+
def _to_untrimmed_dict(self):
41+
return {
42+
'fromArrayProp1': 456,
43+
'fromArrayProp2': 789
44+
}
45+
46+
47+
class RequiringJSObject2(NonAbstractDataBase):
48+
def _to_untrimmed_dict(self):
49+
return {'someKey': 123,
50+
'fromArrayProp1': 456,
51+
'fromArrayProp2': 789}
52+
2753

2854
STANDARD_PARAMS = [
2955
({}, None),
@@ -102,8 +128,10 @@ def test_from_js_literal(input_files, filename, as_file, error):
102128

103129
@pytest.mark.parametrize('cls, expected', [
104130
(NonAbstractDataBase, False),
131+
(NotRequiringJSObject, False),
105132
(RequiringJSObject, True),
106-
133+
(RequiringJSObject2, True)
134+
107135
])
108136
def test_requires_js_object(cls, expected):
109137
obj = cls()

0 commit comments

Comments
 (0)