diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-02 15:22:16 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-02 15:22:16 (GMT) |
commit | d8654cf758c730af430026a5b20810bebceba4d7 (patch) | |
tree | cba77a4cce70773ed2bf00d183459101c53dfd26 /Lib | |
parent | b27ce7e46843841e8e8f2c9e5108044d022ae248 (diff) | |
download | cpython-d8654cf758c730af430026a5b20810bebceba4d7.zip cpython-d8654cf758c730af430026a5b20810bebceba4d7.tar.gz cpython-d8654cf758c730af430026a5b20810bebceba4d7.tar.bz2 |
Merged revisions 59259-59274 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59260 | lars.gustaebel | 2007-12-01 22:02:12 +0100 (Sat, 01 Dec 2007) | 5 lines
Issue #1531: Read fileobj from the current offset, do not seek to
the start.
(will backport to 2.5)
........
r59262 | georg.brandl | 2007-12-01 23:24:47 +0100 (Sat, 01 Dec 2007) | 4 lines
Document PyEval_* functions from ceval.c.
Credits to Michael Sloan from GHOP.
........
r59263 | georg.brandl | 2007-12-01 23:27:56 +0100 (Sat, 01 Dec 2007) | 2 lines
Add a few refcount data entries.
........
r59264 | georg.brandl | 2007-12-01 23:38:48 +0100 (Sat, 01 Dec 2007) | 4 lines
Add test suite for cmd module.
Written by Michael Schneider for GHOP.
........
r59265 | georg.brandl | 2007-12-01 23:42:46 +0100 (Sat, 01 Dec 2007) | 3 lines
Add examples to the ElementTree documentation.
Written by h4wk.cz for GHOP.
........
r59266 | georg.brandl | 2007-12-02 00:12:45 +0100 (Sun, 02 Dec 2007) | 3 lines
Add "Using Python on Windows" document, by Robert Lehmann.
Written for GHOP.
........
r59271 | georg.brandl | 2007-12-02 15:34:34 +0100 (Sun, 02 Dec 2007) | 3 lines
Add example to mmap docs.
Written for GHOP by Rafal Rawicki.
........
r59272 | georg.brandl | 2007-12-02 15:37:29 +0100 (Sun, 02 Dec 2007) | 2 lines
Convert bdb.rst line endings to Unix style.
........
r59274 | georg.brandl | 2007-12-02 15:58:50 +0100 (Sun, 02 Dec 2007) | 4 lines
Add more entries to the glossary.
Written by Jeff Wheeler for GHOP.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/tarfile.py | 3 | ||||
-rw-r--r-- | Lib/test/test_cmd.py | 186 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 32 |
3 files changed, 220 insertions, 1 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index f8afae9..a21f1ab 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1542,7 +1542,8 @@ class TarFile(object): self.closed = False self.members = [] # list of members as TarInfo objects self._loaded = False # flag if all members have been read - self.offset = 0 # current position in the archive file + self.offset = self.fileobj.tell() + # current position in the archive file self.inodes = {} # dictionary caching the inodes of # archive members already added diff --git a/Lib/test/test_cmd.py b/Lib/test/test_cmd.py new file mode 100644 index 0000000..5aa1c40 --- /dev/null +++ b/Lib/test/test_cmd.py @@ -0,0 +1,186 @@ +#!/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() diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 10498bf..a97df37 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -159,6 +159,38 @@ class MiscReadTest(ReadTest): tar = tarfile.open(fileobj=fobj, mode=self.mode) self.assertEqual(tar.name, None) + def test_fileobj_with_offset(self): + # Skip the first member and store values from the second member + # of the testtar. + tar = tarfile.open(self.tarname, mode=self.mode) + tar.next() + t = tar.next() + name = t.name + offset = t.offset + data = tar.extractfile(t).read() + tar.close() + + # Open the testtar and seek to the offset of the second member. + if self.mode.endswith(":gz"): + _open = gzip.GzipFile + elif self.mode.endswith(":bz2"): + _open = bz2.BZ2File + else: + _open = open + fobj = _open(self.tarname, "rb") + fobj.seek(offset) + + # Test if the tarfile starts with the second member. + tar = tar.open(self.tarname, mode="r:", fileobj=fobj) + t = tar.next() + self.assertEqual(t.name, name) + # Read to the end of fileobj and test if seeking back to the + # beginning works. + tar.getmembers() + self.assertEqual(tar.extractfile(t).read(), data, + "seek back did not work") + tar.close() + def test_fail_comp(self): # For Gzip and Bz2 Tests: fail with a ReadError on an uncompressed file. if self.mode == "r:": |