diff --git a/CHANGES.rst b/CHANGES.rst index 29d9142..456a9cb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,13 @@ +Release 1.4.1 +========================================= + +* **BUGFIX**: Fixed incorrect cross-dependency inheritance in + ``options/series_generator.create_series_obj()`` (#36) + +--------------------- + + Release 1.4.0 ========================================= diff --git a/highcharts_maps/__version__.py b/highcharts_maps/__version__.py index 96e3ce8..8e3c933 100644 --- a/highcharts_maps/__version__.py +++ b/highcharts_maps/__version__.py @@ -1 +1 @@ -__version__ = '1.4.0' +__version__ = '1.4.1' diff --git a/highcharts_maps/options/series/series_generator.py b/highcharts_maps/options/series/series_generator.py index 52a5010..ff7f38a 100644 --- a/highcharts_maps/options/series/series_generator.py +++ b/highcharts_maps/options/series/series_generator.py @@ -4,8 +4,9 @@ from highcharts_maps import errors +from highcharts_core.options.series.base import SeriesBase + # Highcharts for Python series -from highcharts_maps.options.series.base import SeriesBase from highcharts_maps.options.series.arcdiagram import ArcDiagramSeries from highcharts_maps.options.series.area import AreaSeries from highcharts_maps.options.series.area import AreaRangeSeries diff --git a/tests/options/chart/test_chart.py b/tests/options/chart/test_chart.py index e9383c0..0ac2a5f 100644 --- a/tests/options/chart/test_chart.py +++ b/tests/options/chart/test_chart.py @@ -12,6 +12,59 @@ STANDARD_PARAMS = [ ({}, None), + ({ + 'align_thresholds': True, + 'align_ticks': True, + 'allow_mutating_data': True, + 'animation': False, + 'background_color': '#fff', + 'border_color': '#ccc', + 'border_radius': 3, + 'border_width': 1, + 'class_name': 'some-class-name', + 'color_count': 10, + 'display_errors': True, + 'events': { + 'addSeries': """function(event) { return true;}""", + 'afterPrint': """function(event) {return true;}""", + 'click': """function(event) { return true; }""", + 'selection': """function(event) { return true; }""" + }, + 'height': 120, + 'ignore_hidden_series': False, + 'inverted': False, + 'margin': 20, + 'number_formatter': """function(value) { return true; }""", + 'pan_key': 'ctrl', + 'panning': { + 'enabled': True, + 'type': 'x' + }, + 'parallel_coordinates': False, + 'plot_background_color': '#ccc', + 'plot_background_image': 'http://www.somewhere.com', + 'plot_border_color': '#999', + 'plot_border_width': 1, + 'plot_shadow': False, + 'polar': False, + 'reflow': False, + 'render_to': 'some-id', + 'scrollable_plot_area': { + 'minHeight': 120, + 'minWidth': 300, + 'opacity': 0.6, + 'scrollPositionX': 0, + 'scrollPositionY': 0 + }, + 'selection_marker_fill': '#ccc', + 'shadow': False, + 'show_axes': True, + 'spacing': [5, 5, 5, 5], + 'style': 'style-string-goes-here', + 'styled_mode': False, + 'type': 'line', + 'width': 50 + }, None), ({ 'align_thresholds': True, 'align_ticks': True, @@ -64,6 +117,16 @@ 'styled_mode': False, 'type': 'line', 'width': 50, + 'zooming': { + 'key': 'alt', + 'mouse_wheel': { + 'enabled': True, + 'sensitivity': 1.5, + 'type': 'xy' + }, + 'pinch_type': 'xy', + 'single_touch': False + } }, None), ] @@ -90,6 +153,7 @@ def test_to_dict(kwargs, error): @pytest.mark.parametrize('filename, as_file, error', [ ('chart/chart/01.js', False, None), + ('chart/chart/02.js', False, None), ('chart/chart/error-01.js', False, @@ -100,6 +164,7 @@ def test_to_dict(kwargs, error): ValueError)), ('chart/chart/01.js', True, None), + ('chart/chart/02.js', False, None), ('chart/chart/error-01.js', True, @@ -112,3 +177,91 @@ def test_to_dict(kwargs, error): ]) def test_from_js_literal(input_files, filename, as_file, error): Class_from_js_literal(cls, input_files, filename, as_file, error) + + +@pytest.mark.parametrize('as_dict, as_js_literal, error', [ + ({ + 'marginRight': 124 + }, False, None), + ({ + 'type': 'bar', + 'marginRight': 124, + 'marginTop': 421, + 'marginBottom': 321, + 'marginLeft': 789, + 'scrollablePlotArea': { + 'minHeight': 1000, + 'opacity': 1 + } + }, False, None), + + ({ + 'marginRight': 124 + }, True, None), + ({ + 'type': 'bar', + 'marginRight': 124, + 'marginTop': 421, + 'marginBottom': 321, + 'marginLeft': 789, + 'scrollablePlotArea': { + 'minHeight': 1000, + 'opacity': 1 + } + }, True, None), +]) +def test_bug124_margin_right(as_dict, as_js_literal, error): + if not error: + if not as_js_literal: + result = cls.from_dict(as_dict) + else: + as_str = str(as_dict) + result = cls.from_js_literal(as_str) + assert isinstance(result, cls) is True + if 'marginRight' in as_dict or 'margin_right' in as_dict: + assert result.margin_right == as_dict.get('marginRight', None) + if 'marginTop' in as_dict or 'margin_top' in as_dict: + assert result.margin_top == as_dict.get('marginTop', None) + if 'marginBottom' in as_dict or 'margin_bottom' in as_dict: + assert result.margin_bottom == as_dict.get('marginBottom', None) + if 'marginLeft' in as_dict or 'margin_left' in as_dict: + assert result.margin_left == as_dict.get('marginLeft', None) + else: + with pytest.raises(error): + if not as_js_literal: + result = cls.from_dict(as_dict) + else: + as_str = str(as_dict) + result = cls.from_js_literal(as_str) + + +@pytest.mark.parametrize('as_str, error', [ + ("""{ + marginRight: 124 + }""", None), + ("""{type: 'bar', + marginRight: 124, + marginTop: 421, + marginBottom: 321, + marginLeft: 789, + scrollablePlotArea: { + minHeight: 1000, + opacity: 1 + } + }""", None), +]) +def test_bug124_margin_right_from_js_literal(as_str, error): + if not error: + result = cls.from_js_literal(as_str) + assert isinstance(result, cls) is True + if 'marginRight' in as_str or 'margin_right' in as_str: + assert result.margin_right is not None + if 'marginTop' in as_str or 'margin_top' in as_str: + assert result.margin_top is not None + if 'marginBottom' in as_str or 'margin_bottom' in as_str: + assert result.margin_bottom is not None + if 'marginLeft' in as_str or 'margin_left' in as_str: + assert result.margin_left is not None + else: + with pytest.raises(error): + result = cls.from_js_literal(as_str) diff --git a/tests/options/series/test_series_generator.py b/tests/options/series/test_series_generator.py new file mode 100644 index 0000000..997100e --- /dev/null +++ b/tests/options/series/test_series_generator.py @@ -0,0 +1,26 @@ +import pytest + +from json.decoder import JSONDecodeError + +from highcharts_core.options.series.base import SeriesBase as CoreSeriesBase +from highcharts_core.options.series.bar import BarSeries as CoreBarSeries +from highcharts_maps.options.series.base import SeriesBase as MapsSeriesBase +from highcharts_maps.options.series.bar import BarSeries as MapsBarSeries + +from highcharts_maps.options.series.series_generator import create_series_obj + + +@pytest.mark.parametrize('cls, expected, error', [ + (CoreBarSeries, True, None), + (MapsBarSeries, True, None), +]) +def test_isinstance_check(cls, expected, error): + if not error: + item = cls() + result = create_series_obj(item) + assert isinstance(result, cls) is expected + assert isinstance(result, CoreSeriesBase) is expected + else: + item = cls() + with pytest.raises(error): + result = create_series_obj(item) \ No newline at end of file