Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e4317fad
Kaydet (Commit)
e4317fad
authored
Ara 01, 2007
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add test suite for cmd module.
Written by Michael Schneider for GHOP.
üst
ebb035ef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
187 additions
and
0 deletions
+187
-0
test_cmd.py
Lib/test/test_cmd.py
+186
-0
ACKS
Misc/ACKS
+1
-0
No files found.
Lib/test/test_cmd.py
0 → 100644
Dosyayı görüntüle @
e4317fad
#!/usr/bin/env python
"""
Test script for the 'cmd' module
Original by Michael Schneider
"""
from
test
import
test_support
import
cmd
import
sys
class
samplecmdclass
(
cmd
.
Cmd
):
"""
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
"""
def
preloop
(
self
):
print
"Hello from preloop"
def
postloop
(
self
):
print
"Hello from postloop"
def
completedefault
(
self
,
*
ignored
):
print
"This is the completedefault methode"
return
def
complete_command
(
self
):
print
"complete command"
return
def
do_shell
(
self
):
pass
def
do_add
(
self
,
s
):
l
=
s
.
split
()
if
len
(
l
)
!=
2
:
print
"*** invalid number of arguments"
return
try
:
l
=
[
int
(
i
)
for
i
in
l
]
except
ValueError
:
print
"*** arguments should be numbers"
return
print
l
[
0
]
+
l
[
1
]
def
help_add
(
self
):
print
"help text for add"
return
def
do_exit
(
self
,
arg
):
return
True
def
test_main
(
verbose
=
None
):
from
test
import
test_support
,
test_cmd
test_support
.
run_doctest
(
test_cmd
,
verbose
)
import
trace
,
sys
,
re
,
StringIO
def
test_coverage
(
coverdir
):
tracer
=
trace
.
Trace
(
ignoredirs
=
[
sys
.
prefix
,
sys
.
exec_prefix
,],
trace
=
0
,
count
=
1
)
tracer
.
run
(
'reload(cmd);test_main()'
)
r
=
tracer
.
results
()
print
"Writing coverage results..."
r
.
write_results
(
show_missing
=
True
,
summary
=
True
,
coverdir
=
coverdir
)
if
__name__
==
"__main__"
:
if
"-c"
in
sys
.
argv
:
test_coverage
(
'/tmp/cmd.cover'
)
else
:
test_main
()
Misc/ACKS
Dosyayı görüntüle @
e4317fad
...
@@ -575,6 +575,7 @@ Neil Schemenauer
...
@@ -575,6 +575,7 @@ Neil Schemenauer
David Scherer
David Scherer
Gregor Schmid
Gregor Schmid
Ralf Schmitt
Ralf Schmitt
Michael Schneider
Peter Schneider-Kamp
Peter Schneider-Kamp
Arvin Schnell
Arvin Schnell
Chad J. Schroeder
Chad J. Schroeder
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment