diff -r a5c8b6ebe895 -r c940e8bc9968 Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py Fri Jun 10 01:39:53 2011 +0200 +++ b/Lib/test/test_zlib.py Fri Jun 10 03:02:14 2011 +0200 @@ -13,6 +13,16 @@ mmap = None +class VersionTestCase(unittest.TestCase): + + def test_library_version(self): + # On the build system, zlibVersion() and ZLIB_VERSION should match. + # zlibVersion() is the actual library version while ZLIB_VERSION is + # the version from the header file. On the build system, the headers + # should match with the library exactly. At runtime, only the first + # digit is required to match. + self.assertEqual(zlib.zlibVersion(), zlib.ZLIB_VERSION) + class ChecksumTestCase(unittest.TestCase): # checksum test cases def test_crc32start(self): @@ -627,6 +637,7 @@ def test_main(): support.run_unittest( + VersionTestCase, ChecksumTestCase, ChecksumBigBufferTestCase, ExceptionTestCase, diff -r a5c8b6ebe895 -r c940e8bc9968 Modules/zlibmodule.c --- a/Modules/zlibmodule.c Fri Jun 10 01:39:53 2011 +0200 +++ b/Modules/zlibmodule.c Fri Jun 10 03:02:14 2011 +0200 @@ -1015,6 +1015,18 @@ } +PyDoc_STRVAR(zlibVersion__doc__, +"zlibVersion() -- Report actual zlib library version loaded at runtime.\n" +"\n" +"Returns a string, for example '1.2.5'."); + +static PyObject * +PyZlib_zlibVersion(PyObject *self, PyObject *args) +{ + return PyUnicode_FromString(zlibVersion()); +} + + static PyMethodDef zlib_methods[] = { {"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS, @@ -1029,6 +1041,8 @@ decompress__doc__}, {"decompressobj", (PyCFunction)PyZlib_decompressobj, METH_VARARGS, decompressobj__doc__}, + {"zlibVersion", (PyCFunction)PyZlib_zlibVersion, METH_NOARGS, + zlibVersion__doc__}, {NULL, NULL} };