Lennart Regebro avatar Lennart Regebro committed 7b90633

Add failing test for #301.

Comments (0)

Files changed (2)

setuptools/command/test.py

         import unittest
         loader_ep = EntryPoint.parse("x="+self.test_loader)
         loader_class = loader_ep.load(require=False)
+        cks = loader_class()
         unittest.main(
             None, None, [unittest.__file__]+self.test_args,
-            testLoader = loader_class()
+            testLoader = cks
         )
 
 

setuptools/tests/test_test.py

+"""develop tests
+"""
+import sys
+import os, shutil, tempfile, unittest
+import tempfile
+import site
+from StringIO import StringIO
+
+from distutils.errors import DistutilsError
+from setuptools.command.test import test
+from setuptools.command import easy_install as easy_install_pkg
+from setuptools.dist import Distribution
+
+SETUP_PY = """\
+from setuptools import setup
+
+setup(name='foo')
+"""
+
+NS_INIT = """try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)
+"""
+TEST_PY = """import unittest
+
+class TestTest(unittest.TestCase):
+    def test_test(self):
+        print "Foo" # Should fail under Python 3 unless 2to3 is used
+
+test_suite = unittest.makeSuite(TestTest)
+"""
+
+class TestTestTest(unittest.TestCase):
+
+    def setUp(self):
+        if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
+            return
+
+        # Directory structure
+        self.dir = tempfile.mkdtemp()
+        os.mkdir(os.path.join(self.dir, 'name'))
+        os.mkdir(os.path.join(self.dir, 'name', 'space'))
+        os.mkdir(os.path.join(self.dir, 'name', 'space', 'tests'))
+        # setup.py
+        setup = os.path.join(self.dir, 'setup.py')
+        f = open(setup, 'w')
+        f.write(SETUP_PY)
+        f.close()
+        self.old_cwd = os.getcwd()
+        # name/__init__.py
+        init = os.path.join(self.dir, 'name', '__init__.py')
+        f = open(init, 'w')
+        f.write(NS_INIT)
+        f.close()
+        # name/space/__init__.py
+        init = os.path.join(self.dir, 'name', 'space', '__init__.py')
+        f = open(init, 'w')
+        f.write('#empty\n')
+        f.close()
+        # name/space/tests/__init__.py
+        init = os.path.join(self.dir, 'name', 'space', 'tests', '__init__.py')
+        f = open(init, 'w')
+        f.write(TEST_PY)
+        f.close()
+        
+        os.chdir(self.dir)
+        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):
+        if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
+            return
+        
+        os.chdir(self.old_cwd)
+        shutil.rmtree(self.dir)
+        shutil.rmtree(site.USER_BASE)
+        shutil.rmtree(site.USER_SITE)
+        site.USER_BASE = self.old_base
+        site.USER_SITE = self.old_site
+
+    def test_test(self):
+        if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
+            return
+        
+        dist = Distribution(dict(
+            script_name='setup.py',
+            script_args=['bdist_egg'],
+            name='foo',
+            py_modules=['name'],
+            namespace_packages=['name'],
+            test_suite='name.space.tests.test_suite',
+            ))
+        dist.script_name = 'setup.py'
+        cmd = test(dist)
+        cmd.user = 1
+        cmd.ensure_finalized()
+        cmd.install_dir = site.USER_SITE
+        cmd.user = 1
+        old_stdout = sys.stdout
+        sys.stdout = StringIO()
+        try:
+            cmd.run()
+        except SystemExit: # The test runner calls sys.exit, stop that making an error.
+            pass
+        finally:
+            sys.stdout = old_stdout
+
+test_suite = unittest.makeSuite(TestTestTest)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.