<s> """<STR_LIT>""" <EOL> from collections import defaultdict <EOL> from hdfs . client import * <EOL> from hdfs . util import HdfsError , temppath <EOL> from util import _IntegrationTest <EOL> from nose . tools import eq_ , nottest , ok_ , raises <EOL> from requests . exceptions import ConnectTimeout , ReadTimeout <EOL> from shutil import rmtree <EOL> from six import b <EOL> from tempfile import mkdtemp <EOL> import os <EOL> import os . path as osp <EOL> import posixpath as psp <EOL> class TestLoad ( object ) : <EOL> """<STR_LIT>""" <EOL> def test_bare ( self ) : <EOL> client = Client . from_options ( { '<STR_LIT:url>' : '<STR_LIT:foo>' } ) <EOL> ok_ ( isinstance ( client , Client ) ) <EOL> def test_new_type ( self ) : <EOL> class NewClient ( Client ) : <EOL> def __init__ ( self , url , bar ) : <EOL> super ( NewClient , self ) . __init__ ( url ) <EOL> self . bar = bar <EOL> client = Client . from_options ( { '<STR_LIT:url>' : '<STR_LIT:bar>' , '<STR_LIT:bar>' : <NUM_LIT:2> } , '<STR_LIT>' ) <EOL> eq_ ( client . bar , <NUM_LIT:2> ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing_options ( self ) : <EOL> Client . from_options ( { } , '<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_invalid_options ( self ) : <EOL> Client . from_options ( { '<STR_LIT:foo>' : <NUM_LIT> } ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing_type ( self ) : <EOL> Client . from_options ( { } , '<STR_LIT>' ) <EOL> def test_timeout ( self ) : <EOL> eq_ ( Client ( '<STR_LIT>' ) . _timeout , None ) <EOL> eq_ ( Client ( '<STR_LIT>' , timeout = <NUM_LIT:1> ) . _timeout , <NUM_LIT:1> ) <EOL> eq_ ( Client ( '<STR_LIT>' , timeout = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) . _timeout , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> eq_ ( Client . from_options ( { '<STR_LIT:url>' : '<STR_LIT>' } ) . _timeout , None ) <EOL> class TestOptions ( _IntegrationTest ) : <EOL> """<STR_LIT>""" <EOL> def test_timeout ( self ) : <EOL> self . client . _timeout = <NUM_LIT> <EOL> try : <EOL> self . client . status ( '<STR_LIT:.>' ) <EOL> except ( ConnectTimeout , ReadTimeout ) : <EOL> self . client . _timeout = None <EOL> else : <EOL> raise HdfsError ( '<STR_LIT>' ) <EOL> class TestApi ( _IntegrationTest ) : <EOL> """<STR_LIT>""" <EOL> def test_list_status_absolute_root ( self ) : <EOL> ok_ ( self . client . _list_status ( '<STR_LIT:/>' ) ) <EOL> def test_get_folder_status ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> status = self . client . _get_file_status ( '<STR_LIT:foo>' ) . json ( ) [ '<STR_LIT>' ] <EOL> eq_ ( status [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> def test_get_home_directory ( self ) : <EOL> path = self . client . _get_home_directory ( '<STR_LIT:/>' ) . json ( ) [ '<STR_LIT>' ] <EOL> ok_ ( '<STR_LIT>' in path ) <EOL> def test_create_file ( self ) : <EOL> path = '<STR_LIT:foo>' <EOL> self . client . _create ( path , data = '<STR_LIT:hello>' ) <EOL> ok_ ( self . _exists ( path ) ) <EOL> def test_create_nested_file ( self ) : <EOL> path = '<STR_LIT>' <EOL> self . client . _create ( path , data = '<STR_LIT:hello>' ) <EOL> ok_ ( self . _exists ( path ) ) <EOL> def test_delete_file ( self ) : <EOL> path = '<STR_LIT:bar>' <EOL> self . client . _create ( path , data = '<STR_LIT:hello>' ) <EOL> ok_ ( self . client . _delete ( path ) . json ( ) [ '<STR_LIT>' ] ) <EOL> ok_ ( not self . _exists ( path ) ) <EOL> def test_delete_missing_file ( self ) : <EOL> path = '<STR_LIT>' <EOL> ok_ ( not self . client . _delete ( path ) . json ( ) [ '<STR_LIT>' ] ) <EOL> def test_rename_file ( self ) : <EOL> paths = [ '<STR_LIT:foo>' , '<STR_LIT>' % ( self . client . root . rstrip ( '<STR_LIT:/>' ) , ) ] <EOL> self . client . _create ( paths [ <NUM_LIT:0> ] , data = '<STR_LIT:hello>' ) <EOL> ok_ ( self . client . _rename ( paths [ <NUM_LIT:0> ] , destination = paths [ <NUM_LIT:1> ] ) . json ( ) [ '<STR_LIT>' ] ) <EOL> ok_ ( not self . _exists ( paths [ <NUM_LIT:0> ] ) ) <EOL> eq_ ( self . client . _open ( paths [ <NUM_LIT:1> ] . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] ) . content , b'<STR_LIT:hello>' ) <EOL> self . client . _delete ( paths [ <NUM_LIT:1> ] ) <EOL> def test_rename_file_to_existing ( self ) : <EOL> p = [ '<STR_LIT:foo>' , '<STR_LIT>' % ( self . client . root . rstrip ( '<STR_LIT:/>' ) , ) ] <EOL> self . client . _create ( p [ <NUM_LIT:0> ] , data = '<STR_LIT:hello>' ) <EOL> self . client . _create ( p [ <NUM_LIT:1> ] , data = '<STR_LIT>' ) <EOL> try : <EOL> ok_ ( not self . client . _rename ( p [ <NUM_LIT:0> ] , destination = p [ <NUM_LIT:1> ] ) . json ( ) [ '<STR_LIT>' ] ) <EOL> finally : <EOL> self . client . _delete ( p [ <NUM_LIT:0> ] ) <EOL> self . client . _delete ( p [ <NUM_LIT:1> ] ) <EOL> def test_open_file ( self ) : <EOL> self . client . _create ( '<STR_LIT:foo>' , data = '<STR_LIT:hello>' ) <EOL> eq_ ( self . client . _open ( '<STR_LIT:foo>' ) . content , b'<STR_LIT:hello>' ) <EOL> def test_get_file_checksum ( self ) : <EOL> self . client . _create ( '<STR_LIT:foo>' , data = '<STR_LIT:hello>' ) <EOL> data = self . client . _get_file_checksum ( '<STR_LIT:foo>' ) . json ( ) [ '<STR_LIT>' ] <EOL> eq_ ( sorted ( data ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> ok_ ( int ( data [ '<STR_LIT>' ] ) ) <EOL> @ raises ( HdfsError ) <EOL> def test_get_file_checksum_on_folder ( self ) : <EOL> self . client . _get_file_checksum ( '<STR_LIT>' ) <EOL> class TestResolve ( _IntegrationTest ) : <EOL> def test_resolve_relative ( self ) : <EOL> eq_ ( Client ( '<STR_LIT:url>' , root = '<STR_LIT:/>' ) . resolve ( '<STR_LIT:bar>' ) , '<STR_LIT>' ) <EOL> eq_ ( Client ( '<STR_LIT:url>' , root = '<STR_LIT>' ) . resolve ( '<STR_LIT:bar>' ) , '<STR_LIT>' ) <EOL> eq_ ( Client ( '<STR_LIT:url>' , root = '<STR_LIT>' ) . resolve ( '<STR_LIT:bar>' ) , '<STR_LIT>' ) <EOL> eq_ ( Client ( '<STR_LIT:url>' , root = '<STR_LIT>' ) . resolve ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> eq_ ( Client ( '<STR_LIT:url>' , root = '<STR_LIT>' ) . resolve ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_resolve_relative_no_root ( self ) : <EOL> root = self . client . root <EOL> try : <EOL> self . client . root = None <EOL> home = self . client . _get_home_directory ( '<STR_LIT:/>' ) . json ( ) [ '<STR_LIT>' ] <EOL> eq_ ( self . client . resolve ( '<STR_LIT:bar>' ) , psp . join ( home , '<STR_LIT:bar>' ) ) <EOL> eq_ ( self . client . root , home ) <EOL> finally : <EOL> self . client . root = root <EOL> def test_resolve_relative_root ( self ) : <EOL> root = self . client . root <EOL> try : <EOL> self . client . root = '<STR_LIT:bar>' <EOL> home = self . client . _get_home_directory ( '<STR_LIT:/>' ) . json ( ) [ '<STR_LIT>' ] <EOL> eq_ ( self . client . resolve ( '<STR_LIT:foo>' ) , psp . join ( home , '<STR_LIT:bar>' , '<STR_LIT:foo>' ) ) <EOL> eq_ ( self . client . root , psp . join ( home , '<STR_LIT:bar>' ) ) <EOL> finally : <EOL> self . client . root = root <EOL> def test_resolve_absolute ( self ) : <EOL> eq_ ( Client ( '<STR_LIT:url>' ) . resolve ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> eq_ ( Client ( '<STR_LIT:url>' ) . resolve ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_resolve_filename ( self ) : <EOL> path = '<STR_LIT>' <EOL> encoded = self . client . resolve ( path ) <EOL> eq_ ( encoded . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:2> : ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_resolve_filename_with_safe_characters ( self ) : <EOL> path = '<STR_LIT>' <EOL> encoded = self . client . resolve ( path ) <EOL> eq_ ( encoded . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> def test_create_file_with_reserved_characters ( self ) : <EOL> path = '<STR_LIT>' <EOL> self . client . write ( path , data = '<STR_LIT:hello>' ) <EOL> with self . client . read ( path ) as reader : <EOL> eq_ ( reader . read ( ) , b'<STR_LIT:hello>' ) <EOL> def test_create_file_with_percent ( self ) : <EOL> path = '<STR_LIT>' <EOL> try : <EOL> self . client . write ( path , data = '<STR_LIT:hello>' ) <EOL> except HdfsError : <EOL> pass <EOL> with self . client . read ( path ) as reader : <EOL> eq_ ( reader . read ( ) , b'<STR_LIT:hello>' ) <EOL> class TestWrite ( _IntegrationTest ) : <EOL> def test_create_from_string ( self ) : <EOL> self . client . write ( '<STR_LIT>' , u'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_create_from_string_with_encoding ( self ) : <EOL> self . client . write ( '<STR_LIT>' , u'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_create_from_generator ( self ) : <EOL> data = ( e for e in [ b'<STR_LIT>' , b'<STR_LIT>' ] ) <EOL> self . client . write ( '<STR_LIT>' , data ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_create_from_generator_with_encoding ( self ) : <EOL> data = ( e for e in [ u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> self . client . write ( '<STR_LIT>' , data , encoding = '<STR_LIT:utf-8>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_create_from_file_object ( self ) : <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> with open ( tpath ) as reader : <EOL> self . client . write ( '<STR_LIT>' , reader ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_create_set_permission ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , permission = '<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> eq_ ( self . client . status ( '<STR_LIT>' ) [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_create_to_existing_file_without_overwrite ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_create_and_overwrite_file ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , overwrite = True ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_as_context_manager ( self ) : <EOL> with self . client . write ( '<STR_LIT>' ) as writer : <EOL> writer . write ( b'<STR_LIT>' ) <EOL> writer . write ( b'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_as_context_manager_with_encoding ( self ) : <EOL> with self . client . write ( '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as writer : <EOL> writer . write ( u'<STR_LIT>' ) <EOL> writer . write ( u'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> def test_dump_json ( self ) : <EOL> from json import dump , loads <EOL> data = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> with self . client . write ( '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as writer : <EOL> dump ( data , writer ) <EOL> eq_ ( loads ( self . _read ( '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) ) , data ) <EOL> @ raises ( HdfsError ) <EOL> def test_create_and_overwrite_directory ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , b'<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_create_invalid_path ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestAppend ( _IntegrationTest ) : <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> super ( TestAppend , cls ) . setup_class ( ) <EOL> if cls . client : <EOL> try : <EOL> cls . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> cls . client . write ( '<STR_LIT>' , '<STR_LIT>' , append = True ) <EOL> except HdfsError as err : <EOL> if '<STR_LIT>' in str ( err ) : <EOL> cls . client = None <EOL> else : <EOL> raise err <EOL> def test_simple ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , append = True ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing_file ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , append = True ) <EOL> @ raises ( ValueError ) <EOL> def test_overwrite_and_append ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , overwrite = True , append = True ) <EOL> @ raises ( ValueError ) <EOL> def test_set_permission_and_append ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , permission = '<STR_LIT>' , append = True ) <EOL> class TestUpload ( _IntegrationTest ) : <EOL> def test_upload_file ( self ) : <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . upload ( '<STR_LIT>' , tpath ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_upload_missing ( self ) : <EOL> with temppath ( ) as tpath : <EOL> self . client . upload ( '<STR_LIT>' , tpath ) <EOL> @ raises ( HdfsError ) <EOL> def test_upload_empty_directory ( self ) : <EOL> dpath = mkdtemp ( ) <EOL> try : <EOL> self . client . upload ( '<STR_LIT>' , dpath ) <EOL> finally : <EOL> os . rmdir ( dpath ) <EOL> def test_upload_directory_to_existing_directory ( self ) : <EOL> dpath = mkdtemp ( ) <EOL> try : <EOL> npath = osp . join ( dpath , '<STR_LIT>' ) <EOL> os . mkdir ( npath ) <EOL> with open ( osp . join ( npath , '<STR_LIT:foo>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> os . mkdir ( osp . join ( npath , '<STR_LIT:bar>' ) ) <EOL> with open ( osp . join ( npath , '<STR_LIT:bar>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . _mkdirs ( '<STR_LIT>' ) <EOL> self . client . upload ( '<STR_LIT>' , npath ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> finally : <EOL> rmtree ( dpath ) <EOL> def test_upload_directory_to_missing ( self ) : <EOL> dpath = mkdtemp ( ) <EOL> try : <EOL> with open ( osp . join ( dpath , '<STR_LIT:foo>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> os . mkdir ( osp . join ( dpath , '<STR_LIT:bar>' ) ) <EOL> with open ( osp . join ( dpath , '<STR_LIT:bar>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . upload ( '<STR_LIT>' , dpath ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> finally : <EOL> rmtree ( dpath ) <EOL> def test_upload_directory_overwrite_existing_file ( self ) : <EOL> dpath = mkdtemp ( ) <EOL> try : <EOL> with open ( osp . join ( dpath , '<STR_LIT:foo>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> os . mkdir ( osp . join ( dpath , '<STR_LIT:bar>' ) ) <EOL> with open ( osp . join ( dpath , '<STR_LIT:bar>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . upload ( '<STR_LIT>' , dpath , overwrite = True ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> finally : <EOL> rmtree ( dpath ) <EOL> def test_upload_overwrite ( self ) : <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT:hello>' ) <EOL> self . client . upload ( '<STR_LIT>' , tpath ) <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . upload ( '<STR_LIT>' , tpath , overwrite = True ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_upload_overwrite_error ( self ) : <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . upload ( '<STR_LIT>' , tpath ) <EOL> self . client . upload ( '<STR_LIT>' , tpath ) <EOL> def test_upload_cleanup ( self ) : <EOL> dpath = mkdtemp ( ) <EOL> _write = self . client . write <EOL> def write ( hdfs_path , * args , ** kwargs ) : <EOL> if '<STR_LIT:bar>' in hdfs_path : <EOL> raise RuntimeError ( ) <EOL> return _write ( hdfs_path , * args , ** kwargs ) <EOL> try : <EOL> self . client . write = write <EOL> npath = osp . join ( dpath , '<STR_LIT>' ) <EOL> os . mkdir ( npath ) <EOL> with open ( osp . join ( npath , '<STR_LIT:foo>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> os . mkdir ( osp . join ( npath , '<STR_LIT:bar>' ) ) <EOL> with open ( osp . join ( npath , '<STR_LIT:bar>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> try : <EOL> self . client . upload ( '<STR_LIT:foo>' , dpath ) <EOL> except RuntimeError : <EOL> ok_ ( not self . _exists ( '<STR_LIT:foo>' ) ) <EOL> else : <EOL> ok_ ( False ) <EOL> finally : <EOL> rmtree ( dpath ) <EOL> self . client . write = _write <EOL> def test_upload_with_progress ( self ) : <EOL> def callback ( path , nbytes , history = defaultdict ( list ) ) : <EOL> history [ path ] . append ( nbytes ) <EOL> return history <EOL> dpath = mkdtemp ( ) <EOL> try : <EOL> path1 = osp . join ( dpath , '<STR_LIT:foo>' ) <EOL> with open ( path1 , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> os . mkdir ( osp . join ( dpath , '<STR_LIT:bar>' ) ) <EOL> path2 = osp . join ( dpath , '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> with open ( path2 , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . upload ( <EOL> '<STR_LIT>' , <EOL> dpath , <EOL> chunk_size = <NUM_LIT:4> , <EOL> n_threads = <NUM_LIT:1> , <EOL> progress = callback <EOL> ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> eq_ ( <EOL> callback ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> { path1 : [ <NUM_LIT:4> , <NUM_LIT:6> , - <NUM_LIT:1> ] , path2 : [ <NUM_LIT:4> , <NUM_LIT:8> , <NUM_LIT:10> , - <NUM_LIT:1> ] , '<STR_LIT>' : [ <NUM_LIT:0> ] } <EOL> ) <EOL> finally : <EOL> rmtree ( dpath ) <EOL> class TestDelete ( _IntegrationTest ) : <EOL> def test_delete_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> ok_ ( self . client . delete ( '<STR_LIT:foo>' ) ) <EOL> ok_ ( not self . _exists ( '<STR_LIT:foo>' ) ) <EOL> def test_delete_empty_directory ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> ok_ ( self . client . delete ( '<STR_LIT:foo>' ) ) <EOL> ok_ ( not self . _exists ( '<STR_LIT:foo>' ) ) <EOL> def test_delete_missing_file ( self ) : <EOL> ok_ ( not self . client . delete ( '<STR_LIT:foo>' ) ) <EOL> def test_delete_non_empty_directory ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ok_ ( self . client . delete ( '<STR_LIT>' , recursive = True ) ) <EOL> ok_ ( not self . _exists ( '<STR_LIT>' ) ) <EOL> @ raises ( HdfsError ) <EOL> def test_delete_non_empty_directory_without_recursive ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> class TestRead ( _IntegrationTest ) : <EOL> @ raises ( ValueError ) <EOL> def test_progress_without_chunk_size ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , progress = lambda path , nbytes : None ) as reader : <EOL> pass <EOL> @ raises ( ValueError ) <EOL> def test_delimiter_without_encoding ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , delimiter = '<STR_LIT:U+002C>' ) as reader : <EOL> pass <EOL> @ raises ( ValueError ) <EOL> def test_delimiter_with_chunk_size ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , delimiter = '<STR_LIT:U+002C>' , chunk_size = <NUM_LIT:1> ) as reader : <EOL> pass <EOL> def test_read_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' ) as reader : <EOL> eq_ ( reader . read ( ) , b'<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_read_directory ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' ) as reader : <EOL> pass <EOL> @ raises ( HdfsError ) <EOL> def test_read_missing_file ( self ) : <EOL> with self . client . read ( '<STR_LIT:foo>' ) as reader : <EOL> pass <EOL> def test_read_file_from_offset ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , offset = <NUM_LIT:7> ) as reader : <EOL> eq_ ( reader . read ( ) , b'<STR_LIT>' ) <EOL> def test_read_file_from_offset_with_limit ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , offset = <NUM_LIT:7> , length = <NUM_LIT:5> ) as reader : <EOL> eq_ ( reader . read ( ) , b'<STR_LIT>' ) <EOL> def test_read_file_with_chunk_size ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , chunk_size = <NUM_LIT:5> ) as reader : <EOL> eq_ ( list ( reader ) , [ b'<STR_LIT:hello>' , b'<STR_LIT>' , b'<STR_LIT>' ] ) <EOL> def test_with_progress ( self ) : <EOL> def cb ( path , nbytes , chunk_lengths = [ ] ) : <EOL> chunk_lengths . append ( nbytes ) <EOL> return chunk_lengths <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:wb>' ) as writer : <EOL> with self . client . read ( '<STR_LIT:foo>' , chunk_size = <NUM_LIT:5> , progress = cb ) as reader : <EOL> for chunk in reader : <EOL> writer . write ( chunk ) <EOL> with open ( tpath , '<STR_LIT:rb>' ) as reader : <EOL> eq_ ( reader . read ( ) , b'<STR_LIT>' ) <EOL> eq_ ( cb ( '<STR_LIT>' , <NUM_LIT:0> ) , [ <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT> , - <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> def test_read_with_encoding ( self ) : <EOL> s = u'<STR_LIT>' <EOL> self . client . write ( '<STR_LIT:foo>' , s ) <EOL> with self . client . read ( '<STR_LIT:foo>' , encoding = '<STR_LIT:utf-8>' ) as reader : <EOL> eq_ ( reader . read ( ) , s ) <EOL> def test_read_with_chunk_size_and_encoding ( self ) : <EOL> s = u'<STR_LIT>' <EOL> self . client . write ( '<STR_LIT:foo>' , s ) <EOL> with self . client . read ( '<STR_LIT:foo>' , chunk_size = <NUM_LIT:5> , encoding = '<STR_LIT:utf-8>' ) as reader : <EOL> eq_ ( list ( reader ) , [ u'<STR_LIT:hello>' , u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> def test_read_json ( self ) : <EOL> from json import dumps , load <EOL> data = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> self . client . write ( '<STR_LIT:foo>' , data = dumps ( data ) , encoding = '<STR_LIT:utf-8>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , encoding = '<STR_LIT:utf-8>' ) as reader : <EOL> eq_ ( load ( reader ) , data ) <EOL> def test_read_with_delimiter ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , u'<STR_LIT>' ) <EOL> with self . client . read ( '<STR_LIT:foo>' , delimiter = '<STR_LIT:\n>' , encoding = '<STR_LIT:utf-8>' ) as reader : <EOL> eq_ ( list ( reader ) , [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> class TestRename ( _IntegrationTest ) : <EOL> def test_rename_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . rename ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> eq_ ( self . _read ( '<STR_LIT:bar>' ) , b'<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_rename_missing_file ( self ) : <EOL> self . client . rename ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_rename_file_to_existing_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> self . client . rename ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> def test_rename_file_into_existing_directory ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . _mkdirs ( '<STR_LIT:bar>' ) <EOL> self . client . rename ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> eq_ ( self . _read ( '<STR_LIT>' ) , b'<STR_LIT>' ) <EOL> class TestDownload ( _IntegrationTest ) : <EOL> @ raises ( HdfsError ) <EOL> def test_missing_dir ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> self . client . download ( '<STR_LIT>' , osp . join ( tpath , '<STR_LIT:foo>' ) ) <EOL> def test_normal_file ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> fpath = self . client . download ( '<STR_LIT>' , tpath ) <EOL> with open ( fpath ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> def test_nonpartitioned_file ( self ) : <EOL> partname = '<STR_LIT>' <EOL> self . client . write ( '<STR_LIT>' + partname , '<STR_LIT>' ) <EOL> with temppath ( ) as tpath : <EOL> fname = self . client . download ( '<STR_LIT>' + partname , tpath ) <EOL> with open ( fname ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT>' ) <EOL> def test_singly_partitioned_file ( self ) : <EOL> partname = '<STR_LIT>' <EOL> self . client . write ( '<STR_LIT>' + partname , '<STR_LIT>' ) <EOL> with temppath ( ) as tpath : <EOL> os . mkdir ( tpath ) <EOL> fname = self . client . download ( '<STR_LIT>' , tpath ) <EOL> with open ( osp . join ( fname , partname ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT>' ) <EOL> def _download_partitioned_file ( self , n_threads ) : <EOL> parts = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> } <EOL> for name , content in parts . items ( ) : <EOL> self . client . write ( '<STR_LIT>' % ( name , ) , content ) <EOL> with temppath ( ) as tpath : <EOL> self . client . download ( '<STR_LIT>' , tpath , n_threads = - <NUM_LIT:1> ) <EOL> local_parts = os . listdir ( tpath ) <EOL> eq_ ( set ( local_parts ) , set ( parts ) ) <EOL> for part in local_parts : <EOL> with open ( osp . join ( tpath , part ) ) as reader : <EOL> eq_ ( reader . read ( ) , parts [ part ] ) <EOL> def test_partitioned_file_max_threads ( self ) : <EOL> self . _download_partitioned_file ( <NUM_LIT:0> ) <EOL> def test_partitioned_file_sync ( self ) : <EOL> self . _download_partitioned_file ( <NUM_LIT:1> ) <EOL> def test_partitioned_file_setting_n_threads ( self ) : <EOL> self . _download_partitioned_file ( <NUM_LIT:2> ) <EOL> def test_overwrite_file ( self ) : <EOL> with temppath ( ) as tpath : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . download ( '<STR_LIT>' , tpath ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' , overwrite = True ) <EOL> fname = self . client . download ( '<STR_LIT>' , tpath , overwrite = True ) <EOL> with open ( fname ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_download_file_to_existing_file ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . download ( '<STR_LIT>' , tpath ) <EOL> def test_download_file_to_existing_file_with_overwrite ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> with open ( tpath , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . download ( '<STR_LIT>' , tpath , overwrite = True ) <EOL> with open ( tpath ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> def test_download_file_to_existing_folder ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> os . mkdir ( tpath ) <EOL> self . client . download ( '<STR_LIT>' , tpath ) <EOL> with open ( osp . join ( tpath , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_download_file_to_existing_folder_with_matching_file ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> os . mkdir ( tpath ) <EOL> with open ( osp . join ( tpath , '<STR_LIT>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . download ( '<STR_LIT>' , tpath ) <EOL> def test_download_file_to_existing_folder_overwrite_matching_file ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> with temppath ( ) as tpath : <EOL> os . mkdir ( tpath ) <EOL> with open ( osp . join ( tpath , '<STR_LIT>' ) , '<STR_LIT:w>' ) as writer : <EOL> writer . write ( '<STR_LIT>' ) <EOL> self . client . download ( '<STR_LIT>' , tpath , overwrite = True ) <EOL> with open ( osp . join ( tpath , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> def test_download_folder_to_existing_folder ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with temppath ( ) as tpath : <EOL> os . mkdir ( tpath ) <EOL> self . client . download ( '<STR_LIT:foo>' , tpath ) <EOL> with open ( osp . join ( tpath , '<STR_LIT:foo>' , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> with open ( osp . join ( tpath , '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT>' ) <EOL> def test_download_folder_to_existing_folder_parallel ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with temppath ( ) as tpath : <EOL> os . mkdir ( tpath ) <EOL> self . client . download ( '<STR_LIT:foo>' , tpath , n_threads = <NUM_LIT:0> ) <EOL> with open ( osp . join ( tpath , '<STR_LIT:foo>' , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> with open ( osp . join ( tpath , '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT>' ) <EOL> def test_download_folder_to_missing_folder ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with temppath ( ) as tpath : <EOL> self . client . download ( '<STR_LIT:foo>' , tpath ) <EOL> with open ( osp . join ( tpath , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT:hello>' ) <EOL> with open ( osp . join ( tpath , '<STR_LIT:bar>' , '<STR_LIT>' ) ) as reader : <EOL> eq_ ( reader . read ( ) , '<STR_LIT>' ) <EOL> def test_download_cleanup ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _read = self . client . read <EOL> def read ( hdfs_path , * args , ** kwargs ) : <EOL> if '<STR_LIT:bar>' in hdfs_path : <EOL> raise RuntimeError ( ) <EOL> return _read ( hdfs_path , * args , ** kwargs ) <EOL> with temppath ( ) as tpath : <EOL> try : <EOL> self . client . read = read <EOL> self . client . download ( '<STR_LIT:foo>' , tpath ) <EOL> except RuntimeError : <EOL> ok_ ( not osp . exists ( tpath ) ) <EOL> else : <EOL> ok_ ( False ) <EOL> finally : <EOL> self . client . read = _read <EOL> @ raises ( HdfsError ) <EOL> def test_download_empty_folder ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> with temppath ( ) as tpath : <EOL> self . client . download ( '<STR_LIT:foo>' , tpath ) <EOL> class TestStatus ( _IntegrationTest ) : <EOL> def test_directory ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . status ( '<STR_LIT:foo>' ) <EOL> def test_missing_non_strict ( self ) : <EOL> ok_ ( self . client . status ( '<STR_LIT:foo>' , strict = False ) is None ) <EOL> class TestSetOwner ( _IntegrationTest ) : <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> super ( TestSetOwner , cls ) . setup_class ( ) <EOL> if cls . client : <EOL> try : <EOL> cls . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> cls . client . set_owner ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> except HdfsError as err : <EOL> if '<STR_LIT>' in str ( err ) : <EOL> cls . client = None <EOL> else : <EOL> raise err <EOL> def test_directory_owner ( self ) : <EOL> new_owner = '<STR_LIT>' <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , new_owner ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , new_owner ) <EOL> def test_file_owner ( self ) : <EOL> new_owner = '<STR_LIT>' <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , new_owner ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , new_owner ) <EOL> def test_directory_for_group ( self ) : <EOL> new_group = '<STR_LIT>' <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , group = '<STR_LIT>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , group = new_group ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , new_group ) <EOL> def test_file_for_group ( self ) : <EOL> new_group = '<STR_LIT>' <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , group = '<STR_LIT>' ) <EOL> self . client . set_owner ( '<STR_LIT:foo>' , group = new_group ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , new_group ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing_for_group ( self ) : <EOL> self . client . set_owner ( '<STR_LIT:foo>' , group = '<STR_LIT>' ) <EOL> class TestSetPermission ( _IntegrationTest ) : <EOL> def test_directory ( self ) : <EOL> new_permission = '<STR_LIT>' <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' , permission = '<STR_LIT>' ) <EOL> self . client . set_permission ( '<STR_LIT:foo>' , new_permission ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , new_permission ) <EOL> def test_file ( self ) : <EOL> new_permission = '<STR_LIT>' <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' , permission = '<STR_LIT>' ) <EOL> self . client . set_permission ( '<STR_LIT:foo>' , new_permission ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , new_permission ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . set_permission ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> class TestContent ( _IntegrationTest ) : <EOL> def test_directory ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> content = self . client . content ( '<STR_LIT>' ) <EOL> eq_ ( content [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> eq_ ( content [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> eq_ ( content [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> content = self . client . content ( '<STR_LIT:foo>' ) <EOL> eq_ ( content [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> eq_ ( content [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> eq_ ( content [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . content ( '<STR_LIT:foo>' ) <EOL> def test_missing_non_strict ( self ) : <EOL> ok_ ( self . client . content ( '<STR_LIT:foo>' , strict = False ) is None ) <EOL> class TestList ( _IntegrationTest ) : <EOL> @ raises ( HdfsError ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . client . list ( '<STR_LIT:foo>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . list ( '<STR_LIT:foo>' ) <EOL> def test_empty_dir ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> eq_ ( self . client . list ( '<STR_LIT:foo>' ) , [ ] ) <EOL> def test_dir ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> eq_ ( self . client . list ( '<STR_LIT:foo>' ) , [ '<STR_LIT:bar>' ] ) <EOL> def test_dir_with_status ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> statuses = self . client . list ( '<STR_LIT:foo>' , status = True ) <EOL> eq_ ( len ( statuses ) , <NUM_LIT:1> ) <EOL> status = self . client . status ( '<STR_LIT>' ) <EOL> status [ '<STR_LIT>' ] = '<STR_LIT:bar>' <EOL> eq_ ( statuses [ <NUM_LIT:0> ] , ( '<STR_LIT:bar>' , status ) ) <EOL> class TestWalk ( _IntegrationTest ) : <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> list ( self . client . walk ( '<STR_LIT:foo>' ) ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> ok_ ( not list ( self . client . walk ( '<STR_LIT:foo>' ) ) ) <EOL> def test_folder ( self ) : <EOL> self . client . write ( '<STR_LIT:hello>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> infos = list ( self . client . walk ( '<STR_LIT>' ) ) <EOL> eq_ ( len ( infos ) , <NUM_LIT:2> ) <EOL> eq_ ( infos [ <NUM_LIT:0> ] , ( psp . join ( self . client . root ) , [ '<STR_LIT:foo>' ] , [ '<STR_LIT:hello>' ] ) ) <EOL> eq_ ( infos [ <NUM_LIT:1> ] , ( psp . join ( self . client . root , '<STR_LIT:foo>' ) , [ ] , [ '<STR_LIT>' ] ) ) <EOL> def test_folder_with_depth ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> infos = list ( self . client . walk ( '<STR_LIT>' , depth = <NUM_LIT:1> ) ) <EOL> eq_ ( len ( infos ) , <NUM_LIT:1> ) <EOL> eq_ ( infos [ <NUM_LIT:0> ] , ( self . client . root , [ '<STR_LIT:foo>' ] , [ ] ) ) <EOL> def test_folder_with_status ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> infos = list ( self . client . walk ( '<STR_LIT>' , status = True ) ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> status [ '<STR_LIT>' ] = '<STR_LIT:foo>' <EOL> eq_ ( len ( infos ) , <NUM_LIT:1> ) <EOL> eq_ ( <EOL> infos [ <NUM_LIT:0> ] , <EOL> ( <EOL> ( self . client . root , self . client . status ( '<STR_LIT>' ) ) , <EOL> [ ] , <EOL> [ ( '<STR_LIT:foo>' , status ) ] <EOL> ) <EOL> ) <EOL> class TestLatestExpansion ( _IntegrationTest ) : <EOL> def test_resolve_simple ( self ) : <EOL> self . client . write ( '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> eq_ ( self . client . resolve ( '<STR_LIT>' ) , osp . join ( self . client . root , '<STR_LIT:foo>' ) ) <EOL> def test_resolve_nested ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> latest = self . client . resolve ( '<STR_LIT>' ) <EOL> eq_ ( latest , osp . join ( self . client . root , '<STR_LIT:bar>' , '<STR_LIT:foo>' ) ) <EOL> def test_resolve_multiple ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> latest = self . client . resolve ( '<STR_LIT>' ) <EOL> eq_ ( latest , osp . join ( self . client . root , '<STR_LIT:bar>' , '<STR_LIT:foo>' ) ) <EOL> def test_resolve_multiple_shortcut ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> latest = self . client . resolve ( '<STR_LIT>' ) <EOL> eq_ ( latest , osp . join ( self . client . root , '<STR_LIT:bar>' , '<STR_LIT:foo>' ) ) <EOL> @ nottest <EOL> @ raises ( HdfsError ) <EOL> def test_resolve_file ( self ) : <EOL> self . client . write ( '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> self . client . resolve ( '<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_resolve_empty_directory ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:bar>' ) <EOL> self . client . resolve ( '<STR_LIT>' ) <EOL> class TestParts ( _IntegrationTest ) : <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . parts ( '<STR_LIT:foo>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> self . client . parts ( '<STR_LIT:foo>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_empty_folder ( self ) : <EOL> self . client . _mkdirs ( '<STR_LIT:foo>' ) <EOL> self . client . parts ( '<STR_LIT:foo>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_folder_without_parts ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . parts ( '<STR_LIT:foo>' ) <EOL> def test_folder_with_single_part ( self ) : <EOL> fname = '<STR_LIT>' <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fname ) , '<STR_LIT>' ) <EOL> eq_ ( self . client . parts ( '<STR_LIT:foo>' ) , [ fname ] ) <EOL> def test_folder_with_multiple_parts ( self ) : <EOL> fnames = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) <EOL> eq_ ( self . client . parts ( '<STR_LIT:foo>' ) , fnames ) <EOL> def test_folder_with_multiple_parts_and_others ( self ) : <EOL> fnames = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) <EOL> eq_ ( self . client . parts ( '<STR_LIT:foo>' ) , fnames ) <EOL> def test_with_selection ( self ) : <EOL> fnames = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) <EOL> parts = self . client . parts ( '<STR_LIT:foo>' , parts = <NUM_LIT:1> ) <EOL> eq_ ( len ( parts ) , <NUM_LIT:1> ) <EOL> ok_ ( parts [ <NUM_LIT:0> ] in fnames ) <EOL> def test_with_selection ( self ) : <EOL> fnames = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) <EOL> self . client . write ( psp . join ( '<STR_LIT:foo>' , fnames [ <NUM_LIT:1> ] ) , '<STR_LIT>' ) <EOL> eq_ ( self . client . parts ( '<STR_LIT:foo>' , parts = [ <NUM_LIT:1> ] ) , fnames [ <NUM_LIT:1> : ] ) <EOL> def test_with_status ( self ) : <EOL> fname = '<STR_LIT>' <EOL> fpath = psp . join ( '<STR_LIT:foo>' , fname ) <EOL> self . client . write ( fpath , '<STR_LIT>' ) <EOL> status = self . client . status ( fpath ) <EOL> status [ '<STR_LIT>' ] = fname <EOL> eq_ ( self . client . parts ( '<STR_LIT:foo>' , status = True ) , [ ( fname , status ) ] ) <EOL> class TestMakeDirs ( _IntegrationTest ) : <EOL> def test_simple ( self ) : <EOL> self . client . makedirs ( '<STR_LIT:foo>' ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> def test_nested ( self ) : <EOL> self . client . makedirs ( '<STR_LIT>' ) <EOL> eq_ ( self . client . status ( '<STR_LIT>' ) [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> def test_with_permission ( self ) : <EOL> self . client . makedirs ( '<STR_LIT:foo>' , permission = '<STR_LIT>' ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_overwrite_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> self . client . makedirs ( '<STR_LIT:foo>' ) <EOL> def test_overwrite_directory_with_permission ( self ) : <EOL> self . client . makedirs ( '<STR_LIT:foo>' , permission = '<STR_LIT>' ) <EOL> self . client . makedirs ( '<STR_LIT>' , permission = '<STR_LIT>' ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> eq_ ( self . client . status ( '<STR_LIT>' ) [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class TestSetTimes ( _IntegrationTest ) : <EOL> @ raises ( ValueError ) <EOL> def test_none ( self ) : <EOL> self . client . makedirs ( '<STR_LIT:foo>' ) <EOL> self . client . set_times ( '<STR_LIT:foo>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . set_times ( '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> @ nottest <EOL> @ raises ( HdfsError ) <EOL> def test_negative ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , access_time = - <NUM_LIT> ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , access_time = <NUM_LIT> ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , modification_time = <NUM_LIT> ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , access_time = <NUM_LIT:1> , modification_time = <NUM_LIT:2> ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> eq_ ( status [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> def test_folder ( self ) : <EOL> self . client . write ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , access_time = <NUM_LIT> ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , modification_time = <NUM_LIT> ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . client . set_times ( '<STR_LIT:foo>' , access_time = <NUM_LIT:1> , modification_time = <NUM_LIT:2> ) <EOL> status = self . client . status ( '<STR_LIT:foo>' ) <EOL> eq_ ( status [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> eq_ ( status [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> class TestChecksum ( _IntegrationTest ) : <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . checksum ( '<STR_LIT:foo>' ) <EOL> @ raises ( HdfsError ) <EOL> def test_folder ( self ) : <EOL> self . client . makedirs ( '<STR_LIT:foo>' ) <EOL> self . client . checksum ( '<STR_LIT:foo>' ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> checksum = self . client . checksum ( '<STR_LIT:foo>' ) <EOL> eq_ ( set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , set ( checksum ) ) <EOL> class TestSetReplication ( _IntegrationTest ) : <EOL> @ raises ( HdfsError ) <EOL> def test_missing ( self ) : <EOL> self . client . set_replication ( '<STR_LIT:foo>' , <NUM_LIT:1> ) <EOL> @ raises ( HdfsError ) <EOL> def test_folder ( self ) : <EOL> self . client . makedirs ( '<STR_LIT:foo>' ) <EOL> self . client . set_replication ( '<STR_LIT:foo>' , <NUM_LIT:1> ) <EOL> @ raises ( HdfsError ) <EOL> def test_invalid_replication ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> self . client . set_replication ( '<STR_LIT:foo>' , <NUM_LIT:0> ) <EOL> def test_file ( self ) : <EOL> self . client . write ( '<STR_LIT:foo>' , '<STR_LIT:hello>' ) <EOL> replication = self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] + <NUM_LIT:1> <EOL> self . client . set_replication ( '<STR_LIT:foo>' , replication ) <EOL> eq_ ( self . client . status ( '<STR_LIT:foo>' ) [ '<STR_LIT>' ] , replication ) <EOL> class TestTokenClient ( object ) : <EOL> def test_without_session ( self ) : <EOL> client = TokenClient ( '<STR_LIT:url>' , '<STR_LIT>' ) <EOL> eq_ ( client . _session . params [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_with_session ( self ) : <EOL> session = rq . Session ( ) <EOL> client = TokenClient ( '<STR_LIT:url>' , '<STR_LIT>' , session = session ) <EOL> eq_ ( session . params [ '<STR_LIT>' ] , '<STR_LIT>' ) </s>
