changeset 325:4172feeddf76

want to incorporate run() for tests - not yet working
author catherine@dellzilla
date Thu, 11 Feb 2010 17:03:45 -0500
parents 21584174d865
children 237a89d5a4a9
files cmd2.py docs/freefeatures.rst docs/settingchanges.rst example/example.py example/exampleSession.txt
diffstat 5 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Thu Feb 11 16:07:24 2010 -0500
+++ b/cmd2.py	Thu Feb 11 17:03:45 2010 -0500
@@ -1476,10 +1476,24 @@
     def tearDown(self):
         if self.CmdApp:
             self.outputTrap.tearDown()
-        
+    
+def run(app):
+    class TestMyAppCase(Cmd2TestCase):
+        CmdApp = app.__class__
+    parser = optparse.OptionParser()
+    parser.add_option('-t', '--test', dest='test', action="store_true", 
+                      help='Test against transcript(s) in FILE (wildcards OK)')
+    (callopts, callargs) = parser.parse_args()
+    if callopts.test:
+        app.testfiles = callargs
+        sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main()
+        unittest.main()
+    else:
+        app.cmdloop()   
+
 if __name__ == '__main__':
     doctest.testmod(optionflags = doctest.NORMALIZE_WHITESPACE)
-    
+        
 '''
 To make your application transcript-testable, add text like this to your .py file
 (replacing CmdLineApp with your own application class's name).  Then, a cut-and-pasted
--- a/docs/freefeatures.rst	Thu Feb 11 16:07:24 2010 -0500
+++ b/docs/freefeatures.rst	Thu Feb 11 17:03:45 2010 -0500
@@ -8,10 +8,12 @@
 Script files
 ============
 
-Commands can be loaded from, run from, and saved to text files.
+Commands can be loaded and run from text files.
 
 .. automethod:: cmd2.Cmd.do_load
 
+.. automethod:: cmd2.Cmd.do_save
+
 Output redirection
 ==================
 
@@ -29,10 +31,10 @@
 .. _xclip:: http://www.cyberciti.biz/faq/xclip-linux-insert-files-command-output-intoclipboard/
 
   
-operating-system programs, like 
+Commands at invocation
+======================
 
-Commands at start
-=================
+TODO: broken!?
 
 Python
 ======
--- a/docs/settingchanges.rst	Thu Feb 11 16:07:24 2010 -0500
+++ b/docs/settingchanges.rst	Thu Feb 11 17:03:45 2010 -0500
@@ -31,8 +31,7 @@
     class App(Cmd):
         multilineCommands = ['lenghtycommand']
         def do_lengthycommand(self, args):
-            # ...
-          
+            # ...          
 
 Shortcuts
 =========
--- a/example/example.py	Thu Feb 11 16:07:24 2010 -0500
+++ b/example/example.py	Thu Feb 11 17:03:45 2010 -0500
@@ -1,6 +1,6 @@
 '''A sample application for cmd2.'''
 
-from cmd2 import Cmd, make_option, options, Cmd2TestCase
+from cmd2 import Cmd, make_option, options, Cmd2TestCase, run
 import unittest, optparse, sys
 
 class CmdLineApp(Cmd):
@@ -31,6 +31,7 @@
     do_orate = do_speak   # another synonym, but this one takes multi-line input
 
 c = CmdLineApp()
+#run(c)
 
 class TestMyAppCase(Cmd2TestCase):
     CmdApp = CmdLineApp
@@ -44,4 +45,3 @@
     unittest.main()
 else:
     CmdLineApp().cmdloop()
-
--- a/example/exampleSession.txt	Thu Feb 11 16:07:24 2010 -0500
+++ b/example/exampleSession.txt	Thu Feb 11 17:03:45 2010 -0500
@@ -32,7 +32,7 @@
 case_insensitive: True
 colors: True
 continuation_prompt: > 
-debug: True
+debug: False
 default_file_name: command.txt
 echo: False
 editor: gedit