<s> """<STR_LIT>""" <EOL> from hdfs import InsecureClient <EOL> from hdfs . config import Config <EOL> from hdfs . util import HdfsError <EOL> from nose . plugins . skip import SkipTest <EOL> from nose . tools import eq_ <EOL> from requests . exceptions import ConnectionError <EOL> from six . moves . configparser import NoOptionError , NoSectionError <EOL> from time import sleep <EOL> import os <EOL> import posixpath as psp <EOL> def save_config ( config , path = None ) : <EOL> """<STR_LIT>""" <EOL> with open ( path or config . path , '<STR_LIT:w>' ) as writer : <EOL> config . write ( writer ) <EOL> class _IntegrationTest ( object ) : <EOL> """<STR_LIT>""" <EOL> client = None <EOL> delay = <NUM_LIT:0.5> <EOL> root_suffix = '<STR_LIT>' <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> alias = os . getenv ( '<STR_LIT>' ) <EOL> url = os . getenv ( '<STR_LIT>' ) <EOL> if alias : <EOL> cls . client = Config ( ) . get_client ( alias ) <EOL> if cls . client . root : <EOL> cls . client . root = psp . join ( cls . client . root , cls . root_suffix ) <EOL> else : <EOL> cls . client . root = cls . root_suffix <EOL> elif url : <EOL> cls . client = InsecureClient ( url , root = cls . root_suffix ) <EOL> @ classmethod <EOL> def teardown_class ( cls ) : <EOL> if cls . client : <EOL> cls . client . delete ( '<STR_LIT>' , recursive = True ) <EOL> def setup ( self ) : <EOL> if not self . client : <EOL> raise SkipTest <EOL> else : <EOL> try : <EOL> self . client . delete ( '<STR_LIT>' , recursive = True ) <EOL> except ConnectionError : <EOL> self . client . delete ( '<STR_LIT>' , recursive = True ) <EOL> finally : <EOL> sleep ( self . delay ) <EOL> def _read ( self , hdfs_path , encoding = None ) : <EOL> with self . client . read ( hdfs_path , encoding = encoding ) as reader : <EOL> return reader . read ( ) <EOL> def _exists ( self , hdfs_path ) : <EOL> return bool ( self . client . status ( hdfs_path , strict = False ) ) </s>
