diff options
author | Thomas Wouters <thomas@python.org> | 2007-08-30 22:15:33 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2007-08-30 22:15:33 (GMT) |
commit | 47b49bf6dc5e57578baad3a591117e6da16cf6c8 (patch) | |
tree | 2dc915b2262343fb830a0bfa7d75917b547ddda6 /Lib/ctypes/test | |
parent | cf1be88b438f0e85f2053e4d444b23732757345b (diff) | |
download | cpython-47b49bf6dc5e57578baad3a591117e6da16cf6c8.zip cpython-47b49bf6dc5e57578baad3a591117e6da16cf6c8.tar.gz cpython-47b49bf6dc5e57578baad3a591117e6da16cf6c8.tar.bz2 |
Merged revisions 57620-57771 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57771 | thomas.wouters | 2007-08-30 23:54:39 +0200 (Thu, 30 Aug 2007) | 5 lines
Don't lie in __all__ attributes when SSL is not available: only add the SSL
classes when they are actually created.
........
r57620 | walter.doerwald | 2007-08-28 18:38:26 +0200 (Tue, 28 Aug 2007) | 5 lines
Fix title endtag in HTMLCalender.formatyearpage(). Fix documentation for
HTMLCalender.formatyearpage() (there's no themonth parameter).
This fixes issue1046.
........
r57622 | georg.brandl | 2007-08-28 20:54:44 +0200 (Tue, 28 Aug 2007) | 2 lines
Add a crasher for the thread-unsafety of file objects.
........
r57626 | skip.montanaro | 2007-08-29 01:22:52 +0200 (Wed, 29 Aug 2007) | 1 line
fixes 813986
........
r57628 | walter.doerwald | 2007-08-29 01:35:33 +0200 (Wed, 29 Aug 2007) | 2 lines
Fix test output.
........
r57631 | skip.montanaro | 2007-08-29 03:24:11 +0200 (Wed, 29 Aug 2007) | 2 lines
Install pygettext (once the scriptsinstall target is working again).
........
r57633 | skip.montanaro | 2007-08-29 03:33:45 +0200 (Wed, 29 Aug 2007) | 2 lines
Recent items.
........
r57650 | neal.norwitz | 2007-08-29 08:15:33 +0200 (Wed, 29 Aug 2007) | 1 line
Add Bill as a developer
........
r57651 | facundo.batista | 2007-08-29 12:28:28 +0200 (Wed, 29 Aug 2007) | 5 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised during FailingServerTestCase tests.
[GSoC - Alan McIntyre]
........
r57680 | bill.janssen | 2007-08-30 00:35:05 +0200 (Thu, 30 Aug 2007) | 17 lines
This contains a number of things:
1) Improve the documentation of the SSL module, with a fuller
explanation of certificate usage, another reference, proper
formatting of this and that.
2) Fix Windows bug in ssl.py, and general bug in sslsocket.close().
Remove some unused code from ssl.py. Allow accept() to be called on
sslsocket sockets.
3) Use try-except-else in import of ssl in socket.py. Deprecate use of
socket.ssl().
4) Remove use of socket.ssl() in every library module, except for
test_socket_ssl.py and test_ssl.py.
........
r57714 | georg.brandl | 2007-08-30 12:09:42 +0200 (Thu, 30 Aug 2007) | 2 lines
Stronger urge to convert filenames to str before using them as argument to ZipFile.write().
........
r57716 | georg.brandl | 2007-08-30 12:38:56 +0200 (Thu, 30 Aug 2007) | 2 lines
Patch #1680959: add test suite for pipes module.
........
r57717 | georg.brandl | 2007-08-30 14:32:23 +0200 (Thu, 30 Aug 2007) | 3 lines
* Skip test_pipes on non-POSIX.
* Don't raise TestSkipped within a test function.
........
r57723 | mark.summerfield | 2007-08-30 17:03:03 +0200 (Thu, 30 Aug 2007) | 3 lines
Added more cross-references.
........
r57726 | walter.doerwald | 2007-08-30 17:30:09 +0200 (Thu, 30 Aug 2007) | 2 lines
Rewrap line.
........
r57727 | walter.doerwald | 2007-08-30 17:34:55 +0200 (Thu, 30 Aug 2007) | 2 lines
Set startinpos before calling the error handler.
........
r57730 | bill.janssen | 2007-08-30 19:07:28 +0200 (Thu, 30 Aug 2007) | 3 lines
Added docstrings to methods and functions.
........
r57743 | bill.janssen | 2007-08-30 20:08:06 +0200 (Thu, 30 Aug 2007) | 1 line
added note on new ssl module and deprecation of socket.ssl
........
r57747 | martin.v.loewis | 2007-08-30 20:14:01 +0200 (Thu, 30 Aug 2007) | 1 line
Fix popen usage.
........
r57748 | martin.v.loewis | 2007-08-30 20:15:22 +0200 (Thu, 30 Aug 2007) | 1 line
Fix typo.
........
r57750 | martin.v.loewis | 2007-08-30 20:25:47 +0200 (Thu, 30 Aug 2007) | 1 line
Bug #1746880: Correctly install DLLs into system32 folder on Win64.
........
r57760 | martin.v.loewis | 2007-08-30 21:04:09 +0200 (Thu, 30 Aug 2007) | 1 line
Bug #1709599: Run test_1565150 only if the file system is NTFS.
........
r57762 | martin.v.loewis | 2007-08-30 22:10:57 +0200 (Thu, 30 Aug 2007) | 2 lines
Bump autoconf minimum version to 2.61.
........
r57764 | lars.gustaebel | 2007-08-30 22:24:31 +0200 (Thu, 30 Aug 2007) | 2 lines
Warn about possible risks when extracting untrusted archives.
........
r57769 | thomas.wouters | 2007-08-30 23:01:17 +0200 (Thu, 30 Aug 2007) | 7 lines
Somewhat-preliminary slice-object and extended slicing support for ctypes.
The exact behaviour of omitted and negative indices for the Pointer type may
need a closer look (especially as it's subtly different from simple slices)
but there's time yet before 2.6, and not enough before 3.0a1 :-)
........
Diffstat (limited to 'Lib/ctypes/test')
-rw-r--r-- | Lib/ctypes/test/test_arrays.py | 8 | ||||
-rw-r--r-- | Lib/ctypes/test/test_buffers.py | 16 | ||||
-rw-r--r-- | Lib/ctypes/test/test_cast.py | 12 | ||||
-rw-r--r-- | Lib/ctypes/test/test_memfunctions.py | 8 | ||||
-rw-r--r-- | Lib/ctypes/test/test_slicing.py | 65 | ||||
-rw-r--r-- | Lib/ctypes/test/test_strings.py | 3 | ||||
-rw-r--r-- | Lib/ctypes/test/test_structures.py | 6 | ||||
-rw-r--r-- | Lib/ctypes/test/test_unicode.py | 14 |
8 files changed, 128 insertions, 4 deletions
diff --git a/Lib/ctypes/test/test_arrays.py b/Lib/ctypes/test/test_arrays.py index e01ccfd..f487013 100644 --- a/Lib/ctypes/test/test_arrays.py +++ b/Lib/ctypes/test/test_arrays.py @@ -95,6 +95,10 @@ class ArrayTestCase(unittest.TestCase): p = create_string_buffer("foo") sz = (c_char * 3).from_address(addressof(p)) self.failUnlessEqual(sz[:], "foo") + self.failUnlessEqual(sz[::], "foo") + self.failUnlessEqual(sz[::-1], "oof") + self.failUnlessEqual(sz[::3], "f") + self.failUnlessEqual(sz[1:4:2], "o") self.failUnlessEqual(sz.value, "foo") try: @@ -106,6 +110,10 @@ class ArrayTestCase(unittest.TestCase): p = create_unicode_buffer("foo") sz = (c_wchar * 3).from_address(addressof(p)) self.failUnlessEqual(sz[:], "foo") + self.failUnlessEqual(sz[::], "foo") + self.failUnlessEqual(sz[::-1], "oof") + self.failUnlessEqual(sz[::3], "f") + self.failUnlessEqual(sz[1:4:2], "o") self.failUnlessEqual(sz.value, "foo") if __name__ == '__main__': diff --git a/Lib/ctypes/test/test_buffers.py b/Lib/ctypes/test/test_buffers.py index 35c0510..5e7b23d 100644 --- a/Lib/ctypes/test/test_buffers.py +++ b/Lib/ctypes/test/test_buffers.py @@ -15,6 +15,10 @@ class StringBufferTestCase(unittest.TestCase): self.failUnless(type(b[0]) is bytes) self.failUnlessEqual(b[0], b"a") self.failUnlessEqual(b[:], "abc\0") + self.failUnlessEqual(b[::], "abc\0") + self.failUnlessEqual(b[::-1], "\0cba") + self.failUnlessEqual(b[::2], "ac") + self.failUnlessEqual(b[::5], "a") def test_string_conversion(self): b = create_string_buffer("abc") @@ -23,6 +27,10 @@ class StringBufferTestCase(unittest.TestCase): self.failUnless(type(b[0]) is bytes) self.failUnlessEqual(b[0], b"a") self.failUnlessEqual(b[:], "abc\0") + self.failUnlessEqual(b[::], "abc\0") + self.failUnlessEqual(b[::-1], "\0cba") + self.failUnlessEqual(b[::2], "ac") + self.failUnlessEqual(b[::5], "a") try: c_wchar @@ -41,6 +49,10 @@ class StringBufferTestCase(unittest.TestCase): self.failUnless(type(b[0]) is str) self.failUnlessEqual(b[0], "a") self.failUnlessEqual(b[:], "abc\0") + self.failUnlessEqual(b[::], "abc\0") + self.failUnlessEqual(b[::-1], "\0cba") + self.failUnlessEqual(b[::2], "ac") + self.failUnlessEqual(b[::5], "a") def test_unicode_conversion(self): b = create_unicode_buffer("abc") @@ -49,6 +61,10 @@ class StringBufferTestCase(unittest.TestCase): self.failUnless(type(b[0]) is str) self.failUnlessEqual(b[0], "a") self.failUnlessEqual(b[:], "abc\0") + self.failUnlessEqual(b[::], "abc\0") + self.failUnlessEqual(b[::-1], "\0cba") + self.failUnlessEqual(b[::2], "ac") + self.failUnlessEqual(b[::5], "a") if __name__ == "__main__": unittest.main() diff --git a/Lib/ctypes/test/test_cast.py b/Lib/ctypes/test/test_cast.py index cafb697..cb7524e 100644 --- a/Lib/ctypes/test/test_cast.py +++ b/Lib/ctypes/test/test_cast.py @@ -50,12 +50,24 @@ class Test(unittest.TestCase): def test_other(self): p = cast((c_int * 4)(1, 2, 3, 4), POINTER(c_int)) self.failUnlessEqual(p[:4], [1,2, 3, 4]) + self.failUnlessEqual(p[:4:], [1, 2, 3, 4]) + self.failUnlessEqual(p[3:-1:-1], [4, 3, 2, 1]) + self.failUnlessEqual(p[:4:3], [1, 4]) c_int() self.failUnlessEqual(p[:4], [1, 2, 3, 4]) + self.failUnlessEqual(p[:4:], [1, 2, 3, 4]) + self.failUnlessEqual(p[3:-1:-1], [4, 3, 2, 1]) + self.failUnlessEqual(p[:4:3], [1, 4]) p[2] = 96 self.failUnlessEqual(p[:4], [1, 2, 96, 4]) + self.failUnlessEqual(p[:4:], [1, 2, 96, 4]) + self.failUnlessEqual(p[3:-1:-1], [4, 96, 2, 1]) + self.failUnlessEqual(p[:4:3], [1, 4]) c_int() self.failUnlessEqual(p[:4], [1, 2, 96, 4]) + self.failUnlessEqual(p[:4:], [1, 2, 96, 4]) + self.failUnlessEqual(p[3:-1:-1], [4, 96, 2, 1]) + self.failUnlessEqual(p[:4:3], [1, 4]) def test_char_p(self): # This didn't work: bad argument to internal function diff --git a/Lib/ctypes/test/test_memfunctions.py b/Lib/ctypes/test/test_memfunctions.py index fcc888b..79804bf 100644 --- a/Lib/ctypes/test/test_memfunctions.py +++ b/Lib/ctypes/test/test_memfunctions.py @@ -30,6 +30,14 @@ class MemFunctionsTest(unittest.TestCase): self.failUnlessEqual(cast(a, c_char_p).value, "abcdef") self.failUnlessEqual(cast(a, POINTER(c_byte))[:7], [97, 98, 99, 100, 101, 102, 0]) + self.failUnlessEqual(cast(a, POINTER(c_byte))[:7:], + [97, 98, 99, 100, 101, 102, 0]) + self.failUnlessEqual(cast(a, POINTER(c_byte))[6:-1:-1], + [0, 102, 101, 100, 99, 98, 97]) + self.failUnlessEqual(cast(a, POINTER(c_byte))[:7:2], + [97, 99, 101, 0]) + self.failUnlessEqual(cast(a, POINTER(c_byte))[:7:7], + [97]) def test_string_at(self): s = string_at(b"foo bar") diff --git a/Lib/ctypes/test/test_slicing.py b/Lib/ctypes/test/test_slicing.py index 887475e..5df0019 100644 --- a/Lib/ctypes/test/test_slicing.py +++ b/Lib/ctypes/test/test_slicing.py @@ -8,13 +8,22 @@ class SlicesTestCase(unittest.TestCase): a = (c_int * 100)(*range(1100, 1200)) b = list(range(1100, 1200)) self.failUnlessEqual(a[0:2], b[0:2]) + self.failUnlessEqual(a[0:2:], b[0:2:]) self.failUnlessEqual(len(a), len(b)) self.failUnlessEqual(a[5:7], b[5:7]) + self.failUnlessEqual(a[5:7:], b[5:7:]) self.failUnlessEqual(a[-1], b[-1]) self.failUnlessEqual(a[:], b[:]) + self.failUnlessEqual(a[::], b[::]) + self.failUnlessEqual(a[10::-1], b[10::-1]) + self.failUnlessEqual(a[30:20:-1], b[30:20:-1]) + self.failUnlessEqual(a[:12:6], b[:12:6]) + self.failUnlessEqual(a[2:6:4], b[2:6:4]) a[0:5] = range(5, 10) self.failUnlessEqual(a[0:5], list(range(5, 10))) + self.failUnlessEqual(a[0:5:], list(range(5, 10))) + self.failUnlessEqual(a[4::-1], list(range(9, 4, -1))) def test_setslice_cint(self): a = (c_int * 100)(*range(1100, 1200)) @@ -22,17 +31,36 @@ class SlicesTestCase(unittest.TestCase): a[32:47] = list(range(32, 47)) self.failUnlessEqual(a[32:47], list(range(32, 47))) - - from operator import setslice + a[32:47] = range(132, 147) + self.failUnlessEqual(a[32:47:], list(range(132, 147))) + a[46:31:-1] = range(232, 247) + self.failUnlessEqual(a[32:47:1], list(range(246, 231, -1))) + + a[32:47] = range(1132, 1147) + self.failUnlessEqual(a[:], b) + a[32:47:7] = range(3) + b[32:47:7] = range(3) + self.failUnlessEqual(a[:], b) + a[33::-3] = range(12) + b[33::-3] = range(12) + self.failUnlessEqual(a[:], b) + + from operator import setslice, setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, "abcde") + self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setslice, a, 0, 5, ["a", "b", "c", "d", "e"]) + self.assertRaises(TypeError, setitem, a, slice(0, 5), + ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14]) + self.assertRaises(TypeError, setitem, a, slice(0, 5), + [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setslice, a, 0, 5, range(32)) + self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32)) def test_char_ptr(self): s = b"abcdefghijklmnopqrstuvwxyz" @@ -42,15 +70,32 @@ class SlicesTestCase(unittest.TestCase): dll.my_free.restype = None res = dll.my_strdup(s) self.failUnlessEqual(res[:len(s)], s) + self.failUnlessEqual(res[:3], s[:3]) + self.failUnlessEqual(res[:len(s):], s) + self.failUnlessEqual(res[len(s)-1:-1:-1], s[::-1]) + self.failUnlessEqual(res[len(s)-1:5:-7], s[:5:-7]) + self.failUnlessEqual(res[0:-1:-1], s[0::-1]) import operator + self.assertRaises(ValueError, operator.getitem, + res, slice(None, None, None)) + self.assertRaises(ValueError, operator.getitem, + res, slice(0, None, None)) + self.assertRaises(ValueError, operator.getitem, + res, slice(None, 5, -1)) + self.assertRaises(ValueError, operator.getitem, + res, slice(-5, None, None)) + self.assertRaises(TypeError, operator.setslice, res, 0, 5, "abcde") + self.assertRaises(TypeError, operator.setitem, + res, slice(0, 5), "abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) self.failUnlessEqual(res[:len(s)], list(range(ord("a"), ord("z")+1))) + self.failUnlessEqual(res[:len(s):], list(range(ord("a"), ord("z")+1))) dll.my_free(res) def test_char_ptr_with_free(self): @@ -80,6 +125,10 @@ class SlicesTestCase(unittest.TestCase): p = (c_char * 27)(*s) self.failUnlessEqual(p[:], s) + self.failUnlessEqual(p[::], s) + self.failUnlessEqual(p[::-1], s[::-1]) + self.failUnlessEqual(p[5::-2], s[5::-2]) + self.failUnlessEqual(p[2:5:-3], s[2:5:-3]) try: @@ -96,10 +145,15 @@ class SlicesTestCase(unittest.TestCase): dll.my_free.restype = None res = dll.my_wcsdup(s) self.failUnlessEqual(res[:len(s)], s) + self.failUnlessEqual(res[:len(s):], s) + self.failUnlessEqual(res[len(s)-1:-1:-1], s[::-1]) + self.failUnlessEqual(res[len(s)-1:5:-7], s[:5:-7]) import operator self.assertRaises(TypeError, operator.setslice, res, 0, 5, "abcde") + self.assertRaises(TypeError, operator.setitem, + res, slice(0, 5), "abcde") dll.my_free(res) if sizeof(c_wchar) == sizeof(c_short): @@ -111,8 +165,11 @@ class SlicesTestCase(unittest.TestCase): else: return res = dll.my_wcsdup(s) - self.failUnlessEqual(res[:len(s)-1], - list(range(ord("a"), ord("z")+1))) + tmpl = list(range(ord("a"), ord("z")+1)) + self.failUnlessEqual(res[:len(s)-1], tmpl) + self.failUnlessEqual(res[:len(s)-1:], tmpl) + self.failUnlessEqual(res[len(s)-2:-1:-1], tmpl[::-1]) + self.failUnlessEqual(res[len(s)-2:5:-7], tmpl[:5:-7]) dll.my_free(res) ################################################################ diff --git a/Lib/ctypes/test/test_strings.py b/Lib/ctypes/test/test_strings.py index 17c78a0..ad3c49e 100644 --- a/Lib/ctypes/test/test_strings.py +++ b/Lib/ctypes/test/test_strings.py @@ -121,6 +121,9 @@ class StringTestCase(unittest.TestCase): def XX_test_initialized_strings(self): self.failUnless(c_string("ab", 4).raw[:2] == "ab") + self.failUnless(c_string("ab", 4).raw[:2:] == "ab") + self.failUnless(c_string("ab", 4).raw[:2:-1] == "ba") + self.failUnless(c_string("ab", 4).raw[:2:2] == "a") self.failUnless(c_string("ab", 4).raw[-1] == "\000") self.failUnless(c_string("ab", 2).raw == "a\000") diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index 0aa4aea..b50e4df 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -236,7 +236,13 @@ class StructureTestCase(unittest.TestCase): # can use tuple to initialize array (but not list!) self.failUnlessEqual(SomeInts((1, 2)).a[:], [1, 2, 0, 0]) + self.failUnlessEqual(SomeInts((1, 2)).a[::], [1, 2, 0, 0]) + self.failUnlessEqual(SomeInts((1, 2)).a[::-1], [0, 0, 2, 1]) + self.failUnlessEqual(SomeInts((1, 2)).a[::2], [1, 0]) + self.failUnlessEqual(SomeInts((1, 2)).a[1:5:6], [2]) + self.failUnlessEqual(SomeInts((1, 2)).a[6:4:-1], []) self.failUnlessEqual(SomeInts((1, 2, 3, 4)).a[:], [1, 2, 3, 4]) + self.failUnlessEqual(SomeInts((1, 2, 3, 4)).a[::], [1, 2, 3, 4]) # too long # XXX Should raise ValueError?, not RuntimeError self.assertRaises(RuntimeError, SomeInts, (1, 2, 3, 4, 5)) diff --git a/Lib/ctypes/test/test_unicode.py b/Lib/ctypes/test/test_unicode.py index bf5486c..717805e 100644 --- a/Lib/ctypes/test/test_unicode.py +++ b/Lib/ctypes/test/test_unicode.py @@ -58,11 +58,19 @@ else: ctypes.set_conversion_mode("ascii", "replace") buf = ctypes.create_unicode_buffer(b"ab\xe4\xf6\xfc") self.failUnlessEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0") + self.failUnlessEqual(buf[::], "ab\uFFFD\uFFFD\uFFFD\0") + self.failUnlessEqual(buf[::-1], "\0\uFFFD\uFFFD\uFFFDba") + self.failUnlessEqual(buf[::2], "a\uFFFD\uFFFD") + self.failUnlessEqual(buf[6:5:-1], "") ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_unicode_buffer(b"ab\xe4\xf6\xfc") # is that correct? not sure. But with 'ignore', you get what you pay for.. self.failUnlessEqual(buf[:], "ab\0\0\0\0") + self.failUnlessEqual(buf[::], "ab\0\0\0\0") + self.failUnlessEqual(buf[::-1], "\0\0\0\0ba") + self.failUnlessEqual(buf[::2], "a\0\0") + self.failUnlessEqual(buf[6:5:-1], "") import _ctypes_test func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p @@ -104,11 +112,17 @@ else: ctypes.set_conversion_mode("ascii", "replace") buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc") self.failUnlessEqual(buf[:], "ab???\0") + self.failUnlessEqual(buf[::], "ab???\0") + self.failUnlessEqual(buf[::-1], "\0???ba") + self.failUnlessEqual(buf[::2], "a??") + self.failUnlessEqual(buf[6:5:-1], "") ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc") # is that correct? not sure. But with 'ignore', you get what you pay for.. self.failUnlessEqual(buf[:], "ab\0\0\0\0") + self.failUnlessEqual(buf[::], "ab\0\0\0\0") + self.failUnlessEqual(buf[::-1], "\0\0\0\0ba") if __name__ == '__main__': unittest.main() |