<s> import glob <EOL> import os <EOL> import shutil <EOL> import zipfile <EOL> import pytest <EOL> from pyleus import __version__ <EOL> from pyleus import exception <EOL> from pyleus . cli import build <EOL> from pyleus . testing import mock <EOL> class TestBuild ( object ) : <EOL> @ mock . patch . object ( os . path , '<STR_LIT>' , autospec = True ) <EOL> def test__open_jar_jarfile_not_found ( self , mock_exists ) : <EOL> mock_exists . return_value = False <EOL> with pytest . raises ( exception . JarError ) : <EOL> build . _open_jar ( "<STR_LIT:foo>" ) <EOL> mock_exists . assert_called_once_with ( "<STR_LIT:foo>" ) <EOL> @ mock . patch . object ( os . path , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( zipfile , '<STR_LIT>' , autospec = True ) <EOL> def test__open_jar_not_jarfile ( self , mock_is_zipfile , mock_exists ) : <EOL> mock_exists . return_value = True <EOL> mock_is_zipfile . return_value = False <EOL> with pytest . raises ( exception . JarError ) : <EOL> build . _open_jar ( "<STR_LIT:foo>" ) <EOL> mock_is_zipfile . assert_called_once_with ( "<STR_LIT:foo>" ) <EOL> @ mock . patch . object ( os , '<STR_LIT>' , autospec = True ) <EOL> def test__zip_dir ( self , mock_walk ) : <EOL> mock_arc = mock . Mock ( autospec = True ) <EOL> mock_walk . return_value = [ <EOL> ( "<STR_LIT:foo>" , [ "<STR_LIT:bar>" ] , [ "<STR_LIT>" ] ) , <EOL> ( "<STR_LIT>" , [ ] , [ "<STR_LIT>" ] ) <EOL> ] <EOL> build . _zip_dir ( "<STR_LIT:foo>" , mock_arc ) <EOL> mock_walk . assert_any_call ( "<STR_LIT:foo>" ) <EOL> expected = [ <EOL> mock . call ( "<STR_LIT>" , "<STR_LIT>" , zipfile . ZIP_DEFLATED ) , <EOL> mock . call ( "<STR_LIT>" , "<STR_LIT>" , zipfile . ZIP_DEFLATED ) , <EOL> ] <EOL> mock_arc . write . assert_has_calls ( expected ) <EOL> @ mock . patch . object ( zipfile , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> def test__pack_jar ( self , mock_zip_dir , mock_zipfile ) : <EOL> build . _pack_jar ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> mock_zipfile . assert_called_once_with ( "<STR_LIT:bar>" , "<STR_LIT:w>" ) <EOL> mock_zip_dir . assert_called_once_with ( "<STR_LIT:foo>" , mock_zipfile . return_value ) <EOL> @ mock . patch . object ( os . path , '<STR_LIT>' , autospec = True ) <EOL> def test__validate_venv_dir_contains_venv ( self , mock_exists ) : <EOL> mock_exists . return_value = True <EOL> with pytest . raises ( exception . InvalidTopologyError ) : <EOL> build . _validate_venv ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> mock_exists . assert_called_once_with ( "<STR_LIT>" ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> def test__set_up_virtualenv_with_requirements ( self , mock_venv , <EOL> mock_remove_base_jar ) : <EOL> venv = mock_venv . return_value <EOL> build . _set_up_virtualenv ( <EOL> venv_name = "<STR_LIT:foo>" , <EOL> tmp_dir = "<STR_LIT:bar>" , <EOL> req = "<STR_LIT>" , <EOL> include_packages = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> system_site_packages = True , <EOL> pypi_index_url = "<STR_LIT>" , <EOL> python_interpreter = "<STR_LIT>" , <EOL> verbose = False ) <EOL> expected_install = [ <EOL> mock . call ( "<STR_LIT>" . format ( __version__ ) ) , <EOL> mock . call ( "<STR_LIT>" ) , <EOL> mock . call ( "<STR_LIT>" ) <EOL> ] <EOL> venv . install_package . assert_has_calls ( expected_install ) <EOL> venv . install_from_requirements . assert_called_once_with ( "<STR_LIT>" ) <EOL> mock_remove_base_jar . assert_called_once_with ( venv ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> def test__set_up_virtualenv_without_requirements ( self , mock_venv , <EOL> mock_remove_base_jar ) : <EOL> venv = mock_venv . return_value <EOL> build . _set_up_virtualenv ( <EOL> venv_name = "<STR_LIT:foo>" , <EOL> tmp_dir = "<STR_LIT:bar>" , <EOL> req = None , <EOL> include_packages = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> system_site_packages = True , <EOL> pypi_index_url = "<STR_LIT>" , <EOL> python_interpreter = "<STR_LIT>" , <EOL> verbose = False ) <EOL> expected_install = [ <EOL> mock . call ( "<STR_LIT>" . format ( __version__ ) ) , <EOL> mock . call ( "<STR_LIT>" ) , <EOL> mock . call ( "<STR_LIT>" ) <EOL> ] <EOL> venv . install_package . assert_has_calls ( expected_install ) <EOL> assert venv . install_from_requirements . call_count == <NUM_LIT:0> <EOL> mock_remove_base_jar . assert_called_once_with ( venv ) <EOL> @ mock . patch . object ( glob , '<STR_LIT>' , autospec = True ) <EOL> def test__content_to_copy ( self , mock_glob ) : <EOL> mock_glob . return_value = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> content = build . _content_to_copy ( "<STR_LIT:foo>" , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> mock_glob . assert_called_once_with ( "<STR_LIT>" ) <EOL> assert content == set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( os . path , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( shutil , '<STR_LIT>' , autospec = True ) <EOL> @ mock . patch . object ( shutil , '<STR_LIT>' , autospec = True ) <EOL> def test__copy_dir_content ( <EOL> self , mock_copy2 , mock_copytree , mock_isdir , mock_cont_to_copy ) : <EOL> mock_cont_to_copy . return_value = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> mock_isdir . side_effect = iter ( [ True , False ] ) <EOL> build . _copy_dir_content ( src = "<STR_LIT:foo>" , dst = "<STR_LIT:bar>" , exclude = [ ] ) <EOL> mock_cont_to_copy . assert_called_once_with ( "<STR_LIT:foo>" , [ ] ) <EOL> expected = [ mock . call ( "<STR_LIT>" ) , mock . call ( "<STR_LIT>" ) ] <EOL> mock_isdir . assert_has_calls ( expected ) <EOL> mock_copytree . assert_called_once_with ( <EOL> "<STR_LIT>" , "<STR_LIT>" , symlinks = True ) <EOL> mock_copy2 . assert_called_once_with ( "<STR_LIT>" , "<STR_LIT:bar>" ) <EOL> @ mock . patch . object ( build , '<STR_LIT>' , autospec = True ) <EOL> def test__build_otuput_path ( self , mock_ex_path ) : <EOL> build . _build_output_path ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> mock_ex_path . assert_called_with ( "<STR_LIT:foo>" ) <EOL> build . _build_output_path ( None , "<STR_LIT:bar>" ) <EOL> mock_ex_path . assert_called_with ( "<STR_LIT>" ) <EOL> def test__path_contained_by ( self ) : <EOL> p1 = '<STR_LIT>' <EOL> p2 = '<STR_LIT>' <EOL> p3 = '<STR_LIT>' <EOL> assert not build . _path_contained_by ( p1 , p2 ) <EOL> assert build . _path_contained_by ( p1 , p3 ) <EOL> def test__remove_pyleus_base_jar ( self ) : <EOL> """<STR_LIT>""" <EOL> mock_venv_path = "<STR_LIT>" <EOL> def mock_execute_module ( module , cwd ) : <EOL> return "<STR_LIT>" <EOL> mock_venv = mock . Mock ( <EOL> path = mock_venv_path , <EOL> execute_module = mock_execute_module , <EOL> ) <EOL> with mock . patch . object ( os , '<STR_LIT>' ) as mock_remove : <EOL> build . _remove_pyleus_base_jar ( mock_venv ) <EOL> mock_remove . assert_called_once_with ( "<STR_LIT>" ) <EOL> def test__remove_pyleus_base_jar_no_remove ( self ) : <EOL> """<STR_LIT>""" <EOL> mock_venv_path = "<STR_LIT>" <EOL> def mock_execute_module ( module , cwd ) : <EOL> return "<STR_LIT>" <EOL> mock_venv = mock . Mock ( <EOL> path = mock_venv_path , <EOL> execute_module = mock_execute_module , <EOL> ) <EOL> with mock . patch . object ( os , '<STR_LIT>' ) as mock_remove : <EOL> build . _remove_pyleus_base_jar ( mock_venv ) <EOL> assert not mock_remove . called </s>
