[Python-checkins] python/dist/src/Lib/test test_getopt.py,1.6,1.7
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
2003年4月29日 12:58:10 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv5423
Modified Files:
test_getopt.py
Log Message:
Add doctest for example in the library reference.
Index: test_getopt.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_getopt.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** test_getopt.py 23 Jul 2002 19:03:54 -0000 1.6
--- test_getopt.py 29 Apr 2003 19:58:04 -0000 1.7
***************
*** 126,129 ****
--- 126,169 ----
verify(args == ['arg1', '-b', '1', '--alpha', '--beta=2'])
+ #------------------------------------------------------------------------------
+
+ libreftest = """
+ Examples from the Library Reference: Doc/lib/libgetopt.tex
+
+ An example using only Unix style options:
+
+
+ >>> import getopt
+ >>> args = '-a -b -cfoo -d bar a1 a2'.split()
+ >>> args
+ ['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2']
+ >>> optlist, args = getopt.getopt(args, 'abc:d:')
+ >>> optlist
+ [('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')]
+ >>> args
+ ['a1', 'a2']
+
+ Using long option names is equally easy:
+
+
+ >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
+ >>> args = s.split()
+ >>> args
+ ['--condition=foo', '--testing', '--output-file', 'abc.def', '-x', 'a1', 'a2']
+ >>> optlist, args = getopt.getopt(args, 'x', [
+ ... 'condition=', 'output-file=', 'testing'])
+ >>> optlist
+ [('--condition', 'foo'), ('--testing', ''), ('--output-file', 'abc.def'), ('-x', '')]
+ >>> args
+ ['a1', 'a2']
+
+ """
+
+ __test__ = {'libreftest' : libreftest}
+
+ import doctest, sys
+ doctest.testmod(sys.modules[__name__])
+
+ #------------------------------------------------------------------------------
if verbose: