|
| 1 | +# Copyright 2021 CDPedistas (see AUTHORS.txt) |
| 2 | +# |
| 3 | +# This program is free software: you can redistribute it and/or modify it |
| 4 | +# under the terms of the GNU General Public License version 3, as published |
| 5 | +# by the Free Software Foundation. |
| 6 | +# |
| 7 | +# This program is distributed in the hope that it will be useful, but |
| 8 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
| 9 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 10 | +# PURPOSE. See the GNU General Public License for more details. |
| 11 | +# |
| 12 | +# You should have received a copy of the GNU General Public License along |
| 13 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
| 14 | +# |
| 15 | +# For further info, check https://github.com/PyAr/CDPedia/ |
| 16 | + |
| 17 | +import os |
| 18 | +import shutil |
| 19 | + |
| 20 | +from src.images.download import optimize_png |
| 21 | + |
| 22 | +import pytest |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture |
| 26 | +def image_config(tmp_path): |
| 27 | + img_test_name = 'tests/fixtures/image_to_optimize.png' |
| 28 | + test_path = str(tmp_path / 'image_to_optimize.png') |
| 29 | + shutil.copy(img_test_name, test_path) |
| 30 | + init_size = os.stat(img_test_name).st_size |
| 31 | + return test_path, init_size |
| 32 | + |
| 33 | + |
| 34 | +def test_optimize(image_config): |
| 35 | + img_path, init_size = image_config |
| 36 | + optimize_png(img_path, init_size, init_size) |
| 37 | + final_size = os.stat(img_path).st_size |
| 38 | + assert init_size > final_size |
0 commit comments