[Zope3-checkins] CVS: Zope3/src/zope/app/applicationcontrol/tests - __init__.py:1.2 test_applicationcontrol.py:1.2 test_iservercontrol.py:1.2 test_runtimeinfo.py:1.2 test_zopeversion.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:57 -0500


Update of /cvs-repository/Zope3/src/zope/app/applicationcontrol/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/applicationcontrol/tests

Added Files:
	__init__.py test_applicationcontrol.py test_iservercontrol.py 
	test_runtimeinfo.py test_zopeversion.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/applicationcontrol/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/tests/__init__.py	Wed Dec 25 09:12:26 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/applicationcontrol/tests/test_applicationcontrol.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/tests/test_applicationcontrol.py	Wed Dec 25 09:12:26 2002
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+##############################################################################
+"""
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interface.verify import verifyObject
+
+import time
+from zope.app.applicationcontrol.applicationcontrol import \
+  ApplicationControl
+from zope.app.interfaces.applicationcontrol.applicationcontrol import \
+  IApplicationControl
+
+# seconds, time values may differ in order to be assumed equal
+time_tolerance = 2
+
+#############################################################################
+# If your tests change any global registries, then uncomment the
+# following import and include CleanUp as a base class of your
+# test. It provides a setUp and tearDown that clear global data that
+# has registered with the test cleanup framework.  Don't use this
+# tests outside the Zope package.
+
+# from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+
+#############################################################################
+
+class Test(TestCase):
+
+    def _Test__new(self):
+        return ApplicationControl()
+
+    ############################################################
+    # Interface-driven tests:
+
+    def test_IVerify(self):
+        verifyObject(IApplicationControl, self._Test__new())
+
+    def test_startTime(self):
+        assert_time = time.time()
+        test_time = self._Test__new().getStartTime()
+
+        self.failUnless(abs(assert_time - test_time) < time_tolerance)
+
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/applicationcontrol/tests/test_iservercontrol.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/tests/test_iservercontrol.py	Wed Dec 25 09:12:26 2002
@@ -0,0 +1,75 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+##############################################################################
+"""
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interface.verify import verifyObject
+
+from zope.app.interfaces.applicationcontrol.servercontrol import \
+ IServerControl, DoublePriorityError, NotCallableError
+
+
+#############################################################################
+# If your tests change any global registries, then uncomment the
+# following import and include CleanUp as a base class of your
+# test. It provides a setUp and tearDown that clear global data that
+# has registered with the test cleanup framework.  Don't use this
+# tests outside the Zope package.
+
+# from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+
+#############################################################################
+
+def stub_callback():
+    """stupid callable object"""
+    pass
+
+class BaseTestIServerControl:
+    """Base test cases for ServerControllers.
+
+       Subclasses need to define a method, '_Test__new', that
+       takes no arguments and that returns a new empty test ServerController.
+    """
+
+    ############################################################
+    # Interface-driven tests:
+
+    def test_IVerify(self):
+        verifyObject(IServerControl, self._Test__new())
+
+    def test_registerShutdownHook(self):
+        server_control = self._Test__new()
+
+        # Try to register a noncallable object
+        self.assertRaises(NotCallableError,
+              server_control.registerShutdownHook, None, 10, "test")
+
+        # Try to register a priority for a second time
+        server_control.registerShutdownHook(stub_callback, 10, "Test")
+        self.assertRaises(DoublePriorityError,
+              server_control.registerShutdownHook, stub_callback, 10, "test2")
+
+class Test(BaseTestIServerControl, TestCase):
+    def _Test__new(self):
+        from zope.app.applicationcontrol.servercontrol \
+           import ServerControl
+        return ServerControl()
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/applicationcontrol/tests/test_runtimeinfo.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:57 2002
+++ Zope3/src/zope/app/applicationcontrol/tests/test_runtimeinfo.py	Wed Dec 25 09:12:26 2002
@@ -0,0 +1,101 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interface.verify import verifyObject
+
+import os, sys, time
+from zope.component import getService
+from zope.app.interfaces.applicationcontrol.runtimeinfo import IRuntimeInfo
+from zope.app.applicationcontrol.applicationcontrol import \
+  applicationController
+from zope.app.interfaces.applicationcontrol.zopeversion import IZopeVersion
+
+# seconds, time values may differ in order to be assumed equal
+time_tolerance = 2
+stupid_version_string = "3085t0klvn93850voids"
+
+class TestZopeVersion:
+    """A fallback implementation for the ZopeVersion utility."""
+
+    __implements__ = IZopeVersion
+
+    def getZopeVersion(self):
+        return stupid_version_string
+
+from zope.app.services.tests.placefulsetup\
+           import PlacefulSetup
+
+class Test(PlacefulSetup, TestCase):
+
+    def _Test__new(self):
+        from zope.app.applicationcontrol.runtimeinfo import RuntimeInfo
+        return RuntimeInfo(applicationController)
+
+    ############################################################
+    # Interface-driven tests:
+
+    def testIRuntimeInfoVerify(self):
+        verifyObject(IRuntimeInfo, self._Test__new())
+
+    def test_ZopeVersion(self):
+        runtime_info = self._Test__new()
+
+        # we expect that there is no utility
+        self.assertEqual(runtime_info.getZopeVersion(), "")
+
+        getService(None,'Utilities').provideUtility(IZopeVersion,
+                                               TestZopeVersion())
+        self.assertEqual(runtime_info.getZopeVersion(),
+                                         stupid_version_string)
+    def test_PythonVersion(self):
+        runtime_info = self._Test__new()
+        self.assertEqual(runtime_info.getPythonVersion(), sys.version)
+
+    def test_SystemPlatform(self):
+        runtime_info = self._Test__new()
+        test_platform = (sys.platform,)
+        if hasattr(os, "uname"):
+            test_platform = os.uname()
+        self.assertEqual(runtime_info.getSystemPlatform(), test_platform)
+
+    def test_CommandLine(self):
+        runtime_info = self._Test__new()
+        self.assertEqual(runtime_info.getCommandLine(), sys.argv)
+
+    def test_ProcessId(self):
+        runtime_info = self._Test__new()
+        self.assertEqual(runtime_info.getProcessId(), os.getpid())
+
+    def test_Uptime(self):
+        runtime_info = self._Test__new()
+        # whats the uptime we expect?
+
+        start_time = applicationController.getStartTime()
+        asserted_uptime = time.time() - start_time
+
+        # get the uptime the current implementation calculates
+        test_uptime = runtime_info.getUptime()
+
+        self.failUnless(abs(asserted_uptime - test_uptime) < time_tolerance)
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/applicationcontrol/tests/test_zopeversion.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:57 2002
+++ Zope3/src/zope/app/applicationcontrol/tests/test_zopeversion.py	Wed Dec 25 09:12:26 2002
@@ -0,0 +1,89 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interface.verify import verifyObject
+
+from zope.app.interfaces.applicationcontrol.zopeversion import IZopeVersion
+from zope.app.applicationcontrol.zopeversion import ZopeVersion
+import os
+
+
+#############################################################################
+# If your tests change any global registries, then uncomment the
+# following import and include CleanUp as a base class of your
+# test. It provides a setUp and tearDown that clear global data that
+# has registered with the test cleanup framework.  Don't use this
+# tests outside the Zope package.
+
+# from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+
+#############################################################################
+
+class Test(TestCase):
+
+    def _Test__new(self):
+        return ZopeVersion()
+
+    def _getZopeVersion(self):
+        """example zope version implementation
+        """
+        version_id = "Development/Unknown"
+        version_tag = ""
+        is_cvs = 0
+
+        import zope
+        zopedir = os.path.dirname(zope.__file__)
+
+        # is this a CVS checkout?
+        cvsdir = os.path.join(zopedir, "CVS" )
+        if os.path.isdir(cvsdir):
+            is_cvs = 1
+            tagfile = os.path.join(cvsdir, "Tag")
+
+            # get the tag information
+            if os.path.isfile(tagfile):
+                f = open(tagfile)
+                tag = f.read()
+                if tag.startswith("T"):
+                    version_tag = " (%s)" % tag[1:-1]
+
+        # try to get official Zope release information
+        versionfile = os.path.join(zopedir, "version.txt")
+        if os.path.isfile(versionfile) and not is_cvs:
+            f = open(versionfile)
+            version_id = f.read().split("\n")[0]
+
+        version = "%s%s" % (version_id, version_tag)
+        return version
+
+    def test_IVerify(self):
+        verifyObject(IZopeVersion, self._Test__new())
+
+    def test_ZopeVersion(self):
+        zope_version = self._Test__new()
+        self.assertEqual(zope_version.getZopeVersion(), self._getZopeVersion())
+
+
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')