<s> import bz2 <EOL> import gzip <EOL> import os <EOL> from os . path import join <EOL> from mrjob . fs . local import LocalFilesystem <EOL> from tests . sandbox import SandboxedTestCase <EOL> class LocalFSTestCase ( SandboxedTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( LocalFSTestCase , self ) . setUp ( ) <EOL> self . fs = LocalFilesystem ( ) <EOL> def test_can_handle_local_paths ( self ) : <EOL> self . assertEqual ( self . fs . can_handle_path ( '<STR_LIT>' ) , True ) <EOL> self . assertEqual ( self . fs . can_handle_path ( '<STR_LIT>' ) , True ) <EOL> def test_cant_handle_uris ( self ) : <EOL> self . assertEqual ( self . fs . can_handle_path ( '<STR_LIT>' ) , False ) <EOL> def test_du ( self ) : <EOL> data_path_1 = self . makefile ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data_path_2 = self . makefile ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . fs . du ( self . tmp_dir ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( self . fs . du ( data_path_1 ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( self . fs . du ( data_path_2 ) , <NUM_LIT:4> ) <EOL> def test_ls_empty ( self ) : <EOL> self . assertEqual ( list ( self . fs . ls ( self . tmp_dir ) ) , [ ] ) <EOL> def test_ls_basic ( self ) : <EOL> self . makefile ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> self . assertEqual ( sorted ( self . fs . ls ( self . tmp_dir ) ) , <EOL> sorted ( self . abs_paths ( '<STR_LIT:f>' ) ) ) <EOL> def test_ls_basic_2 ( self ) : <EOL> self . makefile ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> self . makefile ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( sorted ( self . fs . ls ( self . tmp_dir ) ) , <EOL> sorted ( self . abs_paths ( '<STR_LIT:f>' , '<STR_LIT>' ) ) ) <EOL> def test_ls_recurse ( self ) : <EOL> self . makefile ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> self . makefile ( join ( '<STR_LIT:d>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( sorted ( list ( self . fs . ls ( self . tmp_dir ) ) ) , <EOL> sorted ( self . abs_paths ( '<STR_LIT:f>' , '<STR_LIT>' ) ) ) <EOL> def test_cat_uncompressed ( self ) : <EOL> path = self . makefile ( '<STR_LIT:f>' , b'<STR_LIT>' ) <EOL> self . assertEqual ( list ( self . fs . _cat_file ( path ) ) , [ b'<STR_LIT>' , b'<STR_LIT>' ] ) <EOL> def test_cat_gz ( self ) : <EOL> input_gz_path = join ( self . tmp_dir , '<STR_LIT>' ) <EOL> input_gz = gzip . GzipFile ( input_gz_path , '<STR_LIT:wb>' ) <EOL> input_gz . write ( b'<STR_LIT>' ) <EOL> input_gz . close ( ) <EOL> self . assertEqual ( list ( self . fs . _cat_file ( input_gz_path ) ) , <EOL> [ b'<STR_LIT>' , b'<STR_LIT>' ] ) <EOL> def test_cat_bz2 ( self ) : <EOL> input_bz2_path = join ( self . tmp_dir , '<STR_LIT>' ) <EOL> input_bz2 = bz2 . BZ2File ( input_bz2_path , '<STR_LIT:wb>' ) <EOL> input_bz2 . write ( b'<STR_LIT>' ) <EOL> input_bz2 . close ( ) <EOL> self . assertEqual ( list ( self . fs . _cat_file ( input_bz2_path ) ) , <EOL> [ b'<STR_LIT>' , b'<STR_LIT>' , b'<STR_LIT>' ] ) <EOL> def test_mkdir ( self ) : <EOL> path = join ( self . tmp_dir , '<STR_LIT>' ) <EOL> self . fs . mkdir ( path ) <EOL> self . assertEqual ( os . path . isdir ( path ) , True ) <EOL> def test_exists_no ( self ) : <EOL> path = join ( self . tmp_dir , '<STR_LIT:f>' ) <EOL> self . assertEqual ( self . fs . exists ( path ) , False ) <EOL> def test_exists_yes ( self ) : <EOL> path = self . makefile ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . fs . exists ( path ) , True ) <EOL> def test_rm_file ( self ) : <EOL> path = self . makefile ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . fs . exists ( path ) , True ) <EOL> self . fs . rm ( path ) <EOL> self . assertEqual ( self . fs . exists ( path ) , False ) <EOL> def test_rm_dir ( self ) : <EOL> path = self . makedirs ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . fs . exists ( path ) , True ) <EOL> self . fs . rm ( path ) <EOL> self . assertEqual ( self . fs . exists ( path ) , False ) <EOL> def test_touchz ( self ) : <EOL> path = join ( self . tmp_dir , '<STR_LIT:f>' ) <EOL> self . fs . touchz ( path ) <EOL> self . fs . touchz ( path ) <EOL> with open ( path , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> self . assertRaises ( OSError , self . fs . touchz , path ) <EOL> def test_md5sum ( self ) : <EOL> path = self . makefile ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . fs . md5sum ( path ) , <EOL> '<STR_LIT>' ) </s>
