Your IP : 216.73.216.213
�
��fW c @ s� d Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z Gd d � d e j � Z Gd d � d e j
� Z d d d � Z
d
d � Z e d k r� d
e j k r� e d � q� d e j k r� e � j � q� e
� n d S( u@
Test script for the 'cmd' module
Original by Michael Schneider
i N( u supportc B sz | Ee Z d Z d Z d d � Z d d � Z d d � Z d d � Z d
d � Z d d
� Z d d � Z
d d � Z d S( u samplecmdclassu-
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']
Test for the function complete_help():
>>> mycmd.complete_help("a")
['add']
>>> mycmd.complete_help("he")
['help']
>>> mycmd.complete_help("12")
[]
>>> sorted(mycmd.complete_help(""))
['add', 'exit', 'help', 'shell']
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 help
<BLANKLINE>
Undocumented commands:
======================
exit 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 range(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 range(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 help
<BLANKLINE>
Undocumented commands:
======================
exit shell
<BLANKLINE>
help text for add
Hello from postloop
c C s t d � d S( Nu Hello from preloop( u print( u self( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu preloop� s u samplecmdclass.preloopc C s t d � d S( Nu Hello from postloop( u print( u self( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu postloop� s u samplecmdclass.postloopc G s t d � d S( Nu# This is the completedefault methode( u print( u selfu ignored( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu completedefault� s u samplecmdclass.completedefaultc C s t d � d S( Nu complete command( u print( u self( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu complete_command� s u samplecmdclass.complete_commandc C s d S( N( ( u selfu s( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu do_shell� s u samplecmdclass.do_shellc C s� | j � } t | � d k r, t d � d Sy d d � | D� } Wn t k
re t d � d SYn Xt | d | d � d S( Ni u *** invalid number of argumentsc S s g | ] } t | � � q S( ( u int( u .0u i( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu
<listcomp>� s u) samplecmdclass.do_add.<locals>.<listcomp>u *** arguments should be numbersi i ( u splitu lenu printu
ValueError( u selfu su l( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu do_add� s
u samplecmdclass.do_addc C s t d � d S( Nu help text for add( u print( u self( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu help_add� s
u samplecmdclass.help_addc C s d S( NT( u True( u selfu arg( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu do_exit� s u samplecmdclass.do_exitN( u __name__u
__module__u __qualname__u __doc__u preloopu postloopu completedefaultu complete_commandu do_shellu do_addu help_addu do_exit( u
__locals__( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu samplecmdclass s yu samplecmdclassc B s[ | Ee Z d Z Gd d � d e j � Z Gd d � d e � Z d d � Z d d � Z d S(
u TestAlternateInputc B s, | Ee Z d Z d d � Z d d � Z d S( u TestAlternateInput.simplecmdc C s t | d | j �d S( Nu file( u printu stdout( u selfu args( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu do_print� s u% TestAlternateInput.simplecmd.do_printc C s d S( NT( u True( u selfu args( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu do_EOF� s u# TestAlternateInput.simplecmd.do_EOFN( u __name__u
__module__u __qualname__u do_printu do_EOF( u
__locals__( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu simplecmd� s u simplecmdc B s | Ee Z d Z d d � Z d S( u TestAlternateInput.simplecmd2c C s t d d | j �d S( Nu *** Unknown syntax: EOFu fileT( u printu stdoutu True( u selfu args( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu do_EOF� s u$ TestAlternateInput.simplecmd2.do_EOFN( u __name__u
__module__u __qualname__u do_EOF( u
__locals__( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu
simplecmd2� s u
simplecmd2c C s` t j d � } t j � } | j d | d | � } d | _ | j � | j | j � d � d S( Nu print test
print test2u stdinu stdoutu (Cmd) test
(Cmd) test2
(Cmd) F( u iou StringIOu simplecmdu Falseu use_rawinputu cmdloopu assertMultiLineEqualu getvalue( u selfu inputu outputu cmd( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu test_file_with_missing_final_nl� s
u2 TestAlternateInput.test_file_with_missing_final_nlc C s� t j d � } t j � } | j d | d | � } d | _ | j � | j | j � d � t j d � } t j � } | | _ | | _ | j � | j | j � d � d S( Nu print test
print test2u stdinu stdoutu5 (Cmd) test
(Cmd) test2
(Cmd) *** Unknown syntax: EOF
u print
u, (Cmd)
(Cmd)
(Cmd) *** Unknown syntax: EOF
F(
u iou StringIOu
simplecmd2u Falseu use_rawinputu cmdloopu assertMultiLineEqualu getvalueu stdinu stdout( u selfu inputu outputu cmd( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu test_input_reset_at_EOF� s
u* TestAlternateInput.test_input_reset_at_EOFN( u __name__u
__module__u __qualname__u cmdu Cmdu simplecmdu
simplecmd2u test_file_with_missing_final_nlu test_input_reset_at_EOF( u
__locals__( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu TestAlternateInput� s u TestAlternateInputc C s1 d d l m } t j | | � t j t � d S( Ni ( u test_cmd( u testu test_cmdu supportu run_doctestu run_unittestu TestAlternateInput( u verboseu test_cmd( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu test_main� s u test_mainc C s| t j d � } | j d t j t j g d d d d � } | j d � | j � } t d � | j d d d d d
| � d S( Nu traceu
ignoredirsi u counti u reload(cmd);test_main()u Writing coverage results...u show_missingu summaryu coverdirT( u supportu
import_moduleu Traceu sysu base_prefixu base_exec_prefixu runu resultsu printu
write_resultsu True( u coverdiru traceu traceru r( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu
test_coverage� s
u
test_coverageu __main__u -cu /tmp/cmd.coveru -i( u __doc__u cmdu sysu reu unittestu iou testu supportu Cmdu samplecmdclassu TestCaseu TestAlternateInputu Noneu test_mainu
test_coverageu __name__u argvu cmdloop( ( ( u2 /opt/alt/python33/lib64/python3.3/test/test_cmd.pyu <module> s �3