[python-hdf5storage] 56/84: Separated out all the random variable making methods in tests/test_write_readback.py from the master branch into their own test module (tests/make_randoms.py) and made the tests use them.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:25:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 0.1.10
in repository python-hdf5storage.

commit 8b6e6e38653aeda3d1bf6f70c49da66277838b76
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Mon Aug 17 21:20:51 2015 -0400

    Separated out all the random variable making methods in tests/test_write_readback.py from the master branch into their own test module (tests/make_randoms.py) and made the tests use them.
---
 tests/make_randoms.py        | 277 ++++++++++++++++++++++++++++++++++
 tests/test_write_readback.py | 349 +++++++++----------------------------------
 2 files changed, 348 insertions(+), 278 deletions(-)

diff --git a/tests/make_randoms.py b/tests/make_randoms.py
new file mode 100644
index 0000000..39747b7
--- /dev/null
+++ b/tests/make_randoms.py
@@ -0,0 +1,277 @@
+# Copyright (c) 2013-2015, Freja Nordsiek
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import sys
+import posixpath
+import string
+import random
+
+import numpy as np
+import numpy.random
+
+
+random.seed()
+
+
+# The dtypes that can be made
+dtypes = ['bool', 'uint8', 'uint16', 'uint32', 'uint64',
+          'int8', 'int16', 'int32', 'int64',
+          'float32', 'float64', 'complex64', 'complex128',
+          'S', 'U']
+
+# Define the sizes of random datasets to use.
+max_string_length = 10
+max_array_axis_length = 8
+max_list_length = 6
+max_posix_path_depth = 5
+max_posix_path_lengths = 17
+object_subarray_dimensions = 2
+max_object_subarray_axis_length = 5
+min_dict_keys = 4
+max_dict_keys = 12
+max_dict_key_length = 10
+dict_value_subarray_dimensions = 2
+max_dict_value_subarray_axis_length = 5
+min_structured_ndarray_fields = 2
+max_structured_ndarray_fields = 5
+max_structured_ndarray_field_lengths = 10
+max_structured_ndarray_axis_length = 2
+structured_ndarray_subarray_dimensions = 2
+max_structured_ndarray_subarray_axis_length = 4
+
+
+def random_str_ascii(length):
+    # Makes a random ASCII str of the specified length.
+    if sys.hexversion >= 0x03000000:
+        ltrs = string.ascii_letters + string.digits
+        return ''.join([random.choice(ltrs) for i in
+                       range(0, length)])
+    else:
+        ltrs = unicode(string.ascii_letters + string.digits)
+        return u''.join([random.choice(ltrs) for i in
+                        range(0, length)])
+
+
+def random_str_some_unicode(length):
+    # Makes a random ASCII+limited unicode str of the specified
+    # length.
+    ltrs = random_str_ascii(10)
+    if sys.hexversion >= 0x03000000:
+        ltrs += ''.join([chr(500 + i) for i in range(100)])
+    else:
+        ltrs += u''.join([unichr(500 + i) for i in range(100)])
+    return ''.join([random.choice(ltrs) for i in range(0, length)])
+
+
+def random_bytes(length):
+    # Makes a random sequence of bytes of the specified length from
+    # the ASCII set.
+    ltrs = bytes(range(1, 127))
+    return bytes([random.choice(ltrs) for i in range(0, length)])
+
+
+def random_bytes_fullrange(length):
+    # Makes a random sequence of bytes of the specified length from
+    # the ASCII set.
+    ltrs = bytes(range(1, 255))
+    return bytes([random.choice(ltrs) for i in range(0, length)])
+
+def random_int():
+    return random.randint(-(2**63 - 1), 2**63)
+
+
+def random_float():
+    return random.uniform(-1.0, 1.0) \
+        * 10.0**random.randint(-300, 300)
+
+
+def random_numpy(shape, dtype, allow_nan=True,
+                 allow_unicode=False):
+    # Makes a random numpy array of the specified shape and dtype
+    # string. The method is slightly different depending on the
+    # type. For 'bytes', 'str', and 'object'; an array of the
+    # specified size is made and then each element is set to either
+    # a numpy.bytes_, numpy.str_, or some other object of any type
+    # (here, it is a randomly typed random numpy array). If it is
+    # any other type, then it is just a matter of constructing the
+    # right sized ndarray from a random sequence of bytes (all must
+    # be forced to 0 and 1 for bool). Optionally include unicode
+    # characters.
+    if dtype == 'S':
+        length = random.randint(1, max_string_length)
+        data = np.zeros(shape=shape, dtype='S' + str(length))
+        for x in np.nditer(data, op_flags=['readwrite']):
+            if allow_unicode:
+                chars = random_bytes_fullrange(length)
+            else:
+                chars = random_bytes(length)
+            x[...] = np.bytes_(chars)
+        return data
+    elif dtype == 'U':
+        length = random.randint(1, max_string_length)
+        data = np.zeros(shape=shape, dtype='U' + str(length))
+        for x in np.nditer(data, op_flags=['readwrite']):
+            if allow_unicode:
+                chars = _random_str_some_unicode(length)
+            else:
+                chars = random_str_ascii(length)
+            x[...] = np.unicode_(chars)
+        return data
+    elif dtype == 'object':
+        data = np.zeros(shape=shape, dtype='object')
+        for index, x in np.ndenumerate(data):
+            data[index] = random_numpy( \
+                shape=random_numpy_shape( \
+                object_subarray_dimensions, \
+                max_object_subarray_axis_length), \
+                dtype=random.choice(dtypes))
+        return data
+    else:
+        nbytes = np.ndarray(shape=(1,), dtype=dtype).nbytes
+        bts = np.random.bytes(nbytes * np.prod(shape))
+        if dtype == 'bool':
+            bts = b''.join([{True: b'\x01', False: b'\x00'}[ \
+                ch > 127] for ch in bts])
+        data = np.ndarray(shape=shape, dtype=dtype, buffer=bts)
+        # If it is a floating point type and we are supposed to
+        # remove NaN's, then turn them to zeros.
+        if not allow_nan and data.dtype.kind in ('f', 'c') \
+            and np.any(np.isnan(data)):
+            data = data.copy()
+            data[np.isnan(data)] = 0.0
+        return data
+
+
+def random_numpy_scalar(dtype):
+    # How a random scalar is made depends on th type. For must, it
+    # is just a single number. But for the string types, it is a
+    # string of any length.
+    if dtype == 'S':
+        return np.bytes_(random_bytes(random.randint(1,
+                         max_string_length)))
+    elif dtype == 'U':
+        return np.unicode_(random_str_ascii(
+                           random.randint(1,
+                           max_string_length)))
+    else:
+        return random_numpy(tuple(), dtype)[()]
+
+
+def random_numpy_shape(dimensions, max_length):
+    # Makes a random shape tuple having the specified number of
+    # dimensions. The maximum size along each axis is max_length.
+    return tuple([random.randint(1, max_length) for x in range(0,
+                 dimensions)])
+
+
+def random_list(N, python_or_numpy='numpy'):
+    # Makes a random list of the specified type. If instructed, it
+    # will be composed entirely from random numpy arrays (make a
+    # random object array and then convert that to a
+    # list). Otherwise, it will be a list of random bytes.
+    if python_or_numpy == 'numpy':
+        return random_numpy((N,), dtype='object').tolist()
+    else:
+        data = []
+        for i in range(0, N):
+            data.append(random_bytes(random.randint(1,
+                        max_string_length)))
+        return data
+
+
+def random_dict():
+    # Makes a random dict (random number of randomized keys with
+    # random numpy arrays as values).
+    data = dict()
+    for i in range(0, random.randint(min_dict_keys, \
+            max_dict_keys)):
+        name = random_str_ascii(max_dict_key_length)
+        data[name] = \
+            random_numpy(random_numpy_shape( \
+            dict_value_subarray_dimensions, \
+            max_dict_value_subarray_axis_length), \
+            dtype=random.choice(dtypes))
+    return data
+
+
+def random_structured_numpy_array(shape, field_shapes=None,
+                                  nonascii_fields=False):
+    # Make random field names, dtypes, and sizes. Though, if
+    # field_shapes is explicitly given, the sizes should be
+    # random. The field names must all be of type str, not unicode
+    # in Python 2. Optionally include non-ascii characters in the
+    # field names (will have to be encoded in Python 2.x). String
+    # types will not be used due to the difficulty in assigning the
+    # length.
+    if nonascii_fields:
+        name_func = random_str_some_unicode
+    else:
+        name_func = random_str_ascii
+    names = [name_func(
+             max_structured_ndarray_field_lengths)
+             for i in range(0, random.randint(
+             min_structured_ndarray_fields,
+             max_structured_ndarray_fields))]
+    if sys.hexversion < 0x03000000:
+        for i, name in enumerate(names):
+            names[i] = name.encode('UTF-8')
+    dts = [random.choice(list(set(dtypes)
+           - set(('S', 'U'))))
+           for i in range(len(names))]
+    if field_shapes is None:
+        shapes = [random_numpy_shape(
+                  structured_ndarray_subarray_dimensions,
+                  max_structured_ndarray_subarray_axis_length)
+                  for i in range(len(names))]
+    else:
+        shapes = [field_shapes] * len(names)
+    # Construct the type of the whole thing.
+    dt = np.dtype([(names[i], dts[i], shapes[i])
+                  for i in range(len(names))])
+    # Make the array. If dt.itemsize is 0, then we need to make an
+    # array of int8's the size in shape and convert it to work
+    # around a numpy bug. Otherwise, we will just create an empty
+    # array and then proceed by assigning each field.
+    if dt.itemsize == 0:
+        return np.zeros(shape=shape, dtype='int8').astype(dt)
+    else:
+        data = np.empty(shape=shape, dtype=dt)
+        for index, x in np.ndenumerate(data):
+            for i, name in enumerate(names):
+                data[name][index] = random_numpy(shapes[i], \
+                    dts[i], allow_nan=False)
+        return data
+
+
+def random_name():
+    # Makes a random POSIX path of a random depth.
+    depth = random.randint(1, max_posix_path_depth)
+    path = '/'
+    for i in range(0, depth):
+        path = posixpath.join(path, random_str_ascii(
+                              random.randint(1,
+                              max_posix_path_lengths)))
+    return path
diff --git a/tests/test_write_readback.py b/tests/test_write_readback.py
index dd86440..24b2d9c 100644
--- a/tests/test_write_readback.py
+++ b/tests/test_write_readback.py
@@ -43,6 +43,7 @@ import hdf5storage
 from nose.tools import raises
 
 from asserts import *
+from make_randoms import *
 
 
 random.seed()
@@ -66,213 +67,6 @@ class TestPythonMatlabFormat(object):
                        'float32', 'float64', 'complex64', 'complex128',
                        'S', 'U']
 
-        # Define the sizes of random datasets to use.
-        self.max_string_length = 10
-        self.max_array_axis_length = 8
-        self.max_list_length = 6
-        self.max_posix_path_depth = 5
-        self.max_posix_path_lengths = 17
-        self.object_subarray_dimensions = 2
-        self.max_object_subarray_axis_length = 5
-        self.min_dict_keys = 4
-        self.max_dict_keys = 12
-        self.max_dict_key_length = 10
-        self.dict_value_subarray_dimensions = 2
-        self.max_dict_value_subarray_axis_length = 5
-        self.min_structured_ndarray_fields = 2
-        self.max_structured_ndarray_fields = 5
-        self.max_structured_ndarray_field_lengths = 10
-        self.max_structured_ndarray_axis_length = 2
-        self.structured_ndarray_subarray_dimensions = 2
-        self.max_structured_ndarray_subarray_axis_length = 4
-        
-
-    def random_str_ascii(self, length):
-        # Makes a random ASCII str of the specified length.
-        if sys.hexversion >= 0x03000000:
-            ltrs = string.ascii_letters + string.digits
-            return ''.join([random.choice(ltrs) for i in \
-                range(0, length)])
-        else:
-            ltrs = unicode(string.ascii_letters + string.digits)
-            return u''.join([random.choice(ltrs) for i in \
-                range(0, length)])
-
-    def random_str_some_unicode(self, length):
-        # Makes a random ASCII+limited unicode str of the specified
-        # length.
-        ltrs = self.random_str_ascii(10)
-        if sys.hexversion >= 0x03000000:
-            ltrs += ''.join([chr(500 + i) for i in range(100)])
-        else:
-            ltrs += u''.join([unichr(500 + i) for i in range(100)])
-        return ''.join([random.choice(ltrs) for i in range(0, length)])
-
-    def random_bytes(self, length):
-        # Makes a random sequence of bytes of the specified length from
-        # the ASCII set.
-        ltrs = bytes(range(1, 127))
-        return bytes([random.choice(ltrs) for i in range(0, length)])
-
-    def random_int(self):
-        return random.randint(-(2**63 - 1), 2**63)
-
-    def random_float(self):
-        return random.uniform(-1.0, 1.0) \
-            * 10.0**random.randint(-300, 300)
-
-    def random_numpy(self, shape, dtype, allow_nan=True):
-        # Makes a random numpy array of the specified shape and dtype
-        # string. The method is slightly different depending on the
-        # type. For 'bytes', 'str', and 'object'; an array of the
-        # specified size is made and then each element is set to either
-        # a numpy.bytes_, numpy.str_, or some other object of any type
-        # (here, it is a randomly typed random numpy array). If it is
-        # any other type, then it is just a matter of constructing the
-        # right sized ndarray from a random sequence of bytes (all must
-        # be forced to 0 and 1 for bool).
-        if dtype == 'S':
-            length = random.randint(1, self.max_string_length)
-            data = np.zeros(shape=shape, dtype='S' + str(length))
-            for x in np.nditer(data, op_flags=['readwrite']):
-                x[...] = np.bytes_(self.random_bytes(length))
-            return data
-        elif dtype == 'U':
-            length = random.randint(1, self.max_string_length)
-            data = np.zeros(shape=shape, dtype='U' + str(length))
-            for x in np.nditer(data, op_flags=['readwrite']):
-                x[...] = np.unicode_(self.random_str_ascii(length))
-            return data
-        elif dtype == 'object':
-            data = np.zeros(shape=shape, dtype='object')
-            for index, x in np.ndenumerate(data):
-                data[index] = self.random_numpy( \
-                    shape=self.random_numpy_shape( \
-                    self.object_subarray_dimensions, \
-                    self.max_object_subarray_axis_length), \
-                    dtype=random.choice(self.dtypes))
-            return data
-        else:
-            nbytes = np.ndarray(shape=(1,), dtype=dtype).nbytes
-            bts = np.random.bytes(nbytes * np.prod(shape))
-            if dtype == 'bool':
-                bts = b''.join([{True: b'\x01', False: b'\x00'}[ \
-                    ch > 127] for ch in bts])
-            data = np.ndarray(shape=shape, dtype=dtype, buffer=bts)
-            # If it is a floating point type and we are supposed to
-            # remove NaN's, then turn them to zeros.
-            if not allow_nan and data.dtype.kind in ('f', 'c') \
-                and np.any(np.isnan(data)):
-                data = data.copy()
-                data[np.isnan(data)] = 0.0
-            return data
-
-    def random_numpy_scalar(self, dtype):
-        # How a random scalar is made depends on th type. For must, it
-        # is just a single number. But for the string types, it is a
-        # string of any length.
-        if dtype == 'S':
-            return np.bytes_(self.random_bytes(random.randint(1,
-                             self.max_string_length)))
-        elif dtype == 'U':
-            return np.unicode_(self.random_str_ascii(
-                               random.randint(1,
-                               self.max_string_length)))
-        else:
-            return self.random_numpy(tuple(), dtype)[()]
-
-    def random_numpy_shape(self, dimensions, max_length):
-        # Makes a random shape tuple having the specified number of
-        # dimensions. The maximum size along each axis is max_length.
-        return tuple([random.randint(1, max_length) for x in range(0,
-                     dimensions)])
-
-    def random_list(self, N, python_or_numpy='numpy'):
-        # Makes a random list of the specified type. If instructed, it
-        # will be composed entirely from random numpy arrays (make a
-        # random object array and then convert that to a
-        # list). Otherwise, it will be a list of random bytes.
-        if python_or_numpy == 'numpy':
-            return self.random_numpy((N,), dtype='object').tolist()
-        else:
-            data = []
-            for i in range(0, N):
-                data.append(self.random_bytes(random.randint(1,
-                            self.max_string_length)))
-            return data
-
-    def random_dict(self):
-        # Makes a random dict (random number of randomized keys with
-        # random numpy arrays as values).
-        data = dict()
-        for i in range(0, random.randint(self.min_dict_keys, \
-                self.max_dict_keys)):
-            name = self.random_str_ascii(self.max_dict_key_length)
-            data[name] = \
-                self.random_numpy(self.random_numpy_shape( \
-                self.dict_value_subarray_dimensions, \
-                self.max_dict_value_subarray_axis_length), \
-                dtype=random.choice(self.dtypes))
-        return data
-    
-    def random_structured_numpy_array(self, shape, field_shapes=None,
-                                      nonascii_fields=False):
-        # Make random field names, dtypes, and sizes. Though, if
-        # field_shapes is explicitly given, the sizes should be
-        # random. The field names must all be of type str, not unicode
-        # in Python 2. Optionally include non-ascii characters in the
-        # field names (will have to be encoded in Python 2.x). String
-        # types will not be used due to the difficulty in assigning the
-        # length.
-        if nonascii_fields:
-            name_func = self.random_str_some_unicode
-        else:
-            name_func = self.random_str_ascii
-        names = [name_func(
-                 self.max_structured_ndarray_field_lengths)
-                 for i in range(0, random.randint(
-                 self.min_structured_ndarray_fields,
-                 self.max_structured_ndarray_fields))]
-        if sys.hexversion < 0x03000000:
-            for i, name in enumerate(names):
-                names[i] = name.encode('UTF-8')
-        dtypes = [random.choice(list(set(self.dtypes)
-                  - set(('S', 'U'))))
-                  for i in range(len(names))]
-        if field_shapes is None:
-            shapes = [self.random_numpy_shape(
-                      self.structured_ndarray_subarray_dimensions,
-                      self.max_structured_ndarray_subarray_axis_length)
-                      for i in range(len(names))]
-        else:
-            shapes = [field_shapes] * len(names)
-        # Construct the type of the whole thing.
-        dt = np.dtype([(names[i], dtypes[i], shapes[i])
-                      for i in range(len(names))])
-        # Make the array. If dt.itemsize is 0, then we need to make an
-        # array of int8's the size in shape and convert it to work
-        # around a numpy bug. Otherwise, we will just create an empty
-        # array and then proceed by assigning each field.
-        if dt.itemsize == 0:
-            return np.zeros(shape=shape, dtype='int8').astype(dt)
-        else:
-            data = np.empty(shape=shape, dtype=dt)
-            for index, x in np.ndenumerate(data):
-                for i, name in enumerate(names):
-                    data[name][index] = self.random_numpy(shapes[i], \
-                        dtypes[i], allow_nan=False)
-            return data
-
-    def random_name(self):
-        # Makes a random POSIX path of a random depth.
-        depth = random.randint(1, self.max_posix_path_depth)
-        path = '/'
-        for i in range(0, depth):
-            path = posixpath.join(path, self.random_str_ascii(
-                                  random.randint(1,
-                                  self.max_posix_path_lengths)))
-        return path
-
     def write_readback(self, data, name, options):
         # Write the data to the proper file with the given name, read it
         # back, and return the result. The file needs to be deleted
@@ -297,18 +91,18 @@ class TestPythonMatlabFormat(object):
     def check_numpy_scalar(self, dtype):
         # Makes a random numpy scalar of the given type, writes it and
         # reads it back, and then compares it.
-        data = self.random_numpy_scalar(dtype)
-        out = self.write_readback(data, self.random_name(),
+        data = random_numpy_scalar(dtype)
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def check_numpy_array(self, dtype, dimensions):
         # Makes a random numpy array of the given type, writes it and
         # reads it back, and then compares it.
-        shape = self.random_numpy_shape(dimensions,
-                                        self.max_array_axis_length)
-        data = self.random_numpy(shape, dtype)
-        out = self.write_readback(data, self.random_name(),
+        shape = random_numpy_shape(dimensions,
+                                   max_array_axis_length)
+        data = random_numpy(shape, dtype)
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
@@ -316,27 +110,27 @@ class TestPythonMatlabFormat(object):
         # Makes an empty numpy array of the given type, writes it and
         # reads it back, and then compares it.
         data = np.array([], dtype)
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
     
     def check_numpy_structured_array(self, dimensions):
         # Makes a random structured ndarray of the given type, writes it
         # and reads it back, and then compares it.
-        shape = self.random_numpy_shape(dimensions, \
-            self.max_structured_ndarray_axis_length)
-        data = self.random_structured_numpy_array(shape)
-        out = self.write_readback(data, self.random_name(),
+        shape = random_numpy_shape(dimensions, \
+            max_structured_ndarray_axis_length)
+        data = random_structured_numpy_array(shape)
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
     
     def check_numpy_structured_array_empty(self, dimensions):
         # Makes a random structured ndarray of the given type, writes it
         # and reads it back, and then compares it.
-        shape = self.random_numpy_shape(dimensions, \
-            self.max_structured_ndarray_axis_length)
-        data = self.random_structured_numpy_array(shape, (1, 0))
-        out = self.write_readback(data, self.random_name(),
+        shape = random_numpy_shape(dimensions, \
+            max_structured_ndarray_axis_length)
+        data = random_structured_numpy_array(shape, (1, 0))
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
     
@@ -344,150 +138,150 @@ class TestPythonMatlabFormat(object):
         # Makes a random collection of the specified type, writes it and
         # reads it back, and then compares it.
         if tp in (set, frozenset):
-            data = tp(self.random_list(self.max_list_length,
+            data = tp(random_list(max_list_length,
                       python_or_numpy='python'))
         else:
-            data = tp(self.random_list(self.max_list_length,
+            data = tp(random_list(max_list_length,
                       python_or_numpy='numpy'))
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_None(self):
         data = None
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_bool_True(self):
         data = True
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_bool_False(self):
         data = False
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_int(self):
-        data = self.random_int()
-        out = self.write_readback(data, self.random_name(),
+        data = random_int()
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     # Only relevant in Python 2.x.
     def test_long(self):
         if sys.hexversion < 0x03000000:
-            data = long(self.random_int())
-            out = self.write_readback(data, self.random_name(),
+            data = long(random_int())
+            out = self.write_readback(data, random_name(),
                                       self.options)
             self.assert_equal(out, data)
 
     @raises(NotImplementedError)
     def test_int_or_long_too_big(self):
         if sys.hexversion >= 0x03000000:
-            data = 2**64 * self.random_int()
+            data = 2**64 * random_int()
         else:
-            data = long(2)**64 * long(self.random_int())
-        out = self.write_readback(data, self.random_name(),
+            data = long(2)**64 * long(random_int())
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_float(self):
-        data = self.random_float()
-        out = self.write_readback(data, self.random_name(),
+        data = random_float()
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_float_inf(self):
         data = float(np.inf)
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_float_ninf(self):
         data = float(-np.inf)
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_float_nan(self):
         data = float(np.nan)
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         assert math.isnan(out)
 
     def test_complex(self):
-        data = self.random_float() + 1j*self.random_float()
-        out = self.write_readback(data, self.random_name(),
+        data = random_float() + 1j*random_float()
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_complex_real_nan(self):
-        data = complex(np.nan, self.random_float())
-        out = self.write_readback(data, self.random_name(),
+        data = complex(np.nan, random_float())
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_complex_imaginary_nan(self):
-        data = complex(self.random_float(), np.nan)
-        out = self.write_readback(data, self.random_name(),
+        data = complex(random_float(), np.nan)
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_str_ascii(self):
-        data = self.random_str_ascii(random.randint(1,
-                                     self.max_string_length))
-        out = self.write_readback(data, self.random_name(),
+        data = random_str_ascii(random.randint(1,
+                                max_string_length))
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     @raises(NotImplementedError)
     def test_str_ascii_encoded_utf8(self):
-        data = self.random_str_some_unicode(random.randint(1,
-            self.max_string_length)).encode('UTF-8')
-        out = self.write_readback(data, self.random_name(),
+        data = random_str_some_unicode(random.randint(1, \
+            max_string_length)).encode('UTF-8')
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_str_unicode(self):
-        data = self.random_str_some_unicode(random.randint(1,
-                                            self.max_string_length))
-        out = self.write_readback(data, self.random_name(),
+        data = random_str_some_unicode(random.randint(1,
+                                       max_string_length))
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_str_empty(self):
         data = ''
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_bytes(self):
-        data = self.random_bytes(random.randint(1,
-                                 self.max_string_length))
-        out = self.write_readback(data, self.random_name(),
+        data = random_bytes(random.randint(1,
+                            max_string_length))
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_bytes_empty(self):
         data = b''
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_bytearray(self):
-        data = bytearray(self.random_bytes(random.randint(1,
-                         self.max_string_length)))
-        out = self.write_readback(data, self.random_name(),
+        data = bytearray(random_bytes(random.randint(1,
+                         max_string_length)))
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
     def test_bytearray_empty(self):
         data = bytearray(b'')
-        out = self.write_readback(data, self.random_name(),
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
@@ -529,11 +323,11 @@ class TestPythonMatlabFormat(object):
         # Makes a random 1d structured ndarray with non-ascii characters
         # in its fields, writes it and reads it back, and then compares
         # it.
-        shape = self.random_numpy_shape(1, \
-            self.max_structured_ndarray_axis_length)
-        data = self.random_structured_numpy_array(shape,
-                                                  nonascii_fields=True)
-        out = self.write_readback(data, self.random_name(),
+        shape = random_numpy_shape(1, \
+            max_structured_ndarray_axis_length)
+        data = random_structured_numpy_array(shape,
+                                             nonascii_fields=True)
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
@@ -542,8 +336,8 @@ class TestPythonMatlabFormat(object):
             yield self.check_python_collection, tp
 
     def test_dict(self):
-        data = self.random_dict()
-        out = self.write_readback(data, self.random_name(),
+        data = random_dict()
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
@@ -559,14 +353,13 @@ class TestPythonFormat(TestPythonMatlabFormat):
 
     # Won't throw an exception unlike the parent.
     def test_str_ascii_encoded_utf8(self):
-        data = self.random_str_some_unicode(random.randint(1,
-            self.max_string_length)).encode('UTF-8')
-        out = self.write_readback(data, self.random_name(),
+        data = random_str_some_unicode(random.randint(1,
+            max_string_length)).encode('UTF-8')
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
 
-
 class TestNoneFormat(TestPythonMatlabFormat):
     def __init__(self):
         # The parent does most of the setup. All that has to be changed
@@ -581,9 +374,9 @@ class TestNoneFormat(TestPythonMatlabFormat):
 
     # Won't throw an exception unlike the parent.
     def test_str_ascii_encoded_utf8(self):
-        data = self.random_str_some_unicode(random.randint(1,
-            self.max_string_length)).encode('UTF-8')
-        out = self.write_readback(data, self.random_name(),
+        data = random_str_some_unicode(random.randint(1,
+            max_string_length)).encode('UTF-8')
+        out = self.write_readback(data, random_name(),
                                   self.options)
         self.assert_equal(out, data)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git



More information about the debian-science-commits mailing list