<s> import py , os , sys , shutil <EOL> import subprocess <EOL> from testing . udir import udir <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> py . test . skip ( '<STR_LIT>' ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> py . test . skip ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def create_venv ( name ) : <EOL> tmpdir = udir . join ( name ) <EOL> try : <EOL> subprocess . check_call ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , os . path . abspath ( sys . executable ) , <EOL> str ( tmpdir ) ] ) <EOL> except OSError as e : <EOL> py . test . skip ( "<STR_LIT>" % ( e , ) ) <EOL> site_packages = None <EOL> for dirpath , dirnames , filenames in os . walk ( str ( tmpdir ) ) : <EOL> if os . path . basename ( dirpath ) == '<STR_LIT>' : <EOL> site_packages = dirpath <EOL> break <EOL> paths = "<STR_LIT>" <EOL> if site_packages : <EOL> try : <EOL> from cffi import _pycparser <EOL> modules = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except ImportError : <EOL> modules = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> import ply <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> modules += ( '<STR_LIT>' , ) <EOL> paths = [ ] <EOL> for module in modules : <EOL> target = __import__ ( module , None , None , [ ] ) <EOL> if not hasattr ( target , '<STR_LIT>' ) : <EOL> continue <EOL> src = os . path . abspath ( target . __file__ ) <EOL> for end in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if src . lower ( ) . endswith ( end ) : <EOL> src = src [ : - len ( end ) - <NUM_LIT:1> ] <EOL> break <EOL> paths . append ( os . path . dirname ( src ) ) <EOL> paths = os . pathsep . join ( paths ) <EOL> return tmpdir , paths <EOL> SNIPPET_DIR = py . path . local ( __file__ ) . join ( '<STR_LIT:..>' , '<STR_LIT>' ) <EOL> def really_run_setup_and_program ( dirname , venv_dir_and_paths , python_snippet ) : <EOL> venv_dir , paths = venv_dir_and_paths <EOL> def remove ( dir ) : <EOL> dir = str ( SNIPPET_DIR . join ( dirname , dir ) ) <EOL> shutil . rmtree ( dir , ignore_errors = True ) <EOL> remove ( '<STR_LIT>' ) <EOL> remove ( '<STR_LIT>' ) <EOL> for basedir in os . listdir ( str ( SNIPPET_DIR . join ( dirname ) ) ) : <EOL> remove ( os . path . join ( basedir , '<STR_LIT>' ) ) <EOL> olddir = os . getcwd ( ) <EOL> python_f = udir . join ( '<STR_LIT>' ) <EOL> python_f . write ( py . code . Source ( python_snippet ) ) <EOL> try : <EOL> os . chdir ( str ( SNIPPET_DIR . join ( dirname ) ) ) <EOL> if os . name == '<STR_LIT>' : <EOL> bindir = '<STR_LIT>' <EOL> else : <EOL> bindir = '<STR_LIT>' <EOL> vp = str ( venv_dir . join ( bindir ) . join ( '<STR_LIT>' ) ) <EOL> env = os . environ . copy ( ) <EOL> env [ '<STR_LIT>' ] = paths <EOL> subprocess . check_call ( ( vp , '<STR_LIT>' , '<STR_LIT>' ) , env = env ) <EOL> subprocess . check_call ( ( vp , '<STR_LIT>' , '<STR_LIT>' ) , env = env ) <EOL> subprocess . check_call ( ( vp , str ( python_f ) ) , env = env ) <EOL> finally : <EOL> os . chdir ( olddir ) <EOL> def run_setup_and_program ( dirname , python_snippet ) : <EOL> venv_dir = create_venv ( dirname + '<STR_LIT>' ) <EOL> really_run_setup_and_program ( dirname , venv_dir , python_snippet ) <EOL> sys . _force_generic_engine_ = True <EOL> try : <EOL> venv_dir = create_venv ( dirname + '<STR_LIT>' ) <EOL> really_run_setup_and_program ( dirname , venv_dir , python_snippet ) <EOL> finally : <EOL> del sys . _force_generic_engine_ <EOL> assert not os . path . exists ( str ( SNIPPET_DIR . join ( dirname , '<STR_LIT>' ) ) ) <EOL> assert not os . path . exists ( str ( SNIPPET_DIR . join ( dirname , '<STR_LIT>' ) ) ) <EOL> class TestZIntegration ( object ) : <EOL> def teardown_class ( self ) : <EOL> if udir . isdir ( ) : <EOL> udir . remove ( ignore_errors = True ) <EOL> udir . ensure ( dir = <NUM_LIT:1> ) <EOL> def test_infrastructure ( self ) : <EOL> run_setup_and_program ( '<STR_LIT>' , '''<STR_LIT>''' ) <EOL> def test_distutils_module ( self ) : <EOL> run_setup_and_program ( "<STR_LIT>" , '''<STR_LIT>''' ) <EOL> def test_distutils_package_1 ( self ) : <EOL> run_setup_and_program ( "<STR_LIT>" , '''<STR_LIT>''' ) <EOL> def test_distutils_package_2 ( self ) : <EOL> run_setup_and_program ( "<STR_LIT>" , '''<STR_LIT>''' ) <EOL> def test_setuptools_module ( self ) : <EOL> run_setup_and_program ( "<STR_LIT>" , '''<STR_LIT>''' ) <EOL> def test_setuptools_package_1 ( self ) : <EOL> run_setup_and_program ( "<STR_LIT>" , '''<STR_LIT>''' ) <EOL> def test_setuptools_package_2 ( self ) : <EOL> run_setup_and_program ( "<STR_LIT>" , '''<STR_LIT>''' ) </s>
