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
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
=========================================

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.2.1'
__version__ = '1.2.2'
2 changes: 2 additions & 0 deletions highcharts_core/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def download_chart(self,
constructor = constructor,
scale = scale,
width = width,
format_ = format,
**kwargs)

if not isinstance(server_instance, ExportServer):
Expand All @@ -477,6 +478,7 @@ def download_chart(self,
timeout = timeout,
options = self.options,
constructor = constructor,
format_ = format,
**kwargs)

@classmethod
Expand Down
6 changes: 5 additions & 1 deletion highcharts_core/headless_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 23 additions & 4 deletions tests/test_headless_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,31 @@ def test_url(value, error):
'headless_export/output/test-basic.png',
{
'timeout': 5,
'format': 'png',
'format_': 'png',
'constructor': 'Chart'
},
None),
('headless_export/with-series-types.js',
'headless_export/output/test-with-series-types.png',
{
'timeout': 5,
'format': 'png',
'format_': 'png',
'constructor': 'Chart'
},
None),
('headless_export/with-chart-type.js',
'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),
Expand All @@ -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()

Expand All @@ -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(
'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"'
) is True