Skip to content

Commit 0e3b262

Browse files
authored
Merge pull request #64 from highcharts-for-python/develop
PR for v.1.2.2
2 parents 8e55fdf + a149dbb commit 0e3b262

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Release 1.2.2
2+
=========================================
3+
4+
* **BUGFIX:** Fixed behavior where ``Chart.download_chart(format = 'svg')`` was incorrectly returning a PNG rather than an SVG ( #63 ).
5+
6+
------------------
7+
18
Release 1.2.1
29
=========================================
310

highcharts_core/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.1'
1+
__version__ = '1.2.2'

highcharts_core/chart.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def download_chart(self,
464464
constructor = constructor,
465465
scale = scale,
466466
width = width,
467+
format_ = format,
467468
**kwargs)
468469

469470
if not isinstance(server_instance, ExportServer):
@@ -477,6 +478,7 @@ def download_chart(self,
477478
timeout = timeout,
478479
options = self.options,
479480
constructor = constructor,
481+
format_ = format,
480482
**kwargs)
481483

482484
@classmethod

highcharts_core/headless_export.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,13 @@ def request_chart(self,
767767

768768
result.raise_for_status()
769769

770-
if filename:
770+
if filename and self.format_ != 'svg':
771771
with open(filename, 'wb') as file_:
772772
file_.write(result.content)
773+
elif filename and self.format_ == 'svg':
774+
content = str(result.content, encoding = 'utf-8')
775+
with open(filename, 'wt') as file_:
776+
file_.write(content)
773777

774778
return result.content
775779

tests/test_headless_export.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,31 @@ def test_url(value, error):
144144
'headless_export/output/test-basic.png',
145145
{
146146
'timeout': 5,
147-
'format': 'png',
147+
'format_': 'png',
148148
'constructor': 'Chart'
149149
},
150150
None),
151151
('headless_export/with-series-types.js',
152152
'headless_export/output/test-with-series-types.png',
153153
{
154154
'timeout': 5,
155-
'format': 'png',
155+
'format_': 'png',
156156
'constructor': 'Chart'
157157
},
158158
None),
159159
('headless_export/with-chart-type.js',
160160
'headless_export/output/test-with-chart-type.png',
161161
{
162162
'timeout': 5,
163-
'format': 'png',
163+
'format_': 'png',
164+
'constructor': 'Chart'
165+
},
166+
None),
167+
('headless_export/with-chart-type.js',
168+
'headless_export/output/test-with-chart-type.svg',
169+
{
170+
'timeout': 5,
171+
'format_': 'svg',
164172
'constructor': 'Chart'
165173
},
166174
None),
@@ -177,7 +185,7 @@ def test_get_chart(input_files,
177185
target_file = check_input_file(input_files,
178186
target_filename,
179187
create_directory = create_output_directory)
180-
188+
181189
with open(input_file, 'r') as file_:
182190
as_str = file_.read()
183191

@@ -190,6 +198,17 @@ def test_get_chart(input_files,
190198

191199
if not error:
192200
result = cls.get_chart(**kwargs)
201+
202+
format = kwargs.get('format_', None)
203+
print(f'TESTING FORMAT: {format}')
204+
193205
assert result is not None
194206
if target_filename:
195207
assert checkers.is_on_filesystem(target_file) is True
208+
if format == 'svg':
209+
with open(target_file, 'r', encoding = 'utf-8') as file_:
210+
file_contents = file_.read()
211+
contents = str(file_contents)
212+
assert contents.startswith(
213+
'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"'
214+
) is True

0 commit comments

Comments
 (0)