summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-05 03:33:28 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-05 03:33:28 (GMT)
commit29e762c94172a4e0b2855f188399f8f05487920e (patch)
tree5cca8580f7009420f90e7837b70a8ef5e6ac59d8 /Lib/test/test_bytes.py
parentaaa4e9a4380f904c6ae4e7dadd229c48d3adc615 (diff)
downloadcpython-29e762c94172a4e0b2855f188399f8f05487920e.zip
cpython-29e762c94172a4e0b2855f188399f8f05487920e.tar.gz
cpython-29e762c94172a4e0b2855f188399f8f05487920e.tar.bz2
test_bytes: test PyBytes_FromFormat() using ctypes
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 24ee487..e5c7ccd 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -497,6 +497,27 @@ class BytesTest(BaseBytesTest):
return None
self.assertRaises(TypeError, bytes, A())
+ # Test PyBytes_FromFormat()
+ def test_from_format(self):
+ test.support.import_module('ctypes')
+ from ctypes import pythonapi, py_object, c_int, c_char_p
+ PyBytes_FromFormat = pythonapi.PyBytes_FromFormat
+ PyBytes_FromFormat.restype = py_object
+
+ self.assertEqual(PyBytes_FromFormat(b'format'),
+ b'format')
+
+ self.assertEqual(PyBytes_FromFormat(b'%'), b'%')
+ self.assertEqual(PyBytes_FromFormat(b'%%'), b'%')
+ self.assertEqual(PyBytes_FromFormat(b'%%s'), b'%s')
+ self.assertEqual(PyBytes_FromFormat(b'[%%]'), b'[%]')
+ self.assertEqual(PyBytes_FromFormat(b'%%%c', c_int(ord('_'))), b'%_')
+
+ self.assertEqual(PyBytes_FromFormat(b'c:%c', c_int(255)),
+ b'c:\xff')
+ self.assertEqual(PyBytes_FromFormat(b's:%s', c_char_p(b'cstr')),
+ b's:cstr')
+
class ByteArrayTest(BaseBytesTest):
type2test = bytearray