| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,16 +9,15 @@ | |||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | class MemFunctionsTest(unittest.TestCase): | |
| 12 | - @unittest.skip('test disabled') | ||
| 13 | 12 | def test_overflow(self): | |
| 14 | 13 | # string_at and wstring_at must use the Python calling | |
| 15 | 14 | # convention (which acquires the GIL and checks the Python | |
| 16 | 15 | # error flag). Provoke an error and catch it; see also issue | |
| 17 | - # #3554: <http://bugs.python.org/issue3554> | ||
| 16 | + # gh-47804. | ||
| 18 | 17 | self.assertRaises((OverflowError, MemoryError, SystemError), | |
| 19 | - lambda: wstring_at(u"foo", sys.maxint - 1)) | ||
| 18 | + lambda: wstring_at(u"foo", sys.maxsize - 1)) | ||
| 20 | 19 | self.assertRaises((OverflowError, MemoryError, SystemError), | |
| 21 | - lambda: string_at("foo", sys.maxint - 1)) | ||
| 20 | + lambda: string_at("foo", sys.maxsize - 1)) | ||
| 22 | 21 | ||
| 23 | 22 | def test_memmove(self): | |
| 24 | 23 | # large buffers apparently increase the chance that the memory | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | import unittest | |
| 2 | - from ctypes import create_string_buffer, sizeof, byref, c_char, c_wchar | ||
| 2 | + from ctypes import (create_string_buffer, create_unicode_buffer, | ||
| 3 | + sizeof, byref, c_char, c_wchar) | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | class StringArrayTestCase(unittest.TestCase): | |
@@ -88,41 +89,35 @@ def test_wchar(self): | |||
| 88 | 89 | repr(byref(c_wchar("x"))) | |
| 89 | 90 | c_wchar("x") | |
| 90 | 91 | ||
| 91 | - @unittest.skip('test disabled') | ||
| 92 | 92 | def test_basic_wstrings(self): | |
| 93 | - cs = c_wstring("abcdef") | ||
| 94 | - | ||
| 95 | - # XXX This behaviour is about to change: | ||
| 96 | - # len returns the size of the internal buffer in bytes. | ||
| 97 | - # This includes the terminating NUL character. | ||
| 98 | - self.assertEqual(sizeof(cs), 14) | ||
| 99 | - | ||
| 100 | - # The value property is the string up to the first terminating NUL. | ||
| 93 | + cs = create_unicode_buffer("abcdef") | ||
| 101 | 94 | self.assertEqual(cs.value, "abcdef") | |
| 102 | - self.assertEqual(c_wstring("abc\000def").value, "abc") | ||
| 103 | 95 | ||
| 104 | - self.assertEqual(c_wstring("abc\000def").value, "abc") | ||
| 96 | + # value can be changed | ||
| 97 | + cs.value = "abc" | ||
| 98 | + self.assertEqual(cs.value, "abc") | ||
| 99 | + | ||
| 100 | + # string is truncated at NUL character | ||
| 101 | + cs.value = "def\0z" | ||
| 102 | + self.assertEqual(cs.value, "def") | ||
| 105 | 103 | ||
| 106 | - # The raw property is the total buffer contents: | ||
| 107 | - self.assertEqual(cs.raw, "abcdef\000") | ||
| 108 | - self.assertEqual(c_wstring("abc\000def").raw, "abc\000def\000") | ||
| 104 | + self.assertEqual(create_unicode_buffer("abc\0def").value, "abc") | ||
| 109 | 105 | ||
| 110 | - # We can change the value: | ||
| 111 | - cs.value = "ab" | ||
| 112 | - self.assertEqual(cs.value, "ab") | ||
| 113 | - self.assertEqual(cs.raw, "ab\000\000\000\000\000") | ||
| 106 | + # created with an empty string | ||
| 107 | + cs = create_unicode_buffer(3) | ||
| 108 | + self.assertEqual(cs.value, "") | ||
| 114 | 109 | ||
| 115 | - self.assertRaises(TypeError, c_wstring, "123") | ||
| 116 | - self.assertRaises(ValueError, c_wstring, 0) | ||
| 110 | + cs.value = "abc" | ||
| 111 | + self.assertEqual(cs.value, "abc") | ||
| 117 | 112 | ||
| 118 | - @unittest.skip('test disabled') | ||
| 119 | 113 | def test_toolong(self): | |
| 120 | - cs = c_wstring("abcdef") | ||
| 121 | - # Much too long string: | ||
| 122 | - self.assertRaises(ValueError, setattr, cs, "value", "123456789012345") | ||
| 114 | + cs = create_unicode_buffer("abc") | ||
| 115 | + with self.assertRaises(ValueError): | ||
| 116 | + cs.value = "abcdef" | ||
| 123 | 117 | ||
| 124 | - # One char too long values: | ||
| 125 | - self.assertRaises(ValueError, setattr, cs, "value", "1234567") | ||
| 118 | + cs = create_unicode_buffer(4) | ||
| 119 | + with self.assertRaises(ValueError): | ||
| 120 | + cs.value = "abcdef" | ||
| 126 | 121 | ||
| 127 | 122 | ||
| 128 | 123 | def run_test(rep, msg, func, arg): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments