[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests - testRuntimeInfo.py:1.1.2.1

Philipp von Weitershausen philikon@gmx.net
Tue, 9 Apr 2002 09:57:56 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests
In directory cvs.zope.org:/tmp/cvs-serv22029/tests

Added Files:
      Tag: Zope-3x-branch
	testRuntimeInfo.py 
Log Message:
- introduced the IRuntimeInfo interface and adapter to be used for the 
  first ApplicationControl view


=== Added File Zope3/lib/python/Zope/App/OFS/ApplicationControl/tests/testRuntimeInfo.py ===
##############################################################################
#
# 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: testRuntimeInfo.py,v 1.1.2.1 2002/04/09 13:57:55 philikon Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Interface.Verify import verifyObject

import os, sys, time
from Zope.ComponentArchitecture import getUtility, provideUtility
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 = 3
stupid_version_string = "3085t0klvn93850voids"

class TestZopeVersion:
    """A fallback implementation for the ZopeVersion utility."""

    __implements__ = IZopeVersion

    def getZopeVersion(self):
        return stupid_version_string


#############################################################################
# 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):
        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(), "")
        
        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()
        self.assertEqual(runtime_info.getSystemPlatform(), os.uname())

    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_Environment(self):
        runtime_info = self._Test__new()

        self.assertEqual(runtime_info.getEnvironment(), os.environ)

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')