# HG changeset patch # User catherine@dellzilla # Date 1265925825 18000 # Node ID 4172feeddf76c1a74d965a63114bc6eb6946955e # Parent 21584174d865d8bf73280a0f3cc3d759eaa03a8d want to incorporate run() for tests - not yet working diff -r 21584174d865 -r 4172feeddf76 cmd2.py --- 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 diff -r 21584174d865 -r 4172feeddf76 docs/freefeatures.rst --- 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 ====== diff -r 21584174d865 -r 4172feeddf76 docs/settingchanges.rst --- 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 ========= diff -r 21584174d865 -r 4172feeddf76 example/example.py --- 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() - diff -r 21584174d865 -r 4172feeddf76 example/exampleSession.txt --- 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