<s> import os <EOL> import tarfile <EOL> import pytest <EOL> from atomic_reactor . constants import EXPORTED_COMPRESSED_IMAGE_NAME_TEMPLATE <EOL> from atomic_reactor . core import DockerTasker <EOL> from atomic_reactor . inner import DockerBuildWorkflow <EOL> from atomic_reactor . plugin import PostBuildPluginsRunner <EOL> from atomic_reactor . plugins . post_compress import CompressPlugin <EOL> from atomic_reactor . util import ImageName <EOL> from tests . constants import INPUT_IMAGE , MOCK <EOL> if MOCK : <EOL> from tests . docker_mock import mock_docker <EOL> class Y ( object ) : <EOL> dockerfile_path = None <EOL> path = None <EOL> class X ( object ) : <EOL> image_id = INPUT_IMAGE <EOL> source = Y ( ) <EOL> base_image = ImageName . parse ( '<STR_LIT>' ) <EOL> class TestCompress ( object ) : <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ] ) <EOL> def test_compress ( self , tmpdir , caplog , method , load_exported_image , extension ) : <EOL> if MOCK : <EOL> mock_docker ( ) <EOL> tasker = DockerTasker ( ) <EOL> workflow = DockerBuildWorkflow ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT>' ) <EOL> workflow . builder = X ( ) <EOL> exp_img = os . path . join ( str ( tmpdir ) , '<STR_LIT>' ) <EOL> if load_exported_image : <EOL> tarfile . open ( exp_img , mode = '<STR_LIT:w>' ) . close ( ) <EOL> workflow . exported_image_sequence . append ( { '<STR_LIT:path>' : exp_img } ) <EOL> runner = PostBuildPluginsRunner ( <EOL> tasker , <EOL> workflow , <EOL> [ { <EOL> '<STR_LIT:name>' : CompressPlugin . key , <EOL> '<STR_LIT:args>' : { <EOL> '<STR_LIT>' : method , <EOL> '<STR_LIT>' : load_exported_image , <EOL> } , <EOL> } ] <EOL> ) <EOL> runner . run ( ) <EOL> compressed_img = os . path . join ( <EOL> workflow . source . tmpdir , <EOL> EXPORTED_COMPRESSED_IMAGE_NAME_TEMPLATE . format ( extension ) ) <EOL> assert os . path . exists ( compressed_img ) <EOL> metadata = workflow . exported_image_sequence [ - <NUM_LIT:1> ] <EOL> assert metadata [ '<STR_LIT:path>' ] == compressed_img <EOL> assert '<STR_LIT>' in metadata <EOL> assert isinstance ( metadata [ '<STR_LIT>' ] , int ) <EOL> assert "<STR_LIT>" in caplog . text ( ) </s>
