/usr/share/pyshared/zope/applicationcontrol/tests/test_runtimeinfo.py is in python-zope.applicationcontrol 3.5.5-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | ##############################################################################
#
# 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.1 (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.
##############################################################################
"""Runtime Info Tests
$Id: test_runtimeinfo.py 107931 2010-01-09 14:42:28Z faassen $
"""
import unittest
import os, sys, time
try:
import locale
except ImportError:
locale = None
from zope import component
from zope.interface import implements
from zope.interface.verify import verifyObject
from zope.applicationcontrol.applicationcontrol import applicationController
from zope.applicationcontrol.interfaces import IRuntimeInfo, IZopeVersion
# seconds, time values may differ in order to be assumed equal
time_tolerance = 2
stupid_version_string = "3085t0klvn93850voids"
class TestZopeVersion(object):
"""A fallback implementation for the ZopeVersion utility."""
implements(IZopeVersion)
def getZopeVersion(self):
return stupid_version_string
class Test(unittest.TestCase):
def _Test__new(self):
from zope.applicationcontrol.runtimeinfo import RuntimeInfo
return RuntimeInfo(applicationController)
def _getPreferredEncoding(self):
if locale is not None:
try:
return locale.getpreferredencoding()
except locale.Error:
pass
return sys.getdefaultencoding()
def _getFileSystemEncoding(self):
enc = sys.getfilesystemencoding()
if enc is None:
enc = self._getPreferredEncoding()
return enc
def testIRuntimeInfoVerify(self):
verifyObject(IRuntimeInfo, self._Test__new())
def test_PreferredEncoding(self):
runtime_info = self._Test__new()
enc = self._getPreferredEncoding()
self.assertEqual(runtime_info.getPreferredEncoding(), enc)
def test_FileSystemEncoding(self):
runtime_info = self._Test__new()
enc = self._getFileSystemEncoding()
self.assertEqual(runtime_info.getFileSystemEncoding(), enc)
def test_ZopeVersion(self):
runtime_info = self._Test__new()
# we expect that there is no utility
self.assertEqual(runtime_info.getZopeVersion(), u"Unavailable")
siteManager = component.getSiteManager()
siteManager.registerUtility(TestZopeVersion(), IZopeVersion)
self.assertEqual(runtime_info.getZopeVersion(), stupid_version_string)
def test_PythonVersion(self):
runtime_info = self._Test__new()
enc = self._getPreferredEncoding()
self.assertEqual(runtime_info.getPythonVersion(),
unicode(sys.version, enc))
def test_SystemPlatform(self):
runtime_info = self._Test__new()
self.failUnless(runtime_info.getSystemPlatform())
def test_CommandLine(self):
runtime_info = self._Test__new()
self.assertEqual(runtime_info.getCommandLine(), " ".join(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 unittest.TestSuite((
unittest.makeSuite(Test),
))
if __name__ == '__main__':
unittest.main()
|