-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: concentrate test methods on logic
- Loading branch information
Showing
5 changed files
with
76 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import pathlib | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from pre_commit_images.optimize_jpg import main | ||
|
||
|
||
def test_compress_jpg(tmpdir): | ||
@pytest.fixture | ||
def images(tmpdir): | ||
image = "test.jpg" | ||
path = Path(tmpdir) / image | ||
test_file = Path(__file__).parent / image | ||
path = pathlib.Path(tmpdir) / image | ||
test_file = pathlib.Path(__file__).parent / image | ||
shutil.copy(test_file, path) | ||
return path, test_file | ||
|
||
|
||
def test_compress_jpg(images): | ||
path, test_file = images | ||
|
||
assert main(("-q", "50", str(path))) == 0 | ||
assert test_file.stat().st_size > path.stat().st_size | ||
|
||
|
||
def test_compress_jpg_below_threshold(tmpdir): | ||
image = "test.jpg" | ||
path = Path(tmpdir) / image | ||
test_file = Path(__file__).parent / image | ||
shutil.copy(test_file, path) | ||
def test_compress_jpg_below_threshold(images): | ||
path, test_file = images | ||
|
||
assert main(("-q", "97", "-t", "15000", str(path))) == 0 | ||
assert test_file.stat().st_size == path.stat().st_size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters