importsysimportosimporttempfileimportunittestimportshutilimportcopyCURDIR=os.path.abspath(os.path.dirname(__file__))TOPDIR=os.path.split(CURDIR)[0]sys.path.insert(0,TOPDIR)fromdistribute_setupimport(use_setuptools,_build_egg,_python_cmd,_do_download,_install,DEFAULT_URL,DEFAULT_VERSION)importdistribute_setupclassTestSetup(unittest.TestCase):defurlopen(self,url):returnopen(self.tarball)defsetUp(self):self.old_sys_path=copy.copy(sys.path)self.cwd=os.getcwd()self.tmpdir=tempfile.mkdtemp()os.chdir(TOPDIR)_python_cmd("setup.py","-q","egg_info","-RDb","''","sdist","--dist-dir","%s"%self.tmpdir)tarball=os.listdir(self.tmpdir)[0]self.tarball=os.path.join(self.tmpdir,tarball)importurllib2urllib2.urlopen=self.urlopendeftearDown(self):shutil.rmtree(self.tmpdir)os.chdir(self.cwd)sys.path=copy.copy(self.old_sys_path)deftest_build_egg(self):# making it an eggegg=_build_egg(self.tarball,self.tmpdir)# now trying to import itsys.path[0]=eggimportsetuptoolsself.assert_(setuptools.__file__.startswith(egg))deftest_do_download(self):tmpdir=tempfile.mkdtemp()_do_download(DEFAULT_VERSION,DEFAULT_URL,tmpdir,1)importsetuptoolsself.assert_(setuptools.bootstrap_install_from.startswith(tmpdir))deftest_install(self):def_faked(*args):returnTruedistribute_setup.python_cmd=_faked_install(self.tarball)deftest_use_setuptools(self):self.assertEquals(use_setuptools(),None)# make sure fake_setuptools is not called by defaultimportpkg_resourcesdelpkg_resources._distributedeffake_setuptools(*args):raiseAssertionErrorpkg_resources._fake_setuptools=fake_setuptoolsuse_setuptools()if__name__=='__main__':unittest.main()