# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1224977331 14400 # Node ID e3b8eaadea56abd5c46ff333b80f5cd7aef09a95 # Parent c1e5df33721f76f1679d957edc5020c5c214d267 going to collapse down out of overdone package structure diff -r c1e5df33721f -r e3b8eaadea56 MANIFEST.in.donotuse --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MANIFEST.in.donotuse Sat Oct 25 19:28:51 2008 -0400 @@ -0,0 +1,3 @@ +include cmd2/example/example.py +include cmd2/example/exampleSession.txt +include setup.py \ No newline at end of file diff -r c1e5df33721f -r e3b8eaadea56 README.txt --- a/README.txt Fri Oct 24 17:47:56 2008 -0400 +++ b/README.txt Sat Oct 25 19:28:51 2008 -0400 @@ -63,15 +63,18 @@ Cheese Shop page: http://pypi.python.org/pypi/cmd2 -Example cmd2 application (cmd2_example.py) :: +Example cmd2 application (example/example.py) :: - from cmd2 import Cmd, make_option, options - + '''A sample application for cmd2.''' + + from cmd2 import Cmd, make_option, options, Cmd2TestCase + import unittest, optparse, sys + class CmdLineApp(Cmd): multilineCommands = ['orate'] Cmd.shortcuts.update({'&': 'speak'}) maxrepeats = 3 - Cmd.settable.append('maxrepeats') + Cmd.settable.append('maxrepeats') @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"), make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), @@ -79,23 +82,34 @@ ]) def do_speak(self, arg, opts=None): """Repeats what you tell me to.""" - arg = ' '.join(arg) + arg = ''.join(arg) if opts.piglatin: arg = '%s%say' % (arg[1:], arg[0]) if opts.shout: - arg = arg.upper() + arg = arg.upper() repetitions = opts.repeat or 1 for i in range(min(repetitions, self.maxrepeats)): self.stdout.write(arg) self.stdout.write('\n') - # self.stdout.write is better than "print", because Cmd can be + # self.stdout.write is better than "print", because Cmd can be # initialized with a non-standard output destination - + do_say = do_speak # now "say" is a synonym for "speak" do_orate = do_speak # another synonym, but this one takes multi-line input - app = CmdLineApp() - app.cmdloop() + class TestMyAppCase(Cmd2TestCase): + CmdApp = CmdLineApp + transcriptFileName = 'exampleSession.txt' + + parser = optparse.OptionParser() + parser.add_option('-t', '--test', dest='unittests', action='store_true', default=False, help='Run unit test suite') + (callopts, callargs) = parser.parse_args() + if callopts.unittests: + sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main() + unittest.main() + else: + app = CmdLineApp() + app.cmdloop() Sample session using the above code :: diff -r c1e5df33721f -r e3b8eaadea56 cmd2/cmd2.py --- a/cmd2/cmd2.py Fri Oct 24 17:47:56 2008 -0400 +++ b/cmd2/cmd2.py Sat Oct 25 19:28:51 2008 -0400 @@ -11,6 +11,7 @@ Settable environment parameters Parsing commands with `optparse` options (flags) Redirection to file with >, >>; input from file with < +Easy transcript-based testing of applications (see example/example.py) Note that redirection with > and | will only work if `self.stdout.write()` is used in place of `print`. The standard library's `cmd` module is diff -r c1e5df33721f -r e3b8eaadea56 setup.py --- a/setup.py Fri Oct 24 17:47:56 2008 -0400 +++ b/setup.py Sat Oct 25 19:28:51 2008 -0400 @@ -3,11 +3,10 @@ setup( name="cmd2", + version="0.4", packages=["cmd2",], package_dir={'cmd2': 'cmd2'}, - package_data={'cmd2': ['example/*.*']}, - include_package_data=True, - version="0.4", + package_data={'cmd2': ['example/*.txt', 'example/*.py']}, # metadata for upload to PyPI author = 'Catherine Devlin', @@ -31,7 +30,7 @@ * > (filename), >> (filename) redirect output to file * < (filename) gets input from file * bare >, >>, < redirect to/from paste buffer - * test apps against sample session transcript (see example.py in source directory) + * test apps against sample session transcript (see example/example.py) Useable without modification anywhere cmd is used; simply import cmd2.Cmd in place of cmd.Cmd.