diff -r cc3255a707c7 Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py Thu Jun 09 16:01:09 2011 -0400 +++ b/Lib/test/test_zlib.py Fri Jun 10 02:46:22 2011 +0200 @@ -13,6 +13,16 @@ zlib = import_module('zlib') +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): @@ -562,6 +572,7 @@ def test_main(): run_unittest( + VersionTestCase, ChecksumTestCase, ExceptionTestCase, CompressTestCase, diff -r cc3255a707c7 Modules/zlibmodule.c --- a/Modules/zlibmodule.c Thu Jun 09 16:01:09 2011 -0400 +++ b/Modules/zlibmodule.c Fri Jun 10 02:46:22 2011 +0200 @@ -950,6 +950,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 PyString_FromString(zlibVersion()); +} + + static PyMethodDef zlib_methods[] = { {"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS, @@ -964,6 +976,8 @@ decompress__doc__}, {"decompressobj", (PyCFunction)PyZlib_decompressobj, METH_VARARGS, decompressobj__doc__}, + {"zlibVersion", (PyCFunction)PyZlib_zlibVersion, METH_NOARGS, + zlibVersion__doc__}, {NULL, NULL} };