Commits

Ronald Oussoren committed 11be5f1

Ensure that "python setup.py test" actually works

The py2app_tests package must contain code that works in both
2.x and 3.x for now, 2to3 support can be added later when
needed.

  • Participants
  • Parent commits cda6590

Comments (0)

Files changed (4)

py2app_tests/basic_app/__init__.py

-"""dummy init file to trick 2to3"""

py2app_tests/basic_app/main.py

 
 def import_module(name):
     try:
-        exec "import %s"%(name,)
+        exec ("import %s"%(name,))
         m = eval(name)
-    except ImportError, msg:
-        print "* import failed"
+    except ImportError:
+        print ("* import failed")
 
     else:
         for k in name.split('.')[1:]:
             m = getattr(m, k)
-        print m.__name__
+        print (m.__name__)
 
 
 while True:
         break
 
     try:
-        exec line
+        exec (line)
     except SystemExit:
         raise
 
-    except Exception, e:
-        print "* Exception", e
+    except Exception:
+        print ("* Exception " + str(sys.exc_info()[1]))
 
     sys.stdout.flush()
     sys.stderr.flush()

py2app_tests/test_basic_app.py

         return p
 
     def wait_with_timeout(self, proc, timeout=10):
-        for i in xrange(timeout):
+        for i in range(timeout):
             x = proc.poll()
             if x is None:
                 time.sleep(1)
 from distutils.core import PyPIRCCommand
 from distutils.errors  import DistutilsError
 from distutils import log
-
-from pkg_resources import require, DistributionNotFound
+from setuptools.command import test
 
 LONG_DESCRIPTION = open('README.txt').read()
 LONG_DESCRIPTION += '\n' + open('doc/changelog.rst').read()
 else:
     extra_args = dict()
 
+
+
+def test_loader():
+    import unittest
+
+    topdir = os.path.dirname(os.path.abspath(__file__))
+    testModules = [ fn[:-3] for fn in os.listdir(os.path.join(topdir, 'py2app_tests')) if fn.endswith('.py')]
+    sys.path.insert(0, os.path.join(topdir, 'py2app_tests'))
+
+    suites = []
+    for modName in testModules:
+        try:
+            module = __import__(modName)
+        except ImportError:
+            print ("SKIP %s: %s"%(modName, sys.exc_info[1]))
+            continue
+
+        s = unittest.defaultTestLoader.loadTestsFromModule(module)
+        suites.append(s)
+
+    return unittest.TestSuite(suites)
+
 class upload_docs (PyPIRCCommand):
     description = "upload sphinx documentation"
     user_options = PyPIRCCommand.user_options
     cmdclass=dict(
         upload_docs=upload_docs,
     ),
-    packages=find_packages(),
+    packages=find_packages(exclude=['py2app_tests']),
     package_data={
         'py2app.apptemplate': [
             'prebuilt/main-i386',
         ]
     },
     zip_safe=False,
-    # workaround for setuptools 0.6b4 bug
-    dependency_links=[],
-    test_suite='py2app_tests',
+    dependency_links=[], # workaround for setuptools 0.6b4 bug
+    test_suite='__main__.test_loader',
     **extra_args
 )