<s> import unittest2 <EOL> import inspect <EOL> import errno <EOL> import socket <EOL> from mock import patch , Mock <EOL> from snakebite . client import HAClient , AutoConfigClient , Client <EOL> from snakebite . config import HDFSConfig <EOL> from snakebite . namenode import Namenode <EOL> from snakebite . errors import OutOfNNException , RequestError , InvalidInputException <EOL> class ClientTest ( unittest2 . TestCase ) : <EOL> original_hdfs_try_path = HDFSConfig . hdfs_try_paths <EOL> original_core_try_path = HDFSConfig . core_try_paths <EOL> def setUp ( self ) : <EOL> HDFSConfig . use_trash = False <EOL> HDFSConfig . hdfs_try_paths = self . original_hdfs_try_path <EOL> HDFSConfig . core_try_paths = self . original_core_try_path <EOL> def test_ha_client_econnrefused_socket_error ( self ) : <EOL> e = socket . error <EOL> e . errno = errno . ECONNREFUSED <EOL> mocked_client_cat = Mock ( side_effect = e ) <EOL> ha_client = HAClient ( [ Namenode ( "<STR_LIT:foo>" ) , Namenode ( "<STR_LIT:bar>" ) ] ) <EOL> ha_client . cat = HAClient . _ha_gen_method ( mocked_client_cat ) <EOL> cat_result_gen = ha_client . cat ( ha_client , [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( OutOfNNException , all , cat_result_gen ) <EOL> def test_ha_client_ehostunreach_socket_error ( self ) : <EOL> e = socket . error <EOL> e . errno = errno . EHOSTUNREACH <EOL> mocked_client_cat = Mock ( side_effect = e ) <EOL> ha_client = HAClient ( [ Namenode ( "<STR_LIT:foo>" ) , Namenode ( "<STR_LIT:bar>" ) ] ) <EOL> ha_client . cat = HAClient . _ha_gen_method ( mocked_client_cat ) <EOL> cat_result_gen = ha_client . cat ( ha_client , [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( OutOfNNException , all , cat_result_gen ) <EOL> def test_ha_client_socket_timeout ( self ) : <EOL> e = socket . timeout <EOL> mocked_client_cat = Mock ( side_effect = e ) <EOL> ha_client = HAClient ( [ Namenode ( "<STR_LIT:foo>" ) , Namenode ( "<STR_LIT:bar>" ) ] ) <EOL> ha_client . cat = HAClient . _ha_gen_method ( mocked_client_cat ) <EOL> cat_result_gen = ha_client . cat ( ha_client , [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( OutOfNNException , all , cat_result_gen ) <EOL> def test_ha_client_standby_errror ( self ) : <EOL> e = RequestError ( "<STR_LIT>" ) <EOL> mocked_client_cat = Mock ( side_effect = e ) <EOL> ha_client = HAClient ( [ Namenode ( "<STR_LIT:foo>" ) , Namenode ( "<STR_LIT:bar>" ) ] ) <EOL> ha_client . cat = HAClient . _ha_gen_method ( mocked_client_cat ) <EOL> cat_result_gen = ha_client . cat ( ha_client , [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( OutOfNNException , all , cat_result_gen ) <EOL> def test_wrapped_methods ( self ) : <EOL> public_methods = [ ( name , method ) for name , method in inspect . getmembers ( HAClient , inspect . ismethod ) if not name . startswith ( "<STR_LIT:_>" ) ] <EOL> self . assertGreater ( len ( public_methods ) , <NUM_LIT:0> ) <EOL> wrapped_methods = [ str ( method ) for name , method in public_methods if "<STR_LIT>" in str ( method ) ] <EOL> self . assertEqual ( len ( public_methods ) , len ( wrapped_methods ) ) <EOL> def test_empty_namenodes_haclient ( self ) : <EOL> namenodes = ( ) <EOL> self . assertRaises ( InvalidInputException , HAClient , namenodes ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_empty_namenodes_autoclient ( self , environ_get ) : <EOL> environ_get . return_value = False <EOL> HDFSConfig . hdfs_try_paths = ( ) <EOL> HDFSConfig . core_try_paths = ( ) <EOL> self . assertRaises ( InvalidInputException , AutoConfigClient ) </s>
