<s> from minicluster import MiniClusterTestCase <EOL> import unittest <EOL> import subprocess <EOL> import select <EOL> import re <EOL> try : <EOL> from snakebite . minicluster import MiniCluster <EOL> except ImportError : <EOL> raise unittest . SkipTest ( '<STR_LIT>' ) <EOL> class WebHdfsMiniCluster ( MiniCluster ) : <EOL> '''<STR_LIT>''' <EOL> @ property <EOL> def webhdfs_port ( self ) : <EOL> return self . port <EOL> def _start_mini_cluster ( self , nnport = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _jobclient_jar : <EOL> hadoop_jar = self . _jobclient_jar <EOL> else : <EOL> hadoop_jar = self . _find_mini_cluster_jar ( self . _hadoop_home ) <EOL> if not hadoop_jar : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> cmd = [ self . _hadoop_cmd , '<STR_LIT>' , hadoop_jar , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if nnport : <EOL> cmd . extend ( [ '<STR_LIT>' , "<STR_LIT:%s>" % nnport ] ) <EOL> if True : <EOL> cmd . extend ( [ '<STR_LIT>' ] ) <EOL> self . hdfs = subprocess . Popen ( cmd , bufsize = <NUM_LIT:0> , stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , universal_newlines = True ) <EOL> def _get_namenode_port ( self ) : <EOL> just_seen_webhdfs = False <EOL> while self . hdfs . poll ( ) is None : <EOL> rlist , wlist , xlist = select . select ( [ self . hdfs . stderr , self . hdfs . stdout ] , [ ] , [ ] ) <EOL> for f in rlist : <EOL> line = f . readline ( ) <EOL> print ( line . rstrip ( ) ) <EOL> m = re . match ( "<STR_LIT>" , line ) <EOL> if just_seen_webhdfs and m : <EOL> return int ( m . group ( <NUM_LIT:1> ) ) <EOL> just_seen_webhdfs = re . match ( "<STR_LIT>" , line ) <EOL> class WebHdfsMiniClusterTestCase ( MiniClusterTestCase ) : <EOL> @ classmethod <EOL> def instantiate_cluster ( cls ) : <EOL> return WebHdfsMiniCluster ( None , nnport = <NUM_LIT> ) </s>
