Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_zlib.CompressTestCase Class Reference
Inheritance diagram for test.test_zlib.CompressTestCase:
Inheritance graph
[legend]
Collaboration diagram for test.test_zlib.CompressTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_speech
def test_speech128
def test_incomplete_stream
def test_big_compress_buffer
def test_big_decompress_buffer
def test_length_overflow
def check_big_compress_buffer
def check_big_decompress_buffer

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Definition at line 157 of file test_zlib.py.


Member Function Documentation

def test.test_zlib.BaseCompressTestCase.check_big_compress_buffer (   self,
  size,
  compress_func 
) [inherited]

Definition at line 126 of file test_zlib.py.

00126 
00127     def check_big_compress_buffer(self, size, compress_func):
00128         _1M = 1024 * 1024
00129         fmt = "%%0%dx" % (2 * _1M)
00130         # Generate 10MB worth of random, and expand it by repeating it.
00131         # The assumption is that zlib's memory is not big enough to exploit
00132         # such spread out redundancy.
00133         data = b''.join([random.getrandbits(8 * _1M).to_bytes(_1M, 'little')
00134                         for i in range(10)])
00135         data = data * (size // len(data) + 1)
00136         try:
00137             compress_func(data)
00138         finally:
00139             # Release memory
00140             data = None

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_zlib.BaseCompressTestCase.check_big_decompress_buffer (   self,
  size,
  decompress_func 
) [inherited]

Definition at line 141 of file test_zlib.py.

00141 
00142     def check_big_decompress_buffer(self, size, decompress_func):
00143         data = b'x' * size
00144         try:
00145             compressed = zlib.compress(data, 1)
00146         finally:
00147             # Release memory
00148             data = None
00149         data = decompress_func(compressed)
00150         # Sanity check
00151         try:
00152             self.assertEqual(len(data), size)
00153             self.assertEqual(len(data.strip(b'x')), 0)
00154         finally:
00155             data = None
00156 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 181 of file test_zlib.py.

00181 
00182     def test_big_compress_buffer(self, size):
00183         compress = lambda s: zlib.compress(s, 1)
00184         self.check_big_compress_buffer(size, compress)

Here is the call graph for this function:

Definition at line 186 of file test_zlib.py.

00186 
00187     def test_big_decompress_buffer(self, size):
00188         self.check_big_decompress_buffer(size, zlib.decompress)

Here is the call graph for this function:

Definition at line 171 of file test_zlib.py.

00171 
00172     def test_incomplete_stream(self):
00173         # An useful error message is given
00174         x = zlib.compress(HAMLET_SCENE)
00175         self.assertRaisesRegex(zlib.error,
00176             "Error -5 while decompressing data: incomplete or truncated stream",
00177             zlib.decompress, x[:-1])

Here is the call graph for this function:

Definition at line 190 of file test_zlib.py.

00190 
00191     def test_length_overflow(self, size):
00192         if size < _4G + 100:
00193             self.skipTest("not enough free memory, need at least 4 GB")
00194         data = b'x' * size
00195         try:
00196             self.assertRaises(OverflowError, zlib.compress, data, 1)
00197             self.assertRaises(OverflowError, zlib.decompress, data)
00198         finally:
00199             data = None
00200 

Here is the call graph for this function:

Definition at line 159 of file test_zlib.py.

00159 
00160     def test_speech(self):
00161         x = zlib.compress(HAMLET_SCENE)
00162         self.assertEqual(zlib.decompress(x), HAMLET_SCENE)

Here is the call graph for this function:

Definition at line 163 of file test_zlib.py.

00163 
00164     def test_speech128(self):
00165         # compress more data
00166         data = HAMLET_SCENE * 128
00167         x = zlib.compress(data)
00168         self.assertEqual(zlib.compress(bytearray(data)), x)
00169         for ob in x, bytearray(x):
00170             self.assertEqual(zlib.decompress(ob), data)

Here is the call graph for this function:


Member Data Documentation

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: