<s> import os <EOL> import errno <EOL> import re <EOL> from distutils . dir_util import remove_tree <EOL> from distutils . dir_util import mkpath <EOL> from mock import patch <EOL> from mock import call <EOL> from tests . base_test_case import BaseTestCase <EOL> from packaging . bdist_prestoadmin import bdist_prestoadmin <EOL> from packaging import package_dir as packaging_dir <EOL> from distutils . dist import Distribution <EOL> class TestBDistPrestoAdmin ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestBDistPrestoAdmin , self ) . setUp ( ) <EOL> self . attrs = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : bdist_prestoadmin } , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> dist = Distribution ( attrs = self . attrs ) <EOL> self . bdist = dist . get_command_obj ( '<STR_LIT>' ) <EOL> self . bdist . finalize_options ( ) <EOL> def test_initialize ( self ) : <EOL> dist = Distribution ( attrs = self . attrs ) <EOL> bdist = dist . get_command_obj ( '<STR_LIT>' ) <EOL> self . assertEquals ( bdist . bdist_dir , None ) <EOL> self . assertEquals ( bdist . dist_dir , None ) <EOL> self . assertEquals ( bdist . virtualenv_version , None ) <EOL> self . assertEquals ( bdist . keep_temp , False ) <EOL> self . assertEquals ( bdist . online_install , False ) <EOL> def test_finalize ( self ) : <EOL> self . assertRegexpMatches ( <EOL> self . bdist . bdist_dir , <EOL> '<STR_LIT>' ) <EOL> self . assertEquals ( self . bdist . dist_dir , '<STR_LIT>' ) <EOL> self . assertEquals ( self . bdist . default_virtualenv_version , '<STR_LIT>' ) <EOL> self . assertEquals ( self . bdist . keep_temp , False ) <EOL> def test_finalize_argvs ( self ) : <EOL> self . attrs [ '<STR_LIT>' ] = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> dist = Distribution ( attrs = self . attrs ) <EOL> dist . parse_command_line ( ) <EOL> bdist = dist . get_command_obj ( '<STR_LIT>' ) <EOL> bdist . finalize_options ( ) <EOL> self . assertEquals ( bdist . bdist_dir , '<STR_LIT>' ) <EOL> self . assertEquals ( bdist . dist_dir , '<STR_LIT>' ) <EOL> self . assertEquals ( bdist . virtualenv_version , '<STR_LIT>' ) <EOL> self . assertEquals ( bdist . keep_temp , True ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_build_wheel ( self , run_command_mock ) : <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> self . bdist . build_wheel ( '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_package_dependencies_for_offline_installer ( self , pip_mock , <EOL> urlretrieve_mock ) : <EOL> build_path = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . bdist . package_dependencies ( build_path ) <EOL> calls = [ call ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) , <EOL> call ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) ] <EOL> pip_mock . assert_has_calls ( calls , any_order = False ) <EOL> @ patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_package_dependencies_for_online_installer ( <EOL> self , package_dependencies_mock , build_wheel_mock , <EOL> generate_install_script_mock ) : <EOL> self . bdist . online_install = True <EOL> self . bdist . run ( ) <EOL> assert not package_dependencies_mock . called , '<STR_LIT>' <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_correct_use_of_precompiled_pycrypto ( self , pip_mock , urllib_mock , <EOL> sys_mock ) : <EOL> build_path = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> thirdparty_dir = os . path . join ( build_path , '<STR_LIT>' ) <EOL> pycrypto_whl = '<STR_LIT>' <EOL> pypi_pycrypto_url = '<STR_LIT>' + pycrypto_whl <EOL> sys_mock . version = '<STR_LIT>' <EOL> self . bdist . package_dependencies ( build_path ) <EOL> urllib_mock . assert_called_with ( <EOL> pypi_pycrypto_url . format ( '<STR_LIT>' ) , <EOL> os . path . join ( thirdparty_dir , pycrypto_whl . format ( '<STR_LIT>' ) ) <EOL> ) <EOL> sys_mock . version = '<STR_LIT>' <EOL> self . bdist . package_dependencies ( build_path ) <EOL> urllib_mock . assert_called_with ( <EOL> pypi_pycrypto_url . format ( '<STR_LIT>' ) , <EOL> os . path . join ( thirdparty_dir , pycrypto_whl . format ( '<STR_LIT>' ) ) <EOL> ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_offline_installer_fails_when_not_on_td_network ( <EOL> self , pip_mock , urllib_mock , sys_mock ) : <EOL> build_path = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exception = IOError ( ) <EOL> exception . errno = '<STR_LIT>' <EOL> urllib_mock . side_effect = exception <EOL> self . assertRaises ( IOError , self . bdist . package_dependencies , <EOL> build_path ) <EOL> def test_generate_online_install_script ( self ) : <EOL> self . generate_script ( '<STR_LIT>' , True ) <EOL> def test_generate_offline_install_script ( self ) : <EOL> self . generate_script ( '<STR_LIT>' , False ) <EOL> def generate_script ( self , expected_file , is_online ) : <EOL> try : <EOL> self . bdist . online_install = is_online <EOL> os . chdir ( packaging_dir ) <EOL> try : <EOL> os . mkdir ( '<STR_LIT>' ) <EOL> except OSError as exception : <EOL> if exception . errno != errno . EEXIST : <EOL> raise <EOL> self . bdist . generate_install_script ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> actual_install_script = open ( '<STR_LIT>' ) . read ( ) <EOL> file_dir = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> template = os . path . join ( file_dir , <EOL> '<STR_LIT>' , <EOL> expected_file ) <EOL> expected_install_script = open ( template ) . read ( ) <EOL> self . assertEqual ( expected_install_script , actual_install_script ) <EOL> finally : <EOL> remove_tree ( '<STR_LIT>' ) <EOL> def test_archive_dist_offline ( self ) : <EOL> build_path = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> mkpath ( build_path ) <EOL> self . bdist . archive_dist ( build_path , '<STR_LIT>' ) <EOL> archive = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( archive ) ) <EOL> finally : <EOL> remove_tree ( os . path . dirname ( build_path ) ) <EOL> remove_tree ( '<STR_LIT>' ) <EOL> def test_archive_dist_online ( self ) : <EOL> build_path = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> mkpath ( build_path ) <EOL> self . bdist . online_install = True <EOL> self . bdist . archive_dist ( build_path , '<STR_LIT>' ) <EOL> archive = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( archive ) ) <EOL> finally : <EOL> remove_tree ( os . path . dirname ( build_path ) ) <EOL> remove_tree ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_run ( self , <EOL> archive_dist_mock , <EOL> package_dependencies_mock , <EOL> install_script_mock , <EOL> build_wheel_mock , <EOL> remove_tree_mock , <EOL> mkpath_mock ) : <EOL> self . bdist . run ( ) <EOL> def matching_regex ( expected_regex ) : <EOL> class RegexMatcher : <EOL> def __eq__ ( self , other ) : <EOL> return re . match ( expected_regex , other ) <EOL> return RegexMatcher ( ) <EOL> build_path_re = matching_regex ( <EOL> '<STR_LIT>' ) <EOL> build_wheel_mock . assert_called_once_with ( build_path_re ) <EOL> install_script_mock . assert_called_once_with ( '<STR_LIT>' , <EOL> build_path_re ) <EOL> package_dependencies_mock . assert_called_once_with ( <EOL> build_path_re ) <EOL> archive_dist_mock . assert_called_once_with ( build_path_re , '<STR_LIT>' ) <EOL> def test_description ( self ) : <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> self . bdist . description ) <EOL> def test_user_options ( self ) : <EOL> expected = [ ( '<STR_LIT>' , '<STR_LIT:b>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:k>' , <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> ] <EOL> self . assertEquals ( expected , self . bdist . user_options ) </s>
