
"Ic           @   s   d  Z  d d k Z d d k Z d e i f d     YZ d d  Z d d k Z d d k Z d   Z e	 d j o) d e i
 j o e d	  q e   n d S(
   s@   
Test script for the 'cmd' module
Original by Michael Schneider
iNt   samplecmdclassc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s  
    Instance the sampleclass:
    >>> mycmd = samplecmdclass()

    Test for the function parseline():
    >>> mycmd.parseline("")
    (None, None, '')
    >>> mycmd.parseline("?")
    ('help', '', 'help ')
    >>> mycmd.parseline("?help")
    ('help', 'help', 'help help')
    >>> mycmd.parseline("!")
    ('shell', '', 'shell ')
    >>> mycmd.parseline("!command")
    ('shell', 'command', 'shell command')
    >>> mycmd.parseline("func")
    ('func', '', 'func')
    >>> mycmd.parseline("func arg1")
    ('func', 'arg1', 'func arg1')


    Test for the function onecmd():
    >>> mycmd.onecmd("")
    >>> mycmd.onecmd("add 4 5")
    9
    >>> mycmd.onecmd("")
    9
    >>> mycmd.onecmd("test")
    *** Unknown syntax: test

    Test for the function emptyline():
    >>> mycmd.emptyline()
    *** Unknown syntax: test

    Test for the function default():
    >>> mycmd.default("default")
    *** Unknown syntax: default

    Test for the function completedefault():
    >>> mycmd.completedefault()
    This is the completedefault methode
    >>> mycmd.completenames("a")
    ['add']

    Test for the function completenames():
    >>> mycmd.completenames("12")
    []
    >>> mycmd.completenames("help")
    ['help', 'help']

    Test for the function complete_help():
    >>> mycmd.complete_help("a")
    ['add']
    >>> mycmd.complete_help("he")
    ['help', 'help']
    >>> mycmd.complete_help("12")
    []

    Test for the function do_help():
    >>> mycmd.do_help("testet")
    *** No help on testet
    >>> mycmd.do_help("add")
    help text for add
    >>> mycmd.onecmd("help add")
    help text for add
    >>> mycmd.do_help("")
    <BLANKLINE>
    Documented commands (type help <topic>):
    ========================================
    add
    <BLANKLINE>
    Undocumented commands:
    ======================
    exit  help  shell
    <BLANKLINE>

    Test for the function print_topics():
    >>> mycmd.print_topics("header", ["command1", "command2"], 2 ,10)
    header
    ======
    command1
    command2
    <BLANKLINE>

    Test for the function columnize():
    >>> mycmd.columnize([str(i) for i in xrange(20)])
    0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19
    >>> mycmd.columnize([str(i) for i in xrange(20)], 10)
    0  7   14
    1  8   15
    2  9   16
    3  10  17
    4  11  18
    5  12  19
    6  13

    This is a interactive test, put some commands in the cmdqueue attribute
    and let it execute
    This test includes the preloop(), postloop(), default(), emptyline(),
    parseline(), do_help() functions
    >>> mycmd.use_rawinput=0
    >>> mycmd.cmdqueue=["", "add", "add 4 5", "help", "help add","exit"]
    >>> mycmd.cmdloop()
    Hello from preloop
    help text for add
    *** invalid number of arguments
    9
    <BLANKLINE>
    Documented commands (type help <topic>):
    ========================================
    add
    <BLANKLINE>
    Undocumented commands:
    ======================
    exit  help  shell
    <BLANKLINE>
    help text for add
    Hello from postloop
    c         C   s	   d GHd  S(   Ns   Hello from preloop(    (   t   self(    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   preloop   s    c         C   s	   d GHd  S(   Ns   Hello from postloop(    (   R   (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   postloop   s    c         G   s	   d GHd  S(   Ns#   This is the completedefault methode(    (   R   t   ignored(    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   completedefault   s    c         C   s	   d GHd  S(   Ns   complete command(    (   R   (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   complete_command   s    c         C   s   d  S(   N(    (   R   (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   do_shell   s    c         C   s   | i    } t |  d j o
 d GHd  Sy+ g  } | D] } | t |  q7 ~ } Wn t j
 o d GHd  SX| d | d GHd  S(   Ni   s   *** invalid number of argumentss   *** arguments should be numbersi    i   (   t   splitt   lent   intt
   ValueError(   R   t   st   lt   _[1]t   i(    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   do_add   s    +c         C   s	   d GHd  S(   Ns   help text for add(    (   R   (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   help_add   s    c         C   s   t  S(   N(   t   True(   R   t   arg(    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   do_exit   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   (    (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyR       s   w							c         C   s*   d d k  l } l } | i | |   d  S(   Ni(   t   test_supportt   test_cmd(   t   testR   R   t   run_doctest(   t   verboseR   R   (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt	   test_main   s    c         C   sh   t  i d t i t i g d d d d  } | i d  | i   } d GH| i d t d	 t d
 |   d  S(   Nt
   ignoredirst   tracei    t   counti   s   reload(cmd);test_main()s   Writing coverage results...t   show_missingt   summaryt   coverdir(	   R   t   Tracet   syst   prefixt   exec_prefixt   runt   resultst   write_resultsR   (   R#   t   tracert   r(    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   test_coverage   s    t   __main__s   -cs   /tmp/cmd.cover(   R   t   cmdR%   t   CmdR    t   NoneR   R   R-   R   t   argv(    (    (    s*   /mit/python/lib/python2.6/test/test_cmd.pyt   <module>   s   	