<s> """<STR_LIT>""" <EOL> import os <EOL> from gslib . exception import CommandException <EOL> import gslib . tests . testcase as testcase <EOL> class TestHash ( testcase . GsUtilUnitTestCase ) : <EOL> """<STR_LIT>""" <EOL> _TEST_FILE_CONTENTS = '<STR_LIT>' <EOL> _TEST_FILE_B64_CRC = '<STR_LIT>' <EOL> _TEST_FILE_B64_MD5 = '<STR_LIT>' <EOL> _TEST_FILE_HEX_CRC = '<STR_LIT>' <EOL> _TEST_FILE_HEX_MD5 = '<STR_LIT>' <EOL> def testHashContents ( self ) : <EOL> tmp_file = self . CreateTempFile ( contents = self . _TEST_FILE_CONTENTS ) <EOL> stdout = self . RunCommand ( '<STR_LIT>' , args = [ tmp_file ] , return_stdout = True ) <EOL> self . assertIn ( '<STR_LIT>' , stdout ) <EOL> self . assertIn ( '<STR_LIT>' % self . _TEST_FILE_B64_CRC , stdout ) <EOL> self . assertIn ( '<STR_LIT>' % self . _TEST_FILE_B64_MD5 , stdout ) <EOL> def testHashNoMatch ( self ) : <EOL> try : <EOL> self . RunCommand ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CommandException , e : <EOL> self . assertIn ( '<STR_LIT>' , e . reason ) <EOL> def testHashCloudObject ( self ) : <EOL> try : <EOL> self . RunCommand ( '<STR_LIT>' , args = [ '<STR_LIT>' ] ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except CommandException , e : <EOL> self . assertEquals ( '<STR_LIT>' , e . reason ) <EOL> def testHashHexFormat ( self ) : <EOL> tmp_file = self . CreateTempFile ( contents = self . _TEST_FILE_CONTENTS ) <EOL> stdout = self . RunCommand ( '<STR_LIT>' , args = [ '<STR_LIT>' , tmp_file ] , return_stdout = True ) <EOL> self . assertIn ( '<STR_LIT>' , stdout ) <EOL> self . assertIn ( '<STR_LIT>' % self . _TEST_FILE_HEX_CRC , stdout ) <EOL> self . assertIn ( '<STR_LIT>' % self . _TEST_FILE_HEX_MD5 , stdout ) <EOL> def testHashWildcard ( self ) : <EOL> num_test_files = <NUM_LIT:2> <EOL> tmp_dir = self . CreateTempDir ( test_files = num_test_files ) <EOL> stdout = self . RunCommand ( '<STR_LIT>' , args = [ os . path . join ( tmp_dir , '<STR_LIT:*>' ) ] , <EOL> return_stdout = True ) <EOL> num_expected_lines = num_test_files * ( <NUM_LIT:1> + <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( stdout . splitlines ( ) ) , num_expected_lines ) <EOL> def testHashSelectAlg ( self ) : <EOL> tmp_file = self . CreateTempFile ( contents = self . _TEST_FILE_CONTENTS ) <EOL> stdout_crc = self . RunCommand ( '<STR_LIT>' , args = [ '<STR_LIT:-c>' , tmp_file ] , <EOL> return_stdout = True ) <EOL> stdout_md5 = self . RunCommand ( '<STR_LIT>' , args = [ '<STR_LIT>' , tmp_file ] , <EOL> return_stdout = True ) <EOL> stdout_both = self . RunCommand ( '<STR_LIT>' , args = [ '<STR_LIT:-c>' , '<STR_LIT>' , tmp_file ] , <EOL> return_stdout = True ) <EOL> for stdout in ( stdout_crc , stdout_both ) : <EOL> self . assertIn ( '<STR_LIT>' % self . _TEST_FILE_B64_CRC , stdout ) <EOL> for stdout in ( stdout_md5 , stdout_both ) : <EOL> self . assertIn ( '<STR_LIT>' % self . _TEST_FILE_B64_MD5 , stdout ) <EOL> self . assertNotIn ( '<STR_LIT>' , stdout_crc ) <EOL> self . assertNotIn ( '<STR_LIT>' , stdout_md5 ) </s>
