<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> from pants . binaries . binary_util import BinaryUtil <EOL> from pants_test . base_test import BaseTest <EOL> class BinaryUtilTest ( BaseTest ) : <EOL> """<STR_LIT>""" <EOL> class MapFetcher ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , read_map ) : <EOL> self . _map = read_map <EOL> def download ( self , url , listener = None , path_or_fd = None ) : <EOL> if not url in self . _map : <EOL> raise IOError ( "<STR_LIT>" . format ( url ) ) <EOL> if not path_or_fd : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> path_or_fd . write ( self . _map [ url ] ) <EOL> return path_or_fd <EOL> def keys ( self ) : <EOL> return self . _map . keys ( ) <EOL> def values ( self ) : <EOL> return self . _map . values ( ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . _map [ key ] <EOL> def setUp ( self ) : <EOL> super ( BinaryUtilTest , self ) . setUp ( ) <EOL> @ classmethod <EOL> def _fake_base ( cls , name ) : <EOL> return '<STR_LIT>' . format ( name = name ) <EOL> @ classmethod <EOL> def _fake_url ( cls , binaries , base , binary_key ) : <EOL> binary_util = BinaryUtil ( [ ] , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> supportdir , version , name = binaries [ binary_key ] <EOL> binary = binary_util . _select_binary_base_path ( supportdir , version , binary_key ) <EOL> return '<STR_LIT>' . format ( base = base , binary = binary ) <EOL> def test_nobases ( self ) : <EOL> """<STR_LIT>""" <EOL> binary_util = BinaryUtil ( baseurls = [ ] , timeout_secs = <NUM_LIT:30> , bootstrapdir = '<STR_LIT>' ) <EOL> with self . assertRaises ( binary_util . NoBaseUrlsError ) : <EOL> binary_path = binary_util . _select_binary_base_path ( supportdir = '<STR_LIT>' , <EOL> version = '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> with binary_util . _select_binary_stream ( name = '<STR_LIT>' , binary_path = binary_path ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_support_url_multi ( self ) : <EOL> """<STR_LIT>""" <EOL> count = <NUM_LIT:0> <EOL> binary_util = BinaryUtil ( <EOL> baseurls = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> timeout_secs = <NUM_LIT:30> , <EOL> bootstrapdir = '<STR_LIT>' ) <EOL> binary_path = binary_util . _select_binary_base_path ( supportdir = '<STR_LIT>' , <EOL> version = '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> with binary_util . _select_binary_stream ( name = '<STR_LIT>' , binary_path = binary_path ) as stream : <EOL> stream ( ) <EOL> count += <NUM_LIT:1> <EOL> self . assertEqual ( count , <NUM_LIT:1> ) <EOL> def test_support_url_fallback ( self ) : <EOL> """<STR_LIT>""" <EOL> fake_base , fake_url = self . _fake_base , self . _fake_url <EOL> bases = [ fake_base ( '<STR_LIT>' ) , fake_base ( '<STR_LIT>' ) , fake_base ( '<STR_LIT>' ) ] <EOL> binary_util = BinaryUtil ( bases , <NUM_LIT:30> , '<STR_LIT>' ) <EOL> binaries = { t [ <NUM_LIT:2> ] : t for t in ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) } <EOL> fetcher = self . MapFetcher ( { <EOL> fake_url ( binaries , bases [ <NUM_LIT:0> ] , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> fake_url ( binaries , bases [ <NUM_LIT:0> ] , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> fake_url ( binaries , bases [ <NUM_LIT:1> ] , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> fake_url ( binaries , bases [ <NUM_LIT:1> ] , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> fake_url ( binaries , bases [ <NUM_LIT:2> ] , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> fake_url ( binaries , bases [ <NUM_LIT:2> ] , '<STR_LIT>' ) : '<STR_LIT>' , <EOL> } ) <EOL> unseen = [ item for item in fetcher . values ( ) if item . startswith ( '<STR_LIT>' ) ] <EOL> for supportdir , version , name in binaries . values ( ) : <EOL> binary_path = binary_util . _select_binary_base_path ( supportdir = supportdir , <EOL> version = version , <EOL> name = name ) <EOL> with binary_util . _select_binary_stream ( name = name , <EOL> binary_path = binary_path , <EOL> fetcher = fetcher ) as stream : <EOL> result = stream ( ) <EOL> self . assertEqual ( result , '<STR_LIT>' + name . upper ( ) ) <EOL> unseen . remove ( result ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( unseen ) ) <EOL> def test_select_binary_base_path_linux ( self ) : <EOL> binary_util = BinaryUtil ( [ ] , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> def uname_func ( ) : <EOL> return "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> binary_util . _select_binary_base_path ( "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:version>" , <EOL> uname_func = uname_func ) ) <EOL> def test_select_binary_base_path_darwin ( self ) : <EOL> binary_util = BinaryUtil ( [ ] , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> def uname_func ( ) : <EOL> return "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> binary_util . _select_binary_base_path ( "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:version>" , <EOL> uname_func = uname_func ) ) <EOL> def test_select_binary_base_path_missing_os ( self ) : <EOL> binary_util = BinaryUtil ( [ ] , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> def uname_func ( ) : <EOL> return "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( BinaryUtil . MissingMachineInfo , <EOL> r'<STR_LIT>' ) : <EOL> binary_util . _select_binary_base_path ( "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:version>" , <EOL> uname_func = uname_func ) <EOL> def test_select_binary_base_path_missing_version ( self ) : <EOL> binary_util = BinaryUtil ( [ ] , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> def uname_func ( ) : <EOL> return "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( BinaryUtil . MissingMachineInfo , <EOL> r'<STR_LIT>' ) : <EOL> binary_util . _select_binary_base_path ( "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:version>" , <EOL> uname_func = uname_func ) <EOL> def test_select_binary_base_path_override ( self ) : <EOL> binary_util = BinaryUtil ( [ ] , <NUM_LIT:0> , '<STR_LIT>' , <EOL> { ( '<STR_LIT>' , '<STR_LIT:100>' ) : [ '<STR_LIT>' , '<STR_LIT>' ] } ) <EOL> def uname_func ( ) : <EOL> return "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> binary_util . _select_binary_base_path ( "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:version>" , <EOL> uname_func = uname_func ) ) </s>
