diff --git a/CHANGES.rst b/CHANGES.rst index a6c783ef..b09330a4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +Release 1.2.2 +========================================= + +* **BUGFIX:** Fixed behavior where ``Chart.download_chart(format = 'svg')`` was incorrectly returning a PNG rather than an SVG ( #63 ). + +------------------ + Release 1.2.1 ========================================= diff --git a/highcharts_core/__version__.py b/highcharts_core/__version__.py index ce34e913..079d34f0 100644 --- a/highcharts_core/__version__.py +++ b/highcharts_core/__version__.py @@ -1 +1 @@ -__version__ = '1.2.1' \ No newline at end of file +__version__ = '1.2.2' \ No newline at end of file diff --git a/highcharts_core/chart.py b/highcharts_core/chart.py index 2536d7fc..bb1c0143 100644 --- a/highcharts_core/chart.py +++ b/highcharts_core/chart.py @@ -464,6 +464,7 @@ def download_chart(self, constructor = constructor, scale = scale, width = width, + format_ = format, **kwargs) if not isinstance(server_instance, ExportServer): @@ -477,6 +478,7 @@ def download_chart(self, timeout = timeout, options = self.options, constructor = constructor, + format_ = format, **kwargs) @classmethod diff --git a/highcharts_core/headless_export.py b/highcharts_core/headless_export.py index 874eff69..06e4fa08 100644 --- a/highcharts_core/headless_export.py +++ b/highcharts_core/headless_export.py @@ -767,9 +767,13 @@ def request_chart(self, result.raise_for_status() - if filename: + if filename and self.format_ != 'svg': with open(filename, 'wb') as file_: file_.write(result.content) + elif filename and self.format_ == 'svg': + content = str(result.content, encoding = 'utf-8') + with open(filename, 'wt') as file_: + file_.write(content) return result.content diff --git a/tests/test_headless_export.py b/tests/test_headless_export.py index d7953464..abf90083 100644 --- a/tests/test_headless_export.py +++ b/tests/test_headless_export.py @@ -144,7 +144,7 @@ def test_url(value, error): 'headless_export/output/test-basic.png', { 'timeout': 5, - 'format': 'png', + 'format_': 'png', 'constructor': 'Chart' }, None), @@ -152,7 +152,7 @@ def test_url(value, error): 'headless_export/output/test-with-series-types.png', { 'timeout': 5, - 'format': 'png', + 'format_': 'png', 'constructor': 'Chart' }, None), @@ -160,7 +160,15 @@ def test_url(value, error): 'headless_export/output/test-with-chart-type.png', { 'timeout': 5, - 'format': 'png', + 'format_': 'png', + 'constructor': 'Chart' + }, + None), + ('headless_export/with-chart-type.js', + 'headless_export/output/test-with-chart-type.svg', + { + 'timeout': 5, + 'format_': 'svg', 'constructor': 'Chart' }, None), @@ -177,7 +185,7 @@ def test_get_chart(input_files, target_file = check_input_file(input_files, target_filename, create_directory = create_output_directory) - + with open(input_file, 'r') as file_: as_str = file_.read() @@ -190,6 +198,17 @@ def test_get_chart(input_files, if not error: result = cls.get_chart(**kwargs) + + format = kwargs.get('format_', None) + print(f'TESTING FORMAT: {format}') + assert result is not None if target_filename: assert checkers.is_on_filesystem(target_file) is True + if format == 'svg': + with open(target_file, 'r', encoding = 'utf-8') as file_: + file_contents = file_.read() + contents = str(file_contents) + assert contents.startswith( + '