A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/wq/django-rest-pandas/commit/c0c8b5cd5d1a107191c3793447bc956e4da09f19 below:

fix and test image renderer · wq/django-rest-pandas@c0c8b5c · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+35

-1

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+35

-1

lines changed Original file line number Diff line number Diff line change

@@ -11,6 +11,7 @@

11 11

from io import StringIO

12 12 13 13

import os

14 +

from io import BytesIO

14 15 15 16 16 17

class PandasBaseRenderer(BaseRenderer):

@@ -148,7 +149,7 @@ def get_pandas_kwargs(self, data, renderer_context):

148 149

return {'ax': self.ax}

149 150 150 151

def get_output(self):

151 -

data = StringIO()

152 +

data = BytesIO()

152 153

self.fig.savefig(data, format=self.format)

153 154

return data.getvalue()

154 155 Original file line number Diff line number Diff line change

@@ -0,0 +1,33 @@

1 +

from rest_framework.test import APITestCase

2 +

from tests.testapp.models import TimeSeries

3 +

import unittest

4 + 5 +

try:

6 +

import matplotlib

7 +

except ImportError:

8 +

matplotlib = None

9 + 10 + 11 +

class ImageTestCase(APITestCase):

12 +

def setUp(self):

13 +

data = (

14 +

('2014-01-01', 0.5),

15 +

('2014-01-02', 0.4),

16 +

('2014-01-03', 0.6),

17 +

('2014-01-04', 0.2),

18 +

('2014-01-05', 0.1),

19 +

)

20 +

for date, value in data:

21 +

TimeSeries.objects.create(date=date, value=value)

22 + 23 +

@unittest.skipUnless(matplotlib, "requires matplotlib")

24 +

def test_png(self):

25 +

response = self.client.get("/timeseries.png")

26 +

header = response.content[1:4]

27 +

self.assertEqual(header, b"PNG")

28 + 29 +

@unittest.skipUnless(matplotlib, "requires matplotlib")

30 +

def test_svg(self):

31 +

response = self.client.get("/timeseries.svg")

32 +

header = response.content[2:5]

33 +

self.assertEqual(header, b"xml")

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4