<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> import unittest <EOL> import site <EOL> import textwrap <EOL> import tarfile <EOL> import urlparse <EOL> import StringIO <EOL> import distutils . core <EOL> from setuptools . sandbox import run_setup , SandboxViolation <EOL> from setuptools . command . easy_install import easy_install , fix_jython_executable , get_script_args , main <EOL> from setuptools . command . easy_install import PthDistributions <EOL> from setuptools . command import easy_install as easy_install_pkg <EOL> from setuptools . dist import Distribution <EOL> from pkg_resources import Distribution as PRDistribution <EOL> import setuptools . tests . server <EOL> try : <EOL> __import__ ( '<STR_LIT>' ) <EOL> import logging <EOL> _LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> logging . basicConfig ( level = logging . INFO , stream = sys . stderr ) <EOL> _MULTIPROC = True <EOL> except ImportError : <EOL> _MULTIPROC = False <EOL> _LOG = None <EOL> class FakeDist ( object ) : <EOL> def get_entry_map ( self , group ) : <EOL> if group != '<STR_LIT>' : <EOL> return { } <EOL> return { '<STR_LIT:name>' : '<STR_LIT>' } <EOL> def as_requirement ( self ) : <EOL> return '<STR_LIT>' <EOL> WANTED = """<STR_LIT>""" % fix_jython_executable ( sys . executable , "<STR_LIT>" ) <EOL> SETUP_PY = """<STR_LIT>""" <EOL> class TestEasyInstallTest ( unittest . TestCase ) : <EOL> def test_install_site_py ( self ) : <EOL> dist = Distribution ( ) <EOL> cmd = easy_install ( dist ) <EOL> cmd . sitepy_installed = False <EOL> cmd . install_dir = tempfile . mkdtemp ( ) <EOL> try : <EOL> cmd . install_site_py ( ) <EOL> sitepy = os . path . join ( cmd . install_dir , '<STR_LIT>' ) <EOL> self . assertTrue ( os . path . exists ( sitepy ) ) <EOL> finally : <EOL> shutil . rmtree ( cmd . install_dir ) <EOL> def test_get_script_args ( self ) : <EOL> dist = FakeDist ( ) <EOL> old_platform = sys . platform <EOL> try : <EOL> name , script = [ i for i in get_script_args ( dist ) . next ( ) ] [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> finally : <EOL> sys . platform = old_platform <EOL> self . assertEqual ( script , WANTED ) <EOL> def test_no_setup_cfg ( self ) : <EOL> dir = tempfile . mkdtemp ( ) <EOL> setup_cfg = open ( os . path . join ( dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> setup_cfg . write ( '<STR_LIT>' ) <EOL> setup_cfg . close ( ) <EOL> setup_py = open ( os . path . join ( dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> setup_py . write ( SETUP_PY ) <EOL> setup_py . close ( ) <EOL> from setuptools . dist import Distribution <EOL> def _parse_command_line ( self ) : <EOL> msg = '<STR_LIT>' <EOL> opts = self . command_options <EOL> if '<STR_LIT>' in opts : <EOL> assert '<STR_LIT>' not in opts [ '<STR_LIT>' ] , msg <EOL> return self . _old_parse_command_line ( ) <EOL> Distribution . _old_parse_command_line = Distribution . parse_command_line <EOL> Distribution . parse_command_line = _parse_command_line <EOL> old_wd = os . getcwd ( ) <EOL> try : <EOL> os . chdir ( dir ) <EOL> reset_setup_stop_context ( <EOL> lambda : self . assertRaises ( SystemExit , main , [ ] ) <EOL> ) <EOL> finally : <EOL> os . chdir ( old_wd ) <EOL> shutil . rmtree ( dir ) <EOL> Distribution . parse_command_line = Distribution . _old_parse_command_line <EOL> def test_no_find_links ( self ) : <EOL> dist = Distribution ( ) <EOL> cmd = easy_install ( dist ) <EOL> cmd . check_pth_processing = lambda : True <EOL> cmd . no_find_links = True <EOL> cmd . find_links = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> cmd . install_dir = os . path . join ( tempfile . mkdtemp ( ) , '<STR_LIT>' ) <EOL> cmd . args = [ '<STR_LIT>' ] <EOL> cmd . ensure_finalized ( ) <EOL> self . assertEqual ( cmd . package_index . scanned_urls , { } ) <EOL> cmd = easy_install ( dist ) <EOL> cmd . check_pth_processing = lambda : True <EOL> cmd . find_links = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> cmd . install_dir = os . path . join ( tempfile . mkdtemp ( ) , '<STR_LIT>' ) <EOL> cmd . args = [ '<STR_LIT>' ] <EOL> cmd . ensure_finalized ( ) <EOL> keys = cmd . package_index . scanned_urls . keys ( ) <EOL> keys . sort ( ) <EOL> self . assertEqual ( keys , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class TestPTHFileWriter ( unittest . TestCase ) : <EOL> def test_add_from_cwd_site_sets_dirty ( self ) : <EOL> '''<STR_LIT>''' <EOL> pth = PthDistributions ( '<STR_LIT>' , [ os . getcwd ( ) ] ) <EOL> self . assertTrue ( not pth . dirty ) <EOL> pth . add ( PRDistribution ( os . getcwd ( ) ) ) <EOL> self . assertTrue ( pth . dirty ) <EOL> def test_add_from_site_is_ignored ( self ) : <EOL> if os . name != '<STR_LIT>' : <EOL> location = '<STR_LIT>' <EOL> else : <EOL> location = '<STR_LIT>' <EOL> pth = PthDistributions ( '<STR_LIT>' , [ location , ] ) <EOL> self . assertTrue ( not pth . dirty ) <EOL> pth . add ( PRDistribution ( location ) ) <EOL> self . assertTrue ( not pth . dirty ) <EOL> class TestUserInstallTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dir = tempfile . mkdtemp ( ) <EOL> setup = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> f = open ( setup , '<STR_LIT:w>' ) <EOL> f . write ( SETUP_PY ) <EOL> f . close ( ) <EOL> self . old_cwd = os . getcwd ( ) <EOL> os . chdir ( self . dir ) <EOL> if sys . version >= "<STR_LIT>" : <EOL> self . old_has_site = easy_install_pkg . HAS_USER_SITE <EOL> self . old_file = easy_install_pkg . __file__ <EOL> self . old_base = site . USER_BASE <EOL> site . USER_BASE = tempfile . mkdtemp ( ) <EOL> self . old_site = site . USER_SITE <EOL> site . USER_SITE = tempfile . mkdtemp ( ) <EOL> easy_install_pkg . __file__ = site . USER_SITE <EOL> def tearDown ( self ) : <EOL> os . chdir ( self . old_cwd ) <EOL> shutil . rmtree ( self . dir ) <EOL> if sys . version >= "<STR_LIT>" : <EOL> shutil . rmtree ( site . USER_BASE ) <EOL> shutil . rmtree ( site . USER_SITE ) <EOL> site . USER_BASE = self . old_base <EOL> site . USER_SITE = self . old_site <EOL> easy_install_pkg . HAS_USER_SITE = self . old_has_site <EOL> easy_install_pkg . __file__ = self . old_file <EOL> def test_user_install_implied ( self ) : <EOL> easy_install_pkg . HAS_USER_SITE = True <EOL> if sys . version < "<STR_LIT>" : <EOL> return <EOL> dist = Distribution ( ) <EOL> dist . script_name = '<STR_LIT>' <EOL> cmd = easy_install ( dist ) <EOL> cmd . args = [ '<STR_LIT>' ] <EOL> cmd . ensure_finalized ( ) <EOL> self . assertTrue ( cmd . user , '<STR_LIT>' ) <EOL> def test_multiproc_atexit ( self ) : <EOL> if not _MULTIPROC : <EOL> return <EOL> _LOG . info ( '<STR_LIT>' ) <EOL> def test_user_install_not_implied_without_usersite_enabled ( self ) : <EOL> easy_install_pkg . HAS_USER_SITE = False <EOL> if sys . version < "<STR_LIT>" : <EOL> return <EOL> dist = Distribution ( ) <EOL> dist . script_name = '<STR_LIT>' <EOL> cmd = easy_install ( dist ) <EOL> cmd . args = [ '<STR_LIT>' ] <EOL> cmd . initialize_options ( ) <EOL> self . assertFalse ( cmd . user , '<STR_LIT>' ) <EOL> def test_local_index ( self ) : <EOL> new_location = tempfile . mkdtemp ( ) <EOL> target = tempfile . mkdtemp ( ) <EOL> egg_file = os . path . join ( new_location , '<STR_LIT>' ) <EOL> f = open ( egg_file , '<STR_LIT:w>' ) <EOL> try : <EOL> f . write ( '<STR_LIT>' ) <EOL> finally : <EOL> f . close ( ) <EOL> sys . path . append ( target ) <EOL> old_ppath = os . environ . get ( '<STR_LIT>' ) <EOL> os . environ [ '<STR_LIT>' ] = os . path . pathsep . join ( sys . path ) <EOL> try : <EOL> dist = Distribution ( ) <EOL> dist . script_name = '<STR_LIT>' <EOL> cmd = easy_install ( dist ) <EOL> cmd . install_dir = target <EOL> cmd . args = [ '<STR_LIT:foo>' ] <EOL> cmd . ensure_finalized ( ) <EOL> cmd . local_index . scan ( [ new_location ] ) <EOL> res = cmd . easy_install ( '<STR_LIT:foo>' ) <EOL> self . assertEqual ( os . path . realpath ( res . location ) , <EOL> os . path . realpath ( new_location ) ) <EOL> finally : <EOL> sys . path . remove ( target ) <EOL> for basedir in [ new_location , target , ] : <EOL> if not os . path . exists ( basedir ) or not os . path . isdir ( basedir ) : <EOL> continue <EOL> try : <EOL> shutil . rmtree ( basedir ) <EOL> except : <EOL> pass <EOL> if old_ppath is not None : <EOL> os . environ [ '<STR_LIT>' ] = old_ppath <EOL> else : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> def test_setup_requires ( self ) : <EOL> """<STR_LIT>""" <EOL> test_setup_attrs = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ os . path . abspath ( self . dir ) ] <EOL> } <EOL> test_pkg = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> test_setup_py = os . path . join ( test_pkg , '<STR_LIT>' ) <EOL> test_setup_cfg = os . path . join ( test_pkg , '<STR_LIT>' ) <EOL> os . mkdir ( test_pkg ) <EOL> f = open ( test_setup_py , '<STR_LIT:w>' ) <EOL> f . write ( textwrap . dedent ( """<STR_LIT>""" % test_setup_attrs ) ) <EOL> f . close ( ) <EOL> foobar_path = os . path . join ( self . dir , '<STR_LIT>' ) <EOL> make_trivial_sdist ( <EOL> foobar_path , <EOL> textwrap . dedent ( """<STR_LIT>""" ) ) <EOL> old_stdout = sys . stdout <EOL> old_stderr = sys . stderr <EOL> sys . stdout = StringIO . StringIO ( ) <EOL> sys . stderr = StringIO . StringIO ( ) <EOL> try : <EOL> reset_setup_stop_context ( <EOL> lambda : run_setup ( test_setup_py , [ '<STR_LIT>' ] ) <EOL> ) <EOL> except SandboxViolation : <EOL> self . fail ( '<STR_LIT>' ) <EOL> finally : <EOL> sys . stdout = old_stdout <EOL> sys . stderr = old_stderr <EOL> class TestSetupRequires ( unittest . TestCase ) : <EOL> def test_setup_requires_honors_fetch_params ( self ) : <EOL> """<STR_LIT>""" <EOL> p_index = setuptools . tests . server . MockServer ( ) <EOL> p_index . start ( ) <EOL> netloc = <NUM_LIT:1> <EOL> p_index_loc = urlparse . urlparse ( p_index . url ) [ netloc ] <EOL> if p_index_loc . endswith ( '<STR_LIT>' ) : <EOL> return <EOL> def install ( dist_file ) : <EOL> def install_at ( temp_install_dir ) : <EOL> def install_env ( ) : <EOL> ei_params = [ '<STR_LIT>' , p_index . url , <EOL> '<STR_LIT>' , p_index_loc , <EOL> '<STR_LIT>' , '<STR_LIT>' , temp_install_dir , <EOL> dist_file ] <EOL> def install_clean_reset ( ) : <EOL> def install_clean_argv ( ) : <EOL> self . assertRaises ( SystemExit , <EOL> easy_install_pkg . main , ei_params ) <EOL> argv_context ( install_clean_argv , [ '<STR_LIT>' ] ) <EOL> reset_setup_stop_context ( install_clean_reset ) <EOL> environment_context ( install_env , PYTHONPATH = temp_install_dir ) <EOL> tempdir_context ( install_at ) <EOL> self . create_sdist ( install ) <EOL> self . assertTrue ( <NUM_LIT:2> <= len ( p_index . requests ) <= <NUM_LIT:3> ) <EOL> self . assertEqual ( p_index . requests [ <NUM_LIT:0> ] . path , '<STR_LIT>' ) <EOL> def create_sdist ( self , installer ) : <EOL> """<STR_LIT>""" <EOL> def build_sdist ( dir ) : <EOL> dist_path = os . path . join ( dir , '<STR_LIT>' ) <EOL> make_trivial_sdist ( <EOL> dist_path , <EOL> textwrap . dedent ( """<STR_LIT>""" ) . lstrip ( ) ) <EOL> installer ( dist_path ) <EOL> tempdir_context ( build_sdist ) <EOL> def make_trivial_sdist ( dist_path , setup_py ) : <EOL> """<STR_LIT>""" <EOL> setup_py_file = tarfile . TarInfo ( name = '<STR_LIT>' ) <EOL> try : <EOL> MemFile = StringIO . BytesIO <EOL> except AttributeError : <EOL> MemFile = StringIO . StringIO <EOL> setup_py_bytes = MemFile ( setup_py . encode ( '<STR_LIT:utf-8>' ) ) <EOL> setup_py_file . size = len ( setup_py_bytes . getvalue ( ) ) <EOL> dist = tarfile . open ( dist_path , '<STR_LIT>' ) <EOL> try : <EOL> dist . addfile ( setup_py_file , fileobj = setup_py_bytes ) <EOL> finally : <EOL> dist . close ( ) <EOL> def tempdir_context ( f , cd = lambda dir : None ) : <EOL> """<STR_LIT>""" <EOL> temp_dir = tempfile . mkdtemp ( ) <EOL> orig_dir = os . getcwd ( ) <EOL> try : <EOL> cd ( temp_dir ) <EOL> f ( temp_dir ) <EOL> finally : <EOL> cd ( orig_dir ) <EOL> shutil . rmtree ( temp_dir ) <EOL> def environment_context ( f , ** updates ) : <EOL> """<STR_LIT>""" <EOL> old_env = os . environ . copy ( ) <EOL> os . environ . update ( updates ) <EOL> try : <EOL> f ( ) <EOL> finally : <EOL> for key in updates : <EOL> del os . environ [ key ] <EOL> os . environ . update ( old_env ) <EOL> def argv_context ( f , repl ) : <EOL> """<STR_LIT>""" <EOL> old_argv = sys . argv [ : ] <EOL> sys . argv [ : ] = repl <EOL> try : <EOL> f ( ) <EOL> finally : <EOL> sys . argv [ : ] = old_argv <EOL> def reset_setup_stop_context ( f ) : <EOL> """<STR_LIT>""" <EOL> setup_stop_after = distutils . core . _setup_stop_after <EOL> distutils . core . _setup_stop_after = None <EOL> try : <EOL> f ( ) <EOL> finally : <EOL> distutils . core . _setup_stop_after = setup_stop_after </s>
