Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_cmd.cpython-311.pyc |
�
�Ke� � �> � d Z ddlZddlZddlZddlZddlZddlmZ G d� dej � � Z G d� dej
� � Zd� Zd � Z
ed
k rNdej v r
e
d� � dS d
ej v r e � � � � � dS ej � � dS dS )z@
Test script for the 'cmd' module
Original by Michael Schneider
� N)�supportc �N � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z
d � Zd
� Zd� Z
dS )
�samplecmdclassa
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 method
>>> 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', 'life', 'meaning', '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.onecmd("help meaning") # doctest: +NORMALIZE_WHITESPACE
Try and be nice to people, avoid eating fat, read a good book every
now and then, get some walking in, and try to live together in peace
and harmony with people of all creeds and nations.
>>> mycmd.do_help("")
<BLANKLINE>
Documented commands (type help <topic>):
========================================
add help
<BLANKLINE>
Miscellaneous help topics:
==========================
life meaning
<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 an 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() # doctest: +REPORT_NDIFF
Hello from preloop
*** invalid number of arguments
9
9
<BLANKLINE>
Documented commands (type help <topic>):
========================================
add help
<BLANKLINE>
Miscellaneous help topics:
==========================
life meaning
<BLANKLINE>
Undocumented commands:
======================
exit shell
<BLANKLINE>
help text for add
Hello from postloop
c �$ � t d� � d S )NzHello from preloop��print��selfs �7/usr/local/apps/python3/lib/python3.11/test/test_cmd.py�preloopzsamplecmdclass.preloop� s � �
�"�#�#�#�#�#� c �$ � t d� � d S )NzHello from postloopr r s r �postloopzsamplecmdclass.postloop� s � �
�#�$�$�$�$�$r
c �$ � t d� � d S )Nz"This is the completedefault methodr )r
�ignoreds r �completedefaultzsamplecmdclass.completedefault� s � �
�2�3�3�3�3�3r
c �$ � t d� � d S )Nzcomplete commandr r s r �complete_commandzsamplecmdclass.complete_command� s � �
� �!�!�!�!�!r
c � � d S �N� )r
�ss r �do_shellzsamplecmdclass.do_shell� s � ��r
c � � |� � � }t |� � dk rt d� � d S d� |D � � }n # t $ r t d� � Y d S w xY wt |d |d z � � d S )N� z*** invalid number of argumentsc �, � g | ]}t |� � ��S r )�int)�.0�is r �
<listcomp>z)samplecmdclass.do_add.<locals>.<listcomp>� s � �#�#�#�A��Q���#�#�#r
z*** arguments should be numbersr � )�split�lenr �
ValueError)r
r �ls r �do_addzsamplecmdclass.do_add� s� � �
�G�G�I�I���q�6�6�Q�;�;��3�4�4�4��F� �#�#��#�#�#�A�A��� � � ��3�4�4�4��F�F� ���� �a��d�1�Q�4�i�����s �A �A$�#A$c �$ � t d� � d S )Nzhelp text for addr r s r �help_addzsamplecmdclass.help_add� s � �
�!�"�"�"��r
c �$ � t d� � d S )Nz�Try and be nice to people, avoid eating fat, read a good book every now and then, get some walking in, and try to live together in peace and harmony with people of all creeds and nations.r r s r �help_meaningzsamplecmdclass.help_meaning� s � �
� 2� 3� 3� 3� �r
c �$ � t d� � d S )Nz&Always look on the bright side of lifer r s r � help_lifezsamplecmdclass.help_life� s � �
�6�7�7�7��r
c � � dS �NTr )r
�args r �do_exitzsamplecmdclass.do_exit� s � ��tr
N)�__name__�
__module__�__qualname__�__doc__r r r r r r&