[Zope3-checkins] SVN: zope.testing/branches/tim-pyc/src/zope/testing/testrunner Added tests for --usecommit.

Tim Peters tim.one at comcast.net
Wed Sep 28 17:09:14 EDT 2005


Log message for revision 38670:
  Added tests for --usecommit.
  

Changed:
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/README.txt
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/__init__.py
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/compiletest.py
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/__init__.py
  A   zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/compiletest.py
  U   zope.testing/branches/tim-pyc/src/zope/testing/testrunner.txt

-=-
Added: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/README.txt
===================================================================
--- zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/README.txt	2005-09-28 19:58:12 UTC (rev 38669)
+++ zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/README.txt	2005-09-28 21:09:14 UTC (rev 38670)
@@ -0,0 +1,2 @@
+The tests in this subtree are trivial, and used only to test
+testrunner's --usecompiled option.


Property changes on: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/__init__.py
===================================================================
--- zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/__init__.py	2005-09-28 19:58:12 UTC (rev 38669)
+++ zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/__init__.py	2005-09-28 21:09:14 UTC (rev 38670)
@@ -0,0 +1 @@
+# Makes this a package.


Property changes on: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/compiletest.py
===================================================================
--- zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/compiletest.py	2005-09-28 19:58:12 UTC (rev 38669)
+++ zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/compiletest.py	2005-09-28 21:09:14 UTC (rev 38670)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import unittest
+
+class Test(unittest.TestCase):
+
+    def test1(self):
+        self.assertEqual(1, 1)
+    def test2(self):
+        self.assertEqual(1, 1)
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(Test))
+    return suite


Property changes on: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/compiletest.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/__init__.py
===================================================================
--- zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/__init__.py	2005-09-28 19:58:12 UTC (rev 38669)
+++ zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/__init__.py	2005-09-28 21:09:14 UTC (rev 38670)
@@ -0,0 +1 @@
+# Makes this a package.


Property changes on: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/compiletest.py
===================================================================
--- zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/compiletest.py	2005-09-28 19:58:12 UTC (rev 38669)
+++ zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/compiletest.py	2005-09-28 21:09:14 UTC (rev 38670)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import unittest
+
+class Test(unittest.TestCase):
+
+    def test1(self):
+        self.assertEqual(1, 1)
+    def test2(self):
+        self.assertEqual(1, 1)
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(Test))
+    return suite


Property changes on: zope.testing/branches/tim-pyc/src/zope/testing/testrunner-ex/usecompiled/package/compiletest.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zope.testing/branches/tim-pyc/src/zope/testing/testrunner.txt
===================================================================
--- zope.testing/branches/tim-pyc/src/zope/testing/testrunner.txt	2005-09-28 19:58:12 UTC (rev 38669)
+++ zope.testing/branches/tim-pyc/src/zope/testing/testrunner.txt	2005-09-28 21:09:14 UTC (rev 38670)
@@ -1926,3 +1926,81 @@
 
     >>> import shutil
     >>> shutil.rmtree('coverage_dir')
+
+Running Without Source Code
+---------------------------
+
+The ``--usecompiled`` option allows running tests in a tree without .py
+source code, provided compiled .pyc or .pyo files exist (without
+``--usecompiled``, .py files are necessary).
+
+We have a very simple directory tree, under ``usecompiled/``, to test
+this.  Because we're going to delete its .py files, we want to work
+in a copy of that:
+
+    >>> NEWNAME = "unlikely_package_name"
+    >>> src = os.path.join(this_directory, 'testrunner-ex', 'usecompiled')
+    >>> os.path.isdir(src)
+    True
+    >>> dst = os.path.join(this_directory, 'testrunner-ex', NEWNAME)
+    >>> os.path.isdir(dst)
+    False
+    >>> shutil.copytree(src, dst)
+    >>> os.path.isdir(dst)
+    True
+
+Now run the tests in the copy:
+
+    >>> mydefaults = [
+    ...     '--path', directory_with_tests,
+    ...     '--tests-pattern', '^compiletest$',
+    ...     '--package', NEWNAME,
+    ...     '-vv',
+    ...     ]
+    >>> sys.argv = ['test']
+    >>> testrunner.run(mydefaults)
+    Running tests at level 1
+    Running unit tests:
+      Running:
+        test1 (unlikely_package_name.compiletest.Test)
+        test2 (unlikely_package_name.compiletest.Test)
+        test1 (unlikely_package_name.package.compiletest.Test)
+        test2 (unlikely_package_name.package.compiletest.Test)
+      Ran 4 tests with 0 failures and 0 errors in N.NNN seconds.
+    False
+
+If we delete the source files, it's normally a disaster (the test runner
+doesn't believe any test files, or even packages, exist).  Note that we
+pass ``--keepbytecode`` this time, because otherwise the testrunner would
+delete the compiled Python files too:
+
+    >>> for root, dirs, files in os.walk(dst):
+    ...    dirs[:] = [d for d in dirs if d == "package"] # prune cruft
+    ...    for f in files:
+    ...        if f.endswith(".py"):
+    ...            os.remove(os.path.join(root, f))
+    >>> testrunner.run(mydefaults, ["test", "--keepbytecode"])
+    Running tests at level 1
+    Total: 0 tests, 0 failures, 0 errors
+    False
+
+Finally, passing ``--usecompiled`` asks the test runner to treat .pyc
+and .pyo files as adequate replacements for .py files.  Note that the
+output is the same as when running with .py source above.  The absence
+of "removing stale bytecode ..." messages shows that ``--usecompiled``
+also implies ``--keepbytecode``:
+
+    >>> testrunner.run(mydefaults, ["test", "--usecompiled"])
+    Running tests at level 1
+    Running unit tests:
+      Running:
+        test1 (unlikely_package_name.compiletest.Test)
+        test2 (unlikely_package_name.compiletest.Test)
+        test1 (unlikely_package_name.package.compiletest.Test)
+        test2 (unlikely_package_name.package.compiletest.Test)
+      Ran 4 tests with 0 failures and 0 errors in N.NNN seconds.
+    False
+
+Remove the copy:
+
+    >>> shutil.rmtree(dst)



More information about the Zope3-Checkins mailing list