-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add scale param to images #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
691b374
90fec76
7aa5561
f49d412
38846f0
e59f6ad
59e0ef6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from __future__ import absolute_import | ||
|
||
from unittest import TestCase | ||
import imghdr | ||
import tempfile | ||
import os | ||
import itertools | ||
|
||
from plotly.plotly import plotly as py | ||
|
||
|
||
class TestImage(TestCase): | ||
def setUp(self): | ||
py.sign_in('PlotlyImageTest', '786r5mecv0', | ||
plotly_domain='https://plot.ly', | ||
plotly_api_domain='https://api.plot.ly') | ||
|
||
self.data = [{'x': [1, 2, 3], 'y': [3, 1, 6]}] | ||
|
||
|
||
def _generate_image_get_returns_valid_image_test(image_format, | ||
width, height, scale): | ||
def test(self): | ||
image = py.image.get(self.data, image_format, width, height, scale) | ||
if image_format in ['png', 'jpeg']: | ||
assert imghdr.what('', image) == image_format | ||
|
||
return test | ||
|
||
|
||
def _generate_image_save_as_saves_valid_image(image_format, | ||
width, height, scale): | ||
def _test(self): | ||
f, filename = tempfile.mkstemp('.{}'.format(image_format)) | ||
py.image.save_as(self.data, filename, format=image_format, | ||
width=width, height=height, scale=scale) | ||
if image_format in ['png', 'jpeg']: | ||
assert imghdr.what(filename) == image_format | ||
else: | ||
assert os.path.getsize(filename) > 0 | ||
|
||
os.remove(filename) | ||
|
||
return _test | ||
|
||
kwargs = { | ||
'format': ['png', 'jpeg', 'pdf', 'svg'], | ||
'width': [None, 300], | ||
'height': [None, 300], | ||
'scale': [None, 5] | ||
} | ||
|
||
for args in itertools.product(kwargs['format'], kwargs['width'], | ||
kwargs['height'], kwargs['scale']): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of the possible combinations of the kwargs, e.g.
|
||
for test_generator in [_generate_image_get_returns_valid_image_test, | ||
_generate_image_save_as_saves_valid_image]: | ||
|
||
if args[0] in ['jpeg', 'pdf', 'svg'] and args[3] is not None: | ||
# Shouldn't need to skip these tests, the server should | ||
# be responding with a 400 level error since scale isn't supported, | ||
# but it doesn't yet, so just skip them | ||
continue | ||
|
||
_test = test_generator(*args) | ||
arg_string = ', '.join([str(a) for a in args]) | ||
test_name = test_generator.__name__.replace('_generate', 'test') | ||
test_name += '({})'.format(arg_string) | ||
setattr(TestImage, test_name, _test) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is so much fun. autogenerating tests of all of the permutations of input arguments!
heck yeah |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.7.7' | ||
__version__ = '1.7.8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have i ever told you how much i like the python standard library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, yeah that's a great one!