Mercurial > python-cmd2
comparison example/example.py @ 325:4172feeddf76
want to incorporate run() for tests - not yet working
author | catherine@dellzilla |
---|---|
date | Thu, 11 Feb 2010 17:03:45 -0500 |
parents | 9d91406ca3a7 |
children | 237a89d5a4a9 |
comparison
equal
deleted
inserted
replaced
324:21584174d865 | 325:4172feeddf76 |
---|---|
1 '''A sample application for cmd2.''' | 1 '''A sample application for cmd2.''' |
2 | 2 |
3 from cmd2 import Cmd, make_option, options, Cmd2TestCase | 3 from cmd2 import Cmd, make_option, options, Cmd2TestCase, run |
4 import unittest, optparse, sys | 4 import unittest, optparse, sys |
5 | 5 |
6 class CmdLineApp(Cmd): | 6 class CmdLineApp(Cmd): |
7 multilineCommands = ['orate'] | 7 multilineCommands = ['orate'] |
8 Cmd.shortcuts.update({'&': 'speak'}) | 8 Cmd.shortcuts.update({'&': 'speak'}) |
29 | 29 |
30 do_say = do_speak # now "say" is a synonym for "speak" | 30 do_say = do_speak # now "say" is a synonym for "speak" |
31 do_orate = do_speak # another synonym, but this one takes multi-line input | 31 do_orate = do_speak # another synonym, but this one takes multi-line input |
32 | 32 |
33 c = CmdLineApp() | 33 c = CmdLineApp() |
34 #run(c) | |
34 | 35 |
35 class TestMyAppCase(Cmd2TestCase): | 36 class TestMyAppCase(Cmd2TestCase): |
36 CmdApp = CmdLineApp | 37 CmdApp = CmdLineApp |
37 parser = optparse.OptionParser() | 38 parser = optparse.OptionParser() |
38 parser.add_option('-t', '--test', dest='test', action="store_true", | 39 parser.add_option('-t', '--test', dest='test', action="store_true", |
42 CmdLineApp.testfiles = callargs | 43 CmdLineApp.testfiles = callargs |
43 sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main() | 44 sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main() |
44 unittest.main() | 45 unittest.main() |
45 else: | 46 else: |
46 CmdLineApp().cmdloop() | 47 CmdLineApp().cmdloop() |
47 |