<s> import os <EOL> import subprocess <EOL> import pytest <EOL> from pyleus import exception <EOL> from pyleus . cli import virtualenv_proxy <EOL> from pyleus . cli . virtualenv_proxy import VirtualenvProxy <EOL> from pyleus . testing import mock , builtins <EOL> VENV_PATH = "<STR_LIT>" <EOL> PYPI_URL = "<STR_LIT>" <EOL> class TestVirtualenvProxyTopLevelFunctions ( object ) : <EOL> @ mock . patch . object ( subprocess , '<STR_LIT>' , autospec = True ) <EOL> def test__exec_bash_cmd ( self , mock_popen ) : <EOL> mock_proc = mock . Mock ( ) <EOL> mock_popen . return_value = mock_proc <EOL> mock_proc . communicate . return_value = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> mock_proc . returncode = <NUM_LIT:1> <EOL> with pytest . raises ( exception . VirtualenvError ) as exc_info : <EOL> virtualenv_proxy . _exec_shell_cmd ( <EOL> "<STR_LIT>" , <EOL> stdout = <NUM_LIT> , <EOL> stderr = <NUM_LIT> , <EOL> err_msg = "<STR_LIT:bar>" , <EOL> ) <EOL> assert "<STR_LIT:bar>" in str ( exc_info . value ) <EOL> mock_popen . assert_called_once_with ( <EOL> "<STR_LIT>" , stdout = <NUM_LIT> , stderr = <NUM_LIT> ) <EOL> mock_proc . communicate . assert_called_once_with ( ) <EOL> class TestVirtualenvProxyCreation ( object ) : <EOL> @ mock . patch . object ( builtins , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( VirtualenvProxy , '<STR_LIT>' , autospec = True ) <EOL> def test___init__ ( self , mock_create , mock_open ) : <EOL> mock_open . return_value = <NUM_LIT> <EOL> venv = VirtualenvProxy ( VENV_PATH , verbose = False ) <EOL> mock_open . assert_called_once_with ( os . devnull , "<STR_LIT:w>" ) <EOL> assert venv . _out_stream == <NUM_LIT> <EOL> mock_create . assert_called_once_with ( venv ) <EOL> venv = VirtualenvProxy ( VENV_PATH , verbose = True ) <EOL> assert mock_open . call_count == <NUM_LIT:1> <EOL> assert venv . _out_stream is None <EOL> @ mock . patch . object ( builtins , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( virtualenv_proxy , '<STR_LIT>' , autospec = True ) <EOL> def test__create_virtualenv_no_options ( <EOL> self , mock_cmd , mock_open ) : <EOL> venv = VirtualenvProxy ( VENV_PATH , <EOL> system_site_packages = False , <EOL> verbose = True ) <EOL> mock_cmd . assert_called_once_with ( <EOL> [ "<STR_LIT>" , VENV_PATH ] , <EOL> stdout = venv . _out_stream , <EOL> stderr = venv . _err_stream , <EOL> err_msg = mock . ANY <EOL> ) <EOL> @ mock . patch . object ( builtins , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( virtualenv_proxy , '<STR_LIT>' , autospec = True ) <EOL> def test__create_virtualenv_system_site_packages ( <EOL> self , mock_cmd , mock_open ) : <EOL> venv = VirtualenvProxy ( VENV_PATH , <EOL> system_site_packages = True , <EOL> verbose = True ) <EOL> mock_cmd . assert_called_once_with ( <EOL> [ "<STR_LIT>" , VENV_PATH , "<STR_LIT>" ] , <EOL> stdout = venv . _out_stream , <EOL> stderr = venv . _err_stream , <EOL> err_msg = mock . ANY <EOL> ) <EOL> @ mock . patch . object ( builtins , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( virtualenv_proxy , '<STR_LIT>' , autospec = True ) <EOL> def test__create_virtualenv_python_interpreter ( <EOL> self , mock_cmd , mock_open ) : <EOL> path = "<STR_LIT>" <EOL> venv = VirtualenvProxy ( VENV_PATH , <EOL> python_interpreter = path , <EOL> verbose = True ) <EOL> mock_cmd . assert_called_once_with ( <EOL> [ "<STR_LIT>" , VENV_PATH , "<STR_LIT>" , path ] , <EOL> stdout = venv . _out_stream , <EOL> stderr = venv . _err_stream , <EOL> err_msg = mock . ANY <EOL> ) <EOL> class TestVirtualenvProxyMethods ( object ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> @ mock . patch . object ( builtins , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( VirtualenvProxy , '<STR_LIT>' , autospec = True ) <EOL> def setup_virtualenv ( self , mock_create , mock_open ) : <EOL> self . venv = VirtualenvProxy ( VENV_PATH , <EOL> pypi_index_url = PYPI_URL , <EOL> verbose = False ) <EOL> @ mock . patch . object ( virtualenv_proxy , '<STR_LIT>' , autospec = True ) <EOL> def test_install_package ( self , mock_cmd ) : <EOL> self . venv . install_package ( "<STR_LIT>" ) <EOL> mock_cmd . assert_called_once_with ( <EOL> [ <EOL> "<STR_LIT>" . format ( VENV_PATH ) , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , PYPI_URL , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> stdout = self . venv . _out_stream , <EOL> stderr = self . venv . _err_stream , <EOL> err_msg = mock . ANY <EOL> ) <EOL> @ mock . patch . object ( virtualenv_proxy , '<STR_LIT>' , autospec = True ) <EOL> def test_install_from_requirements ( self , mock_cmd ) : <EOL> self . venv . install_from_requirements ( "<STR_LIT>" ) <EOL> mock_cmd . assert_called_once_with ( <EOL> [ <EOL> "<STR_LIT>" . format ( VENV_PATH ) , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , PYPI_URL , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> stdout = self . venv . _out_stream , <EOL> stderr = self . venv . _err_stream , <EOL> err_msg = mock . ANY <EOL> ) </s>
