Skip to content

Commit 5c5b81d

Browse files
committed
update tests. drop py2 support
1 parent 7272be7 commit 5c5b81d

File tree

4 files changed

+59
-61
lines changed

4 files changed

+59
-61
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: xenial
12
language: python
2-
python: ['2.7', '3.6']
3-
script: python tests.py
3+
python: ['3.4', '3.5', '3.6', '3.7']
4+
script: python3 setup.py test

setup.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# coding: utf-8
22
from setuptools import setup
3+
from setuptools.command.test import test as TestCommand
4+
35
import imgspy
46

57

8+
class PyTestCommand(TestCommand):
9+
user_options = [("pytest-args=", "a", "Arguments to pass to pytest")]
10+
11+
def run_tests(self):
12+
import sys, pytest
13+
sys.exit(pytest.main([]))
14+
15+
616
setup(
717
name='imgspy',
818
version=imgspy.__version__,
@@ -25,5 +35,7 @@
2535
author='Nazar Kanaev',
2636
author_email='[email protected]',
2737
py_modules=['imgspy'],
28-
test_suite='tests'
38+
test_suite='tests',
39+
tests_require=['pytest'],
40+
cmdclass={"test": PyTestCommand},
2941
)

test_imgspy.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import re
3+
import glob
4+
import textwrap
5+
import urllib.request
6+
7+
import imgspy
8+
9+
10+
BASEDIR = os.path.dirname(os.path.abspath(__file__))
11+
FORMAT = r'sample(?P<width>\d+)x(?P<height>\d+)(?P<comment>[^.]*).(?P<format>\w+)'
12+
13+
14+
def test_samples():
15+
for filepath in glob.glob(os.path.join(BASEDIR, 'fixtures/sample*')):
16+
filename = os.path.basename(filepath)
17+
match = re.match(FORMAT, filename)
18+
expected = {
19+
'type': match.group('format'),
20+
'width': int(match.group('width')),
21+
'height': int(match.group('height'))}
22+
23+
actual = imgspy.info(open(filepath, 'rb'))
24+
assert isinstance(actual, dict), filename
25+
26+
actual_subset = {k: v for k, v in actual.items() if k in expected}
27+
assert actual_subset == expected, filename
28+
29+
30+
def test_datastr():
31+
data = textwrap.dedent('''data:image/png;base64,
32+
iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+
33+
KAAAAD0lEQVR42mNk+M9QzwAEAAmGAYCF+yOnAAAAAElFTkSuQmCC''')
34+
assert imgspy.info(data) == {'type': 'png', 'width': 2, 'height': 1}
35+
36+
37+
def test_url():
38+
domain = 'http://via.placeholder.com'
39+
urls = {
40+
domain + '/500x500.png': {'type': 'png', 'width': 500, 'height': 500},
41+
domain + '/500x500.jpg': {'type': 'jpg', 'width': 500, 'height': 500},}
42+
for url, expected in urls.items():
43+
assert imgspy.info(urllib.request.urlopen(url)) == expected

tests.py

-58
This file was deleted.

0 commit comments

Comments
 (0)