<s> from __future__ import with_statement <EOL> from . import file_utilities <EOL> import pytest <EOL> from . . import zipdir <EOL> from contextlib import closing <EOL> import zipfile <EOL> import tempfile <EOL> import shutil <EOL> import os <EOL> import sys <EOL> class TestZipDir : <EOL> good_cases = [ <EOL> [ "<STR_LIT:a>" , "<STR_LIT:b>" , ( "<STR_LIT>" , <NUM_LIT:1000> ) , ( "<STR_LIT>" , <NUM_LIT:1000> ) , ( "<STR_LIT>" , <NUM_LIT:1000> ) ] , <EOL> [ "<STR_LIT:a>" , ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> [ ( "<STR_LIT:bar>" , <NUM_LIT:1000> ) ] <EOL> ] <EOL> @ pytest . fixture <EOL> def zip_tree ( self , request , test_case ) : <EOL> try : <EOL> test_dir = zip_file = unzip_dir = None <EOL> test_dir = file_utilities . create_test_directory ( test_case ) <EOL> zip_file_handle = tempfile . NamedTemporaryFile ( delete = False ) <EOL> zip_file_handle . close ( ) <EOL> zip_file = zip_file_handle . name <EOL> zipdir . zip_directory ( test_dir , zip_file ) <EOL> unzip_dir = tempfile . mkdtemp ( ) <EOL> with closing ( zipfile . ZipFile ( zip_file , "<STR_LIT:r>" ) ) as f : <EOL> f . extractall ( unzip_dir ) <EOL> except : <EOL> if test_dir is not None : <EOL> shutil . rmtree ( test_dir ) <EOL> if zip_file is not None : <EOL> os . remove ( zip_file ) <EOL> if unzip_dir is not None : <EOL> shutil . rmtree ( unzip_dir ) <EOL> raise <EOL> def cleanup ( ) : <EOL> shutil . rmtree ( test_dir ) <EOL> os . remove ( zip_file ) <EOL> shutil . rmtree ( unzip_dir ) <EOL> request . addfinalizer ( cleanup ) <EOL> return test_dir , zip_file , unzip_dir <EOL> @ pytest . mark . parametrize ( "<STR_LIT>" , good_cases ) <EOL> def test_existence ( self , zip_tree , test_case ) : <EOL> """<STR_LIT>""" <EOL> test_dir , zip_file , unzip_dir = zip_tree <EOL> real_contents = file_utilities . get_files ( unzip_dir ) <EOL> expected_contents = file_utilities . get_files ( test_dir ) <EOL> sys . stdout . write ( "<STR_LIT>" % ( str ( real_contents ) , ) ) <EOL> sys . stdout . write ( <EOL> "<STR_LIT>" % ( str ( expected_contents ) , ) ) <EOL> assert set ( real_contents ) == set ( expected_contents ) <EOL> @ pytest . mark . parametrize ( "<STR_LIT>" , good_cases ) <EOL> def test_files_sizes ( self , zip_tree , test_case ) : <EOL> """<STR_LIT>""" <EOL> test_dir , zip_file , unzip_dir = zip_tree <EOL> for i in test_case : <EOL> if isinstance ( i , tuple ) : <EOL> sys . stdout . write ( "<STR_LIT>" % ( i [ <NUM_LIT:0> ] , ) ) <EOL> file_size = os . stat ( <EOL> os . path . join ( test_dir , i [ <NUM_LIT:0> ] ) ) . st_size <EOL> assert file_size == i [ <NUM_LIT:1> ] </s>
