<s> import os <EOL> import shutil <EOL> from minicluster_testbase import MiniClusterTestBase <EOL> TESTFILES_PATH = os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , "<STR_LIT>" ) <EOL> class CopyToLocalTest ( MiniClusterTestBase ) : <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( TESTFILES_PATH ) <EOL> def test_copyToLocal_file_content ( self ) : <EOL> os . mkdir ( TESTFILES_PATH ) <EOL> target_dir = "<STR_LIT>" % TESTFILES_PATH <EOL> expected_content = self . cluster . cat ( '<STR_LIT>' ) <EOL> for result in self . client . copyToLocal ( [ '<STR_LIT>' ] , target_dir ) : <EOL> self . assertEqual ( result [ '<STR_LIT:path>' ] , target_dir ) <EOL> client_content = self . _read_file ( target_dir ) <EOL> self . assertEqual ( client_content , expected_content ) <EOL> self . assertEqual ( result [ '<STR_LIT:result>' ] , True ) <EOL> def test_copyToLocal_conflicting_names ( self ) : <EOL> os . mkdir ( TESTFILES_PATH ) <EOL> target_dir = "<STR_LIT>" % TESTFILES_PATH <EOL> self . cluster . copyToLocal ( '<STR_LIT>' , target_dir ) <EOL> for result in self . client . copyToLocal ( [ '<STR_LIT>' ] , target_dir ) : <EOL> self . assertEqual ( result [ '<STR_LIT:error>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( result [ '<STR_LIT:path>' ] , target_dir ) <EOL> self . assertEqual ( result [ '<STR_LIT:result>' ] , False ) <EOL> def test_copyToLocal_directory_structure ( self ) : <EOL> test_dir = '<STR_LIT>' % TESTFILES_PATH <EOL> expected_dir = '<STR_LIT>' % TESTFILES_PATH <EOL> os . mkdir ( TESTFILES_PATH ) <EOL> os . mkdir ( expected_dir ) <EOL> os . mkdir ( test_dir ) <EOL> expected_dir_structure = [ ] <EOL> test_dir_structure = [ ] <EOL> self . cluster . copyToLocal ( '<STR_LIT>' , expected_dir ) <EOL> for result in self . client . copyToLocal ( [ '<STR_LIT>' ] , test_dir ) : <EOL> self . assertEqual ( result [ '<STR_LIT:result>' ] , True ) <EOL> for path , dirs , files in os . walk ( expected_dir ) : <EOL> expected_dir_structure . append ( path . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> for f in files : <EOL> f = "<STR_LIT>" % ( path , f ) <EOL> data = self . _read_file ( f ) <EOL> expected_dir_structure . append ( ( f . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) , data ) ) <EOL> for path , dirs , files in os . walk ( test_dir ) : <EOL> test_dir_structure . append ( path . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> for f in files : <EOL> f = "<STR_LIT>" % ( path , f ) <EOL> data = self . _read_file ( f ) <EOL> test_dir_structure . append ( ( f . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) , data ) ) <EOL> self . assertEqual ( expected_dir_structure , test_dir_structure ) <EOL> def test_copyToLocal_relative_directory_structure ( self ) : <EOL> test_dir = '<STR_LIT>' % TESTFILES_PATH <EOL> test_dir = os . path . relpath ( test_dir ) <EOL> expected_dir = '<STR_LIT>' % TESTFILES_PATH <EOL> os . mkdir ( TESTFILES_PATH ) <EOL> os . mkdir ( expected_dir ) <EOL> os . mkdir ( test_dir ) <EOL> expected_dir_structure = [ ] <EOL> test_dir_structure = [ ] <EOL> self . cluster . copyToLocal ( '<STR_LIT>' , expected_dir ) <EOL> for result in self . client . copyToLocal ( [ '<STR_LIT>' ] , test_dir ) : <EOL> self . assertEqual ( result [ '<STR_LIT:result>' ] , True ) <EOL> for path , dirs , files in os . walk ( expected_dir ) : <EOL> expected_dir_structure . append ( path . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> for f in files : <EOL> f = "<STR_LIT>" % ( path , f ) <EOL> data = self . _read_file ( f ) <EOL> expected_dir_structure . append ( ( f . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) , data ) ) <EOL> for path , dirs , files in os . walk ( os . path . abspath ( test_dir ) ) : <EOL> test_dir_structure . append ( path . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> for f in files : <EOL> f = "<STR_LIT>" % ( path , f ) <EOL> data = self . _read_file ( f ) <EOL> test_dir_structure . append ( ( f . replace ( '<STR_LIT>' , "<STR_LIT>" , <NUM_LIT:1> ) , data ) ) <EOL> self . assertEqual ( expected_dir_structure , test_dir_structure ) <EOL> def _read_file ( self , file ) : <EOL> f = open ( file , '<STR_LIT:r>' ) <EOL> data = f . read ( ) <EOL> f . close ( ) <EOL> return data </s>
