summaryrefslogtreecommitdiff
path: root/setuptools/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2010-05-15 07:33:37 -1000
committerJason R. Coombs <jaraco@jaraco.com>2010-05-15 07:33:37 -1000
commit1fc291ffa0bdddb8869224a760f3af7ef5a45cf5 (patch)
treeca6c6b1e70f74b169bd6167d5c2aa81fbddb693d /setuptools/tests
parent4353f3f6eaabc04859bcbd592c58df985bd2ad3b (diff)
parentde6e3bcc3c77bff17a6609b31bc1b6a9212bbd88 (diff)
downloadpython-setuptools-git-1fc291ffa0bdddb8869224a760f3af7ef5a45cf5.tar.gz
Merged Fix for #151
--HG-- branch : distribute extra : rebase_source : 7f7f9c64a26c6110096387b9862e06455c49f2ec
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py64
-rw-r--r--setuptools/tests/test_develop.py24
-rw-r--r--setuptools/tests/test_easy_install.py96
-rw-r--r--setuptools/tests/test_resources.py38
-rw-r--r--setuptools/tests/test_sandbox.py11
-rw-r--r--setuptools/tests/test_upload_docs.py22
6 files changed, 186 insertions, 69 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index f540103e..4fb382ca 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -94,21 +94,21 @@ class DependsTests(TestCase):
from email import __version__
self.assertEqual(req.get_version(), __version__)
- self.failUnless(req.version_ok('1.0.9'))
- self.failIf(req.version_ok('0.9.1'))
- self.failIf(req.version_ok('unknown'))
+ self.assertTrue(req.version_ok('1.0.9'))
+ self.assertFalse(req.version_ok('0.9.1'))
+ self.assertFalse(req.version_ok('unknown'))
- self.failUnless(req.is_present())
- self.failUnless(req.is_current())
+ self.assertTrue(req.is_present())
+ self.assertTrue(req.is_current())
req = Require('Email 3000','03000','email',format=LooseVersion)
- self.failUnless(req.is_present())
- self.failIf(req.is_current())
- self.failIf(req.version_ok('unknown'))
+ self.assertTrue(req.is_present())
+ self.assertFalse(req.is_current())
+ self.assertFalse(req.version_ok('unknown'))
req = Require('Do-what-I-mean','1.0','d-w-i-m')
- self.failIf(req.is_present())
- self.failIf(req.is_current())
+ self.assertFalse(req.is_present())
+ self.assertFalse(req.is_current())
req = Require('Tests', None, 'tests', homepage="http://example.com")
self.assertEqual(req.format, None)
@@ -118,8 +118,8 @@ class DependsTests(TestCase):
self.assertEqual(req.homepage, 'http://example.com')
paths = [os.path.dirname(p) for p in __path__]
- self.failUnless(req.is_present(paths))
- self.failUnless(req.is_current(paths))
+ self.assertTrue(req.is_present(paths))
+ self.assertTrue(req.is_current(paths))
class DistroTests(TestCase):
@@ -137,7 +137,7 @@ class DistroTests(TestCase):
def testDistroType(self):
- self.failUnless(isinstance(self.dist,setuptools.dist.Distribution))
+ self.assertTrue(isinstance(self.dist,setuptools.dist.Distribution))
def testExcludePackage(self):
@@ -189,17 +189,17 @@ class DistroTests(TestCase):
dist.exclude(packages=['a'], py_modules=['b'], ext_modules=[self.e2])
def testContents(self):
- self.failUnless(self.dist.has_contents_for('a'))
+ self.assertTrue(self.dist.has_contents_for('a'))
self.dist.exclude_package('a')
- self.failIf(self.dist.has_contents_for('a'))
+ self.assertFalse(self.dist.has_contents_for('a'))
- self.failUnless(self.dist.has_contents_for('b'))
+ self.assertTrue(self.dist.has_contents_for('b'))
self.dist.exclude_package('b')
- self.failIf(self.dist.has_contents_for('b'))
+ self.assertFalse(self.dist.has_contents_for('b'))
- self.failUnless(self.dist.has_contents_for('c'))
+ self.assertTrue(self.dist.has_contents_for('c'))
self.dist.exclude_package('c')
- self.failIf(self.dist.has_contents_for('c'))
+ self.assertFalse(self.dist.has_contents_for('c'))
@@ -269,12 +269,12 @@ class FeatureTests(TestCase):
)
def testDefaults(self):
- self.failIf(
+ self.assertFalse(
Feature(
"test",standard=True,remove='x',available=False
).include_by_default()
)
- self.failUnless(
+ self.assertTrue(
Feature("test",standard=True,remove='x').include_by_default()
)
# Feature must have either kwargs, removes, or require_features
@@ -288,33 +288,33 @@ class FeatureTests(TestCase):
def testFeatureOptions(self):
dist = self.dist
- self.failUnless(
+ self.assertTrue(
('with-dwim',None,'include DWIM') in dist.feature_options
)
- self.failUnless(
+ self.assertTrue(
('without-dwim',None,'exclude DWIM (default)') in dist.feature_options
)
- self.failUnless(
+ self.assertTrue(
('with-bar',None,'include bar (default)') in dist.feature_options
)
- self.failUnless(
+ self.assertTrue(
('without-bar',None,'exclude bar') in dist.feature_options
)
self.assertEqual(dist.feature_negopt['without-foo'],'with-foo')
self.assertEqual(dist.feature_negopt['without-bar'],'with-bar')
self.assertEqual(dist.feature_negopt['without-dwim'],'with-dwim')
- self.failIf('without-baz' in dist.feature_negopt)
+ self.assertFalse('without-baz' in dist.feature_negopt)
def testUseFeatures(self):
dist = self.dist
self.assertEqual(dist.with_foo,1)
self.assertEqual(dist.with_bar,0)
self.assertEqual(dist.with_baz,1)
- self.failIf('bar_et' in dist.py_modules)
- self.failIf('pkg.bar' in dist.packages)
- self.failUnless('pkg.baz' in dist.packages)
- self.failUnless('scripts/baz_it' in dist.scripts)
- self.failUnless(('libfoo','foo/foofoo.c') in dist.libraries)
+ self.assertFalse('bar_et' in dist.py_modules)
+ self.assertFalse('pkg.bar' in dist.packages)
+ self.assertTrue('pkg.baz' in dist.packages)
+ self.assertTrue('scripts/baz_it' in dist.scripts)
+ self.assertTrue(('libfoo','foo/foofoo.c') in dist.libraries)
self.assertEqual(dist.ext_modules,[])
self.assertEqual(dist.require_features, [self.req])
@@ -331,7 +331,7 @@ class TestCommandTests(TestCase):
def testTestIsCommand(self):
test_cmd = makeSetup().get_command_obj('test')
- self.failUnless(isinstance(test_cmd, distutils.cmd.Command))
+ self.assertTrue(isinstance(test_cmd, distutils.cmd.Command))
def testLongOptSuiteWNoDefault(self):
ts1 = makeSetup(script_args=['test','--test-suite=foo.tests.suite'])
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py
index 1d5fa141..a567dd5a 100644
--- a/setuptools/tests/test_develop.py
+++ b/setuptools/tests/test_develop.py
@@ -6,8 +6,9 @@ import tempfile
import site
from StringIO import StringIO
+from distutils.errors import DistutilsError
from setuptools.command.develop import develop
-from setuptools.command import develop as develop_pkg
+from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
SETUP_PY = """\
@@ -28,9 +29,9 @@ class TestDevelopTest(unittest.TestCase):
os.chdir(self.dir)
if sys.version >= "2.6":
self.old_base = site.USER_BASE
- site.USER_BASE = develop_pkg.USER_BASE = tempfile.mkdtemp()
+ site.USER_BASE = tempfile.mkdtemp()
self.old_site = site.USER_SITE
- site.USER_SITE = develop_pkg.USER_SITE = tempfile.mkdtemp()
+ site.USER_SITE = tempfile.mkdtemp()
def tearDown(self):
os.chdir(self.old_cwd)
@@ -49,6 +50,7 @@ class TestDevelopTest(unittest.TestCase):
cmd = develop(dist)
cmd.user = 1
cmd.ensure_finalized()
+ cmd.install_dir = site.USER_SITE
cmd.user = 1
old_stdout = sys.stdout
sys.stdout = StringIO()
@@ -62,3 +64,19 @@ class TestDevelopTest(unittest.TestCase):
content.sort()
self.assertEquals(content, ['UNKNOWN.egg-link', 'easy-install.pth'])
+ def test_develop_with_setup_requires(self):
+
+ wanted = ("Could not find suitable distribution for "
+ "Requirement.parse('I-DONT-EXIST')")
+ old_dir = os.getcwd()
+ os.chdir(self.dir)
+ try:
+ try:
+ dist = Distribution({'setup_requires': ['I_DONT_EXIST']})
+ except DistutilsError, e:
+ error = str(e)
+ if error == wanted:
+ pass
+ finally:
+ os.chdir(old_dir)
+
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 95909ca7..e02798c6 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -2,8 +2,13 @@
"""
import sys
import os, shutil, tempfile, unittest
+import site
+from StringIO import StringIO
from setuptools.command.easy_install import easy_install, get_script_args, main
+from setuptools.command.easy_install import PthDistributions
+from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
+from pkg_resources import Distribution as PRDistribution
class FakeDist(object):
def get_entry_map(self, group):
@@ -90,3 +95,94 @@ class TestEasyInstallTest(unittest.TestCase):
os.chdir(old_wd)
shutil.rmtree(dir)
+ def test_no_find_links(self):
+ # new option '--no-find-links', that blocks find-links added at
+ # the project level
+ dist = Distribution()
+ cmd = easy_install(dist)
+ cmd.check_pth_processing = lambda : True
+ cmd.no_find_links = True
+ cmd.find_links = ['link1', 'link2']
+ cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
+ cmd.args = ['ok']
+ cmd.ensure_finalized()
+ self.assertEquals(cmd.package_index.scanned_urls, {})
+
+ # let's try without it (default behavior)
+ cmd = easy_install(dist)
+ cmd.check_pth_processing = lambda : True
+ cmd.find_links = ['link1', 'link2']
+ cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
+ cmd.args = ['ok']
+ cmd.ensure_finalized()
+ keys = cmd.package_index.scanned_urls.keys()
+ keys.sort()
+ self.assertEquals(keys, ['link1', 'link2'])
+
+
+class TestPTHFileWriter(unittest.TestCase):
+ def test_add_from_cwd_site_sets_dirty(self):
+ '''a pth file manager should set dirty
+ if a distribution is in site but also the cwd
+ '''
+ pth = PthDistributions('does-not_exist', [os.getcwd()])
+ self.assert_(not pth.dirty)
+ pth.add(PRDistribution(os.getcwd()))
+ self.assert_(pth.dirty)
+
+ def test_add_from_site_is_ignored(self):
+ pth = PthDistributions('does-not_exist', ['/test/location/does-not-have-to-exist'])
+ self.assert_(not pth.dirty)
+ pth.add(PRDistribution('/test/location/does-not-have-to-exist'))
+ self.assert_(not pth.dirty)
+
+
+class TestUserInstallTest(unittest.TestCase):
+
+ def setUp(self):
+ self.dir = tempfile.mkdtemp()
+ setup = os.path.join(self.dir, 'setup.py')
+ f = open(setup, 'w')
+ f.write(SETUP_PY)
+ f.close()
+ self.old_cwd = os.getcwd()
+ os.chdir(self.dir)
+ if sys.version >= "2.6":
+ self.old_base = site.USER_BASE
+ site.USER_BASE = tempfile.mkdtemp()
+ self.old_site = site.USER_SITE
+ site.USER_SITE = tempfile.mkdtemp()
+
+ def tearDown(self):
+ os.chdir(self.old_cwd)
+ shutil.rmtree(self.dir)
+ if sys.version >= "2.6":
+ shutil.rmtree(site.USER_BASE)
+ shutil.rmtree(site.USER_SITE)
+ site.USER_BASE = self.old_base
+ site.USER_SITE = self.old_site
+
+ def test_install(self):
+ #XXX: replace with something meaningfull
+ return
+ if sys.version < "2.6":
+ return
+ dist = Distribution()
+ dist.script_name = 'setup.py'
+ cmd = easy_install(dist)
+ cmd.user = 1
+ cmd.args = ['py']
+ cmd.ensure_finalized()
+ cmd.user = 1
+ old_stdout = sys.stdout
+ sys.stdout = StringIO()
+ try:
+ cmd.run()
+ finally:
+ sys.stdout = old_stdout
+
+ # let's see if we got our egg link at the right place
+ content = os.listdir(site.USER_SITE)
+ content.sort()
+ self.assertEquals(content, ['UNKNOWN.egg-link', 'easy-install.pth'])
+
diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py
index 5cb1baf0..c1dc4887 100644
--- a/setuptools/tests/test_resources.py
+++ b/setuptools/tests/test_resources.py
@@ -35,7 +35,7 @@ class DistroTests(TestCase):
ad.add(Distribution.from_filename("FooPkg-1.2-py2.4.egg"))
# Name is in there now
- self.failUnless(ad['FooPkg'])
+ self.assertTrue(ad['FooPkg'])
# But only 1 package
self.assertEqual(list(ad), ['foopkg'])
@@ -218,7 +218,7 @@ class EntryPointTests(TestCase):
self.assertEqual(ep.module_name,"setuptools.tests.test_resources")
self.assertEqual(ep.attrs, ("EntryPointTests",))
self.assertEqual(ep.extras, ("x",))
- self.failUnless(ep.load() is EntryPointTests)
+ self.assertTrue(ep.load() is EntryPointTests)
self.assertEqual(
str(ep),
"foo = setuptools.tests.test_resources:EntryPointTests [x]"
@@ -318,20 +318,20 @@ class RequirementsTests(TestCase):
foo_dist = Distribution.from_filename("FooPkg-1.3_1.egg")
twist11 = Distribution.from_filename("Twisted-1.1.egg")
twist12 = Distribution.from_filename("Twisted-1.2.egg")
- self.failUnless(parse_version('1.2') in r)
- self.failUnless(parse_version('1.1') not in r)
- self.failUnless('1.2' in r)
- self.failUnless('1.1' not in r)
- self.failUnless(foo_dist not in r)
- self.failUnless(twist11 not in r)
- self.failUnless(twist12 in r)
+ self.assertTrue(parse_version('1.2') in r)
+ self.assertTrue(parse_version('1.1') not in r)
+ self.assertTrue('1.2' in r)
+ self.assertTrue('1.1' not in r)
+ self.assertTrue(foo_dist not in r)
+ self.assertTrue(twist11 not in r)
+ self.assertTrue(twist12 in r)
def testAdvancedContains(self):
r, = parse_requirements("Foo>=1.2,<=1.3,==1.9,>2.0,!=2.5,<3.0,==4.5")
for v in ('1.2','1.2.2','1.3','1.9','2.0.1','2.3','2.6','3.0c1','4.5'):
- self.failUnless(v in r, (v,r))
+ self.assertTrue(v in r, (v,r))
for v in ('1.2c1','1.3.1','1.5','1.9.1','2.0','2.5','3.0','4.0'):
- self.failUnless(v not in r, (v,r))
+ self.assertTrue(v not in r, (v,r))
def testOptionsAndHashing(self):
@@ -353,14 +353,14 @@ class RequirementsTests(TestCase):
r2 = Requirement.parse("foo!=0.3a4")
d = Distribution.from_filename
- self.failIf(d("foo-0.3a4.egg") in r1)
- self.failIf(d("foo-0.3a1.egg") in r1)
- self.failIf(d("foo-0.3a4.egg") in r2)
+ self.assertFalse(d("foo-0.3a4.egg") in r1)
+ self.assertFalse(d("foo-0.3a1.egg") in r1)
+ self.assertFalse(d("foo-0.3a4.egg") in r2)
- self.failUnless(d("foo-0.3a2.egg") in r1)
- self.failUnless(d("foo-0.3a2.egg") in r2)
- self.failUnless(d("foo-0.3a3.egg") in r2)
- self.failUnless(d("foo-0.3a5.egg") in r2)
+ self.assertTrue(d("foo-0.3a2.egg") in r1)
+ self.assertTrue(d("foo-0.3a2.egg") in r2)
+ self.assertTrue(d("foo-0.3a3.egg") in r2)
+ self.assertTrue(d("foo-0.3a5.egg") in r2)
def testDistributeSetuptoolsOverride(self):
# Plain setuptools or distribute mean we return distribute.
@@ -480,7 +480,7 @@ class ParseTests(TestCase):
def testVersionOrdering(self):
def c(s1,s2):
p1, p2 = parse_version(s1),parse_version(s2)
- self.failUnless(p1<p2, (s1,s2,p1,p2))
+ self.assertTrue(p1<p2, (s1,s2,p1,p2))
c('2.1','2.1.1')
c('2a1','2b0')
diff --git a/setuptools/tests/test_sandbox.py b/setuptools/tests/test_sandbox.py
index 8b9e08e6..1609ee86 100644
--- a/setuptools/tests/test_sandbox.py
+++ b/setuptools/tests/test_sandbox.py
@@ -30,10 +30,11 @@ class TestSandbox(unittest.TestCase):
shutil.rmtree(self.dir)
def test_devnull(self):
+ if sys.version < '2.4':
+ return
sandbox = DirectorySandbox(self.dir)
sandbox.run(self._file_writer(os.devnull))
- @staticmethod
def _file_writer(path):
def do_write():
f = open(path, 'w')
@@ -41,6 +42,7 @@ class TestSandbox(unittest.TestCase):
f.close()
return do_write
+ _file_writer = staticmethod(_file_writer)
if has_win32com():
def test_win32com(self):
@@ -53,9 +55,10 @@ class TestSandbox(unittest.TestCase):
target = os.path.join(gen_py, 'test_write')
sandbox = DirectorySandbox(self.dir)
try:
- sandbox.run(self._file_writer(target))
- except SandboxViolation:
- self.fail("Could not create gen_py file due to SandboxViolation")
+ try:
+ sandbox.run(self._file_writer(target))
+ except SandboxViolation:
+ self.fail("Could not create gen_py file due to SandboxViolation")
finally:
if os.path.exists(target): os.remove(target)
diff --git a/setuptools/tests/test_upload_docs.py b/setuptools/tests/test_upload_docs.py
index 15db899f..8b2dc892 100644
--- a/setuptools/tests/test_upload_docs.py
+++ b/setuptools/tests/test_upload_docs.py
@@ -19,24 +19,24 @@ class TestUploadDocsTest(unittest.TestCase):
f.close()
self.old_cwd = os.getcwd()
os.chdir(self.dir)
-
+
self.upload_dir = os.path.join(self.dir, 'build')
os.mkdir(self.upload_dir)
-
+
# A test document.
f = open(os.path.join(self.upload_dir, 'index.html'), 'w')
f.write("Hello world.")
f.close()
-
+
# An empty folder.
os.mkdir(os.path.join(self.upload_dir, 'empty'))
-
+
if sys.version >= "2.6":
self.old_base = site.USER_BASE
site.USER_BASE = upload_docs.USER_BASE = tempfile.mkdtemp()
self.old_site = site.USER_SITE
site.USER_SITE = upload_docs.USER_SITE = tempfile.mkdtemp()
-
+
def tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.dir)
@@ -49,17 +49,17 @@ class TestUploadDocsTest(unittest.TestCase):
def test_create_zipfile(self):
# Test to make sure zipfile creation handles common cases.
# This explicitly includes a folder containing an empty folder.
-
+
dist = Distribution()
-
+
cmd = upload_docs(dist)
cmd.upload_dir = self.upload_dir
zip_file = cmd.create_zipfile()
-
+
assert zipfile.is_zipfile(zip_file)
-
+
zip_f = zipfile.ZipFile(zip_file) # woh...
-
+
assert zip_f.namelist() == ['index.html']
-
+