contrib/python-zstandard/tests/common.py
changeset 31796 e0dc40530c5a
parent 30895 c32454d69b85
child 37495 b1fb341d8a61
equal deleted inserted replaced
31795:2b130e26c3a4 31796:e0dc40530c5a
     1 import inspect
     1 import inspect
     2 import io
     2 import io
       
     3 import os
     3 import types
     4 import types
     4 
     5 
     5 
     6 
     6 def make_cffi(cls):
     7 def make_cffi(cls):
     7     """Decorator to add CFFI versions of each test method."""
     8     """Decorator to add CFFI versions of each test method."""
    57         return super(OpCountingBytesIO, self).read(*args)
    58         return super(OpCountingBytesIO, self).read(*args)
    58 
    59 
    59     def write(self, data):
    60     def write(self, data):
    60         self._write_count += 1
    61         self._write_count += 1
    61         return super(OpCountingBytesIO, self).write(data)
    62         return super(OpCountingBytesIO, self).write(data)
       
    63 
       
    64 
       
    65 _source_files = []
       
    66 
       
    67 
       
    68 def random_input_data():
       
    69     """Obtain the raw content of source files.
       
    70 
       
    71     This is used for generating "random" data to feed into fuzzing, since it is
       
    72     faster than random content generation.
       
    73     """
       
    74     if _source_files:
       
    75         return _source_files
       
    76 
       
    77     for root, dirs, files in os.walk(os.path.dirname(__file__)):
       
    78         dirs[:] = list(sorted(dirs))
       
    79         for f in sorted(files):
       
    80             try:
       
    81                 with open(os.path.join(root, f), 'rb') as fh:
       
    82                     data = fh.read()
       
    83                     if data:
       
    84                         _source_files.append(data)
       
    85             except OSError:
       
    86                 pass
       
    87 
       
    88     return _source_files