Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
fail-fast: false
matrix:
python-version: [
"2.7",
"3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev",
"3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev",
"pypy-2.7", "pypy-3.10"
]
os: [ubuntu-latest, macOS-latest, windows-latest]
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.6.1

* Updated runtime support
* Dropped python 3.7
* Added Python 3.12
* Added Python 3.13
* Tests: Replaced httpretty with requests-mock

## 1.6.0
* Updated runtime support
* Dropped 2.6
Expand Down
63 changes: 28 additions & 35 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,43 @@
except ImportError:
from distutils.core import setup

sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'tinify'))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "tinify"))
from version import __version__

install_require = ['requests >= 2.7.0, < 3.0.0']
tests_require = ['pytest', 'httpretty < 1.1.5']

if sys.version_info < (2, 7):
tests_require.append('unittest2')
if sys.version_info < (3, 3):
tests_require.append('mock >= 1.3, < 2.0')
install_require = ["requests >= 2.7.0, < 3.0.0"]
tests_require = ["pytest", "pytest-xdist", "requests-mock"]

setup(
name='tinify',
name="tinify",
version=__version__,
description='Tinify API client.',
author='Jacob Middag',
author_email='[email protected]',
license='MIT',
long_description='Python client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.',
long_description_content_type='text/markdown',
url='https://tinify.com/developers',

packages=['tinify'],
description="Tinify API client.",
author="Jacob Middag",
author_email="[email protected]",
license="MIT",
long_description="Python client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.",
long_description_content_type="text/markdown",
url="https://tinify.com/developers",
packages=["tinify"],
package_data={
'': ['LICENSE', 'README.md'],
'tinify': ['data/cacert.pem'],
"": ["LICENSE", "README.md"],
"tinify": ["data/cacert.pem"],
},

install_requires=install_require,
tests_require=tests_require,
extras_require={'test': tests_require},

extras_require={"test": tests_require},
classifiers=(
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Natural Language :: English",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
),
)
32 changes: 32 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
import os
import tinify
import requests_mock


@pytest.fixture
def dummy_file():
return os.path.join(os.path.dirname(__file__), "examples", "dummy.png")


@pytest.fixture(autouse=True)
def reset_tinify():
original_key = tinify.key
original_app_identifier = tinify.app_identifier
original_proxy = tinify.proxy

tinify.key = None
tinify.app_identifier = None
tinify.proxy = None

yield

tinify.key = original_key
tinify.app_identifier = original_app_identifier
tinify.proxy = original_proxy


@pytest.fixture
def mock_requests():
with requests_mock.Mocker(real_http=False) as m:
yield m
73 changes: 0 additions & 73 deletions test/helper.py

This file was deleted.

121 changes: 68 additions & 53 deletions test/integration.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import sys, os
import sys
import os
from contextlib import contextmanager
import tinify, unittest, tempfile
import tinify
import pytest
import tempfile

if not os.environ.get("TINIFY_KEY"):
sys.exit("Set the TINIFY_KEY environment variable.")


@contextmanager
def create_named_tmpfile():
# Due to NamedTemporaryFile requiring to be closed when used on Windows
Expand All @@ -19,76 +23,87 @@ def create_named_tmpfile():
os.unlink(tmp.name)


class ClientIntegrationTest(unittest.TestCase):
# Fixture for shared resources
@pytest.fixture(scope="module")
def optimized_image():
tinify.key = os.environ.get("TINIFY_KEY")
tinify.proxy = os.environ.get("TINIFY_PROXY")

unoptimized_path = os.path.join(os.path.dirname(__file__), 'examples', 'voormedia.png')
optimized = tinify.from_file(unoptimized_path)
unoptimized_path = os.path.join(
os.path.dirname(__file__), "examples", "voormedia.png"
)
return tinify.from_file(unoptimized_path)


def test_should_compress_from_file(optimized_image):
with create_named_tmpfile() as tmp:
optimized_image.to_file(tmp)

size = os.path.getsize(tmp)

with open(tmp, "rb") as f:
contents = f.read()

assert 1000 < size < 1500

def test_should_compress_from_file(self):
with create_named_tmpfile() as tmp:
self.optimized.to_file(tmp)
# width == 137
assert b"\x00\x00\x00\x89" in contents
assert b"Copyright Voormedia" not in contents

size = os.path.getsize(tmp)

with open(tmp, 'rb') as f:
contents = f.read()
def test_should_compress_from_url():
source = tinify.from_url(
"https://raw.githubusercontent.com/tinify/tinify-python/master/test/examples/voormedia.png"
)
with create_named_tmpfile() as tmp:
source.to_file(tmp)

self.assertTrue(1000 < size < 1500)
size = os.path.getsize(tmp)
with open(tmp, "rb") as f:
contents = f.read()

# width == 137
self.assertIn(b'\x00\x00\x00\x89', contents)
self.assertNotIn(b'Copyright Voormedia', contents)
assert 1000 < size < 1500

def test_should_compress_from_url(self):
source = tinify.from_url('https://raw.githubusercontent.com/tinify/tinify-python/master/test/examples/voormedia.png')
with create_named_tmpfile() as tmp:
source.to_file(tmp)
# width == 137
assert b"\x00\x00\x00\x89" in contents
assert b"Copyright Voormedia" not in contents

size = os.path.getsize(tmp)
with open(tmp, 'rb') as f:
contents = f.read()

self.assertTrue(1000 < size < 1500)
def test_should_resize(optimized_image):
with create_named_tmpfile() as tmp:
optimized_image.resize(method="fit", width=50, height=20).to_file(tmp)

# width == 137
self.assertIn(b'\x00\x00\x00\x89', contents)
self.assertNotIn(b'Copyright Voormedia', contents)
size = os.path.getsize(tmp)
with open(tmp, "rb") as f:
contents = f.read()

def test_should_resize(self):
with create_named_tmpfile() as tmp:
self.optimized.resize(method="fit", width=50, height=20).to_file(tmp)
assert 500 < size < 1000

size = os.path.getsize(tmp)
with open(tmp, 'rb') as f:
contents = f.read()
# width == 50
assert b"\x00\x00\x00\x32" in contents
assert b"Copyright Voormedia" not in contents

self.assertTrue(500 < size < 1000)

# width == 50
self.assertIn(b'\x00\x00\x00\x32', contents)
self.assertNotIn(b'Copyright Voormedia', contents)
def test_should_preserve_metadata(optimized_image):
with create_named_tmpfile() as tmp:
optimized_image.preserve("copyright", "creation").to_file(tmp)

def test_should_preserve_metadata(self):
with create_named_tmpfile() as tmp:
self.optimized.preserve("copyright", "creation").to_file(tmp)
size = os.path.getsize(tmp)
with open(tmp, "rb") as f:
contents = f.read()

size = os.path.getsize(tmp)
with open(tmp, 'rb') as f:
contents = f.read()
assert 1000 < size < 2000

self.assertTrue(1000 < size < 2000)
# width == 137
assert b"\x00\x00\x00\x89" in contents
assert b"Copyright Voormedia" in contents

# width == 137
self.assertIn(b'\x00\x00\x00\x89', contents)
self.assertIn(b'Copyright Voormedia', contents)

def test_should_transcode_image(self):
with create_named_tmpfile() as tmp:
a = self.optimized.convert(type=["image/webp"]).to_file(tmp)
with open(tmp, 'rb') as f:
content = f.read()
def test_should_transcode_image(optimized_image):
with create_named_tmpfile() as tmp:
optimized_image.convert(type=["image/webp"]).to_file(tmp)
with open(tmp, "rb") as f:
content = f.read()

self.assertEqual(b'RIFF', content[:4])
self.assertEqual(b'WEBP', content[8:12])
assert b"RIFF" == content[:4]
assert b"WEBP" == content[8:12]
Loading
Loading