[Checkins] SVN: zc.zeoinputlog/branches/dev/ Added missing tests and fixed a bug that caused the state to get

Jim Fulton jim at zope.com
Tue Sep 8 05:50:58 EDT 2009


Log message for revision 103630:
  Added missing tests and fixed a bug that caused the state to get
  messed up if the base path didn't exist.
  

Changed:
  U   zc.zeoinputlog/branches/dev/buildout.cfg
  U   zc.zeoinputlog/branches/dev/setup.py
  A   zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/README.test
  U   zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/__init__.py
  A   zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/tests.py

-=-
Modified: zc.zeoinputlog/branches/dev/buildout.cfg
===================================================================
--- zc.zeoinputlog/branches/dev/buildout.cfg	2009-09-08 08:33:25 UTC (rev 103629)
+++ zc.zeoinputlog/branches/dev/buildout.cfg	2009-09-08 09:50:58 UTC (rev 103630)
@@ -4,7 +4,7 @@
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = 
+eggs = zc.zeoinputlog
 
 [py]
 recipe = zc.recipe.egg

Modified: zc.zeoinputlog/branches/dev/setup.py
===================================================================
--- zc.zeoinputlog/branches/dev/setup.py	2009-09-08 08:33:25 UTC (rev 103629)
+++ zc.zeoinputlog/branches/dev/setup.py	2009-09-08 09:50:58 UTC (rev 103630)
@@ -13,7 +13,10 @@
 ##############################################################################
 name, version = 'zc.zeoinputlog', '0.1'
 
-install_requires = ['setuptools']
+install_requires = [
+    'setuptools',
+    'ZODB3 >=3.9.0dev, <3.10.0dev',
+    ]
 extras_require = dict(test=['zope.testing'])
 
 entry_points = """

Added: zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/README.test
===================================================================
--- zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/README.test	                        (rev 0)
+++ zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/README.test	2009-09-08 09:50:58 UTC (rev 103630)
@@ -0,0 +1,119 @@
+The zc.zeoinputlog package provides a mechanism to log ZEO network input
+========================================================================
+
+The mechanism consists of a zc.monitor plugin that provides control
+and a monkeypatch of
+ZEO.zrpc.connection.ManagedServerConnection.Message_input method.
+
+Hopefully, a future version of ZEO will meke the monkey patch
+unnecessary.
+
+This test tests the zc.monitor plugin and tests the monkey patch using
+a monkey oatch of our our own. (ook)
+
+    >>> def base_message_input_ook(self, message):
+    ...     print 'base message input', `message`
+
+    >>> import ZEO.zrpc.connection
+    >>> base_message_input = ZEO.zrpc.connection.Connection.message_input
+    >>> base_init = ZEO.zrpc.connection.Connection.__init__
+    >>> ZEO.zrpc.connection.Connection.message_input = base_message_input_ook
+    >>> ZEO.zrpc.connection.Connection.__init__ = lambda *a: None
+    >>> 'message_input' in ZEO.zrpc.connection.ManagedServerConnection.__dict__
+    False
+
+    >>> connection = ZEO.zrpc.connection.ManagedServerConnection(*'1234')
+    >>> connection.message_input('test')
+    base message input 'test'
+
+Now, we're ready to try out our monitor plugin.
+
+    >>> import sys, zc.zeoinputlog
+    >>> from zc.zeoinputlog import log
+
+Calling the logger without arguments just outouts the current state,
+which is disabled:
+
+    >>> log(sys.stdout)
+    disabled
+
+The zc.zeoinputlog module has a base attribute saying where to create
+log files.  Let's set it to a non-existent directory:
+
+    >>> zc.zeoinputlog.base = 'base'
+
+If we try to enable logging, we'll get an error:
+
+    >>> log(sys.stdout, 'enable')
+    Traceback (most recent call last):
+    ...
+    IOError: [Errno 2] No such file or directory: 'base/090908090305'
+
+    >>> 'message_input' in ZEO.zrpc.connection.ManagedServerConnection.__dict__
+    False
+    >>> log(sys.stdout)
+    disabled
+
+If create the directory, we'll be able to enable logging:
+
+    >>> import os
+    >>> os.mkdir('base')
+    >>> log(sys.stdout, 'enable')
+    enabled 'base/090908090306'
+    >>> connection.message_input('test')
+    base message input 'test'
+    >>> connection.message_input('test2')
+    base message input 'test2'
+    >>> log(sys.stdout)
+    'base/090908090306'
+
+If enable again, we'll get a new log file:
+
+    >>> log(sys.stdout, 'enable')
+    disabled 'base/090908090306'
+    enabled 'base/090908090309'
+    >>> log(sys.stdout)
+    'base/090908090309'
+    >>> connection.message_input('test3')
+    base message input 'test3'
+    >>> connection.message_input('test4')
+    base message input 'test4'
+
+If we disable, we'll stop logging
+
+    >>> log(sys.stdout, 'disable')
+    disabled 'base/090908090309'
+    >>> log(sys.stdout)
+    disabled
+    >>> log(sys.stdout, 'disable')
+    Already disabled
+
+    >>> 'message_input' in ZEO.zrpc.connection.ManagedServerConnection.__dict__
+    False
+    >>> connection.message_input('test5')
+    base message input 'test5'
+    >>> connection.message_input('test6')
+    base message input 'test6'
+
+The log files contain marshals:
+
+    >>> import marshal
+    >>> for p in ('base/090908090306', 'base/090908090309'):
+    ...     print p
+    ...     f = open(p)
+    ...     while 1:
+    ...         try:
+    ...             i, t, m = marshal.load(f)
+    ...             print (i==id(connection), t, m)
+    ...         except EOFError: break
+    base/090908090306
+    (True, 1252400587.910615, 'test')
+    (True, 1252400588.910615, 'test2')
+    base/090908090309
+    (True, 1252400590.910615, 'test3')
+    (True, 1252400591.910615, 'test4')
+
+Restore the monkey patches:
+
+    >>> ZEO.zrpc.connection.Connection.message_input = base_message_input
+    >>> ZEO.zrpc.connection.Connection.__init__ = base_init


Property changes on: zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/README.test
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/__init__.py
===================================================================
--- zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/__init__.py	2009-09-08 08:33:25 UTC (rev 103629)
+++ zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/__init__.py	2009-09-08 09:50:58 UTC (rev 103630)
@@ -15,7 +15,7 @@
     global path
 
     if action is None:
-        connection.write("%r\n" % path)
+        connection.write(path and ("%r\n" % path) or 'disabled')
         return
 
     if action == 'disable':
@@ -33,9 +33,11 @@
     if path:
         log(connection, 'disable')
 
-    path = os.path.join(base, time.strftime("%y%m%d%H%M%S", time.gmtime()))
+    _path = os.path.join(base, time.strftime("%y%m%d%H%M%S",
+                                             time.gmtime(time.time())))
 
-    log_file = open(path, 'w')
+    log_file = open(_path, 'w')
+    path = _path
     base_message_input = ZEO.zrpc.connection.Connection.message_input
     dump = marshal.dump
     timetime = time.time

Added: zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/tests.py
===================================================================
--- zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/tests.py	                        (rev 0)
+++ zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/tests.py	2009-09-08 09:50:58 UTC (rev 103630)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation 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 time
+import unittest
+from zope.testing import doctest, setupstack
+
+_now = 1252400584.910615
+def now():
+    global _now
+    _now += 1
+    return _now
+time_time = time.time
+
+def setUp(test):
+    setupstack.setUpDirectory(test)
+    setupstack.register(test, setattr, time, 'time', time_time)
+    time.time = now
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite(
+            'README.test',
+            setUp=setUp, tearDown=setupstack.tearDown),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+


Property changes on: zc.zeoinputlog/branches/dev/src/zc/zeoinputlog/tests.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the checkins mailing list