[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests - __init__.py:1.2 testApplicationControl.py:1.2 testRuntimeInfo.py:1.2 testZopeVersion.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:28:25 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/OFS/ApplicationControl/tests
Added Files:
__init__.py testApplicationControl.py testRuntimeInfo.py
testZopeVersion.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests/__init__.py 1.1 => 1.2 ===
=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests/testApplicationControl.py 1.1 => 1.2 ===
+#
+# 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 Interface.Verify import verifyObject
+
+import time
+from Zope.App.OFS.ApplicationControl.ApplicationControl import \
+ ApplicationControl
+from Zope.App.OFS.ApplicationControl.IApplicationControl 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_plugins(self):
+ test_appctrl = self._Test__new()
+ assert_info = ( {'name':'foo', 'title':'I\'m a lumberjack'},
+ {'name':'bar', 'title':'and i feel fine.'},
+ {'name':'nudges', 'title':'The nudge'},
+ {'name':'dash', 'title':'The dash'} )
+
+ for info in assert_info:
+ test_appctrl.registerView(info['name'], info['title'])
+
+ test_info = test_appctrl.getListOfViews()
+ self.failUnlessEqual(assert_info, test_info)
+
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests/testRuntimeInfo.py 1.1 => 1.2 ===
+#
+# 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 Interface.Verify import verifyObject
+
+import os, sys, time
+from Zope.ComponentArchitecture import getService
+from Zope.App.OFS.ApplicationControl.IRuntimeInfo import IRuntimeInfo
+from Zope.App.OFS.ApplicationControl.ApplicationControl import \
+ ApplicationController
+from Zope.App.OFS.ApplicationControl.IZopeVersion 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.OFS.Services.ServiceManager.tests.PlacefulSetup\
+ import PlacefulSetup
+
+class Test(PlacefulSetup, TestCase):
+
+ def _Test__new(self):
+ from Zope.App.OFS.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 TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests/testZopeVersion.py 1.1 => 1.2 ===
+#
+# 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 Interface.Verify import verifyObject
+
+from Zope.App.OFS.ApplicationControl.IZopeVersion import IZopeVersion
+from Zope.App.OFS.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 TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')