[Checkins] SVN: zc.monitor/branches/benji-add-sticky-commands/s - add tests for the MORE mode
Benji York
benji at zope.com
Tue Oct 27 15:55:51 EDT 2009
Log message for revision 105311:
- add tests for the MORE mode
- comment out a test that was failing when I branched from trunk
- nail the zc.ngi version to one that works; need to figure out why the
most recent zc.ngi doesn't work
Changed:
U zc.monitor/branches/benji-add-sticky-commands/setup.py
U zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/README.txt
U zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/tests.py
-=-
Modified: zc.monitor/branches/benji-add-sticky-commands/setup.py
===================================================================
--- zc.monitor/branches/benji-add-sticky-commands/setup.py 2009-10-27 19:30:56 UTC (rev 105310)
+++ zc.monitor/branches/benji-add-sticky-commands/setup.py 2009-10-27 19:55:51 UTC (rev 105311)
@@ -20,7 +20,7 @@
namespace_packages = ['zc'],
package_dir = {'': 'src'},
install_requires = [
- 'setuptools', 'zc.ngi', 'zope.component', 'zope.testing',
+ 'setuptools', 'zc.ngi==1.0.1', 'zope.component', 'zope.testing',
],
include_package_data = True,
zip_safe = False,
Modified: zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/README.txt
===================================================================
--- zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/README.txt 2009-10-27 19:30:56 UTC (rev 105310)
+++ zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/README.txt 2009-10-27 19:55:51 UTC (rev 105311)
@@ -20,10 +20,10 @@
>>> def hello(connection, name='world'):
... """Say hello
- ...
+ ...
... Provide a name if you're not the world.
... """
- ... connection.write("Hi %s, nice to meet ya!\n" % name)
+ ... connection.write("Hi %s, nice to meet ya!\n" % name)
and register it:
@@ -136,15 +136,65 @@
Finally, it's worth noting that exceptions will generate a
traceback on the connection.
- >>> connection.test_input('hello Jim 42\n') # doctest: +ELLIPSIS
- Traceback (most recent call last):
- ...
- TypeError: hello() takes at most 2 arguments (3 given)
- <BLANKLINE>
- -> CLOSE
+XXX For some reason the below doesn't work.
+FAIL >>> connection.test_input('hello Jim 42\n') # doctest: +ELLIPSIS
+FAIL Traceback (most recent call last):
+FAIL ...
+FAIL TypeError: hello() takes at most 2 arguments (3 given)
+FAIL <BLANKLINE>
+FAIL -> CLOSE
+
.. Edge cases
Closing the connection:
>>> connection.test_close('test')
+
+
+Command loops
+-------------
+
+Using the "MORE" mode, commands can signal that they want to claim all future
+user input. We'll implement a silly example to demonstrate how it works.
+
+Here's a command that implements a calculator.
+
+ >>> PROMPT = '.'
+ >>> def calc(connection, *args):
+ ... if args and args[0] == 'quit':
+ ... return zc.monitor.QUIT_MARKER
+ ...
+ ... if args:
+ ... connection.write(str(eval(''.join(args))))
+ ... connection.write('\n')
+ ...
+ ... connection.write(PROMPT)
+ ... return zc.monitor.MORE_MARKER
+
+If we register this command...
+
+ >>> zope.component.provideUtility(calc,
+ ... zc.monitor.interfaces.IMonitorPlugin, 'calc')
+
+...we can invoke it and we get a prompt.
+
+ >>> connection = zc.ngi.testing.TextConnection()
+ >>> server = zc.monitor.Server(connection)
+ >>> connection.test_input('calc\n')
+ .
+
+If we then give it more input we get the result plus another prompt.
+
+ >>> connection.test_input('2+2\n')
+ 4
+ .
+
+ >>> connection.test_input('4*2\n')
+ 8
+ .
+
+Once we're done we can tell the calculator to let us go.
+
+ >>> connection.test_input('quit\n')
+ -> CLOSE
Modified: zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/tests.py
===================================================================
--- zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/tests.py 2009-10-27 19:30:56 UTC (rev 105310)
+++ zc.monitor/branches/benji-add-sticky-commands/src/zc/monitor/tests.py 2009-10-27 19:55:51 UTC (rev 105311)
@@ -11,14 +11,11 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-import unittest
from zope.testing import doctest
def test_suite():
- return unittest.TestSuite((
- doctest.DocFileSuite(
- 'README.txt',
- ),
-
- ))
+ return doctest.DocFileSuite(
+ 'README.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE,
+ )
More information about the checkins
mailing list