Skip to content

Commit

Permalink
More tests and add coverage of branches
Browse files Browse the repository at this point in the history
  • Loading branch information
samastur committed Nov 15, 2015
1 parent 6fd61ac commit c2d5902
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[run]
source=pyimagediet
branch=True
13 changes: 13 additions & 0 deletions tests/balloon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python

import sys


def main(filename, content, *args):
with open(filename, 'a') as f:
f.write(content)
f.write('\n')


if __name__ == '__main__':
main(*sys.argv[1:])
36 changes: 36 additions & 0 deletions tests/test_diet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'gif': ['gifsicle'],
'jpeg': ['jpegtran'],
'png': ['optipng', 'advpng', 'pngcrush']}}
BALLOON_CMD = join(TEST_DIR, 'balloon.py')


@pytest.fixture
Expand Down Expand Up @@ -230,6 +231,12 @@ def test_squeeze_shrinks_an_image():
#
# diet
#
def add_fake_pipeline_to_config(cmd, conf):
conf['commands']['balloon'] = cmd
conf['parameters']['balloon'] = '{file} "more bytes"'
conf['pipelines']['text'] = ['balloon']


def test_diet_complains_if_passed_filename_is_not_file():
filename = TEST_FILES_DIR

Expand Down Expand Up @@ -276,3 +283,32 @@ def test_diet_doesnt_change_files_without_pipeline(config_copy):

diet.diet(filename, config_copy)
assert os.stat(filename) == statinfo


def test_diet_keeps_smaller_file_by_default(config_copy):
add_fake_pipeline_to_config(BALLOON_CMD, config_copy)
orig_filename = join(TEST_FILES_DIR, 'config.yaml')
diet.backup_file(orig_filename, 'test')
filename = ".".join([orig_filename, "test"])

old_size = os.stat(filename).st_size

diet.diet(filename, config_copy)
assert os.stat(filename).st_size == old_size

os.remove(filename)


def test_diet_keeps_processed_file_if_keep_processed_is_enabled(config_copy):
add_fake_pipeline_to_config(BALLOON_CMD, config_copy)
config_copy['keep_processed'] = True
orig_filename = join(TEST_FILES_DIR, 'config.yaml')
diet.backup_file(orig_filename, 'test')
filename = ".".join([orig_filename, "test"])

old_size = os.stat(filename).st_size

diet.diet(filename, config_copy)
assert os.stat(filename).st_size > old_size

os.remove(filename)

0 comments on commit c2d5902

Please sign in to comment.