コード例 #1
0
def check_int_key(tp, option_keywords):
    options = hdf5storage.Options(**option_keywords)
    key_value_names = (options.dict_like_keys_name,
                       options.dict_like_values_name)

    data = random_dict(tp)
    for k in key_value_names:
        if k in data:
            del data[k]

    key = random_int()
    data[key] = random_int()

    # Make a random name.
    name = random_name()

    # Write the data to the proper file with the given name with the
    # provided options. The file needs to be deleted after to keep junk
    # from building up.
    fld = None
    try:
        fld = tempfile.mkstemp()
        os.close(fld[0])
        filename = fld[1]
        hdf5storage.write(data, path=name, filename=filename, options=options)

        with h5py.File(filename, mode='r') as f:
            assert_equal_nose(set(key_value_names), set(f[name].keys()))
    except:
        raise
    finally:
        if fld is not None:
            os.remove(fld[1])
コード例 #2
0
 def check_dict_like_key_leading_periods(self, tp):
     data = random_dict(tp)
     prefix = '.' * random.randint(1, 10)
     key = prefix + random_str_ascii(max_dict_key_length)
     data[key] = random_int()
     out = self.write_readback(data, random_name(), self.options)
     self.assert_equal(out, data)
コード例 #3
0
 def check_dict_like_key_back_slash(self, tp):
     data = random_dict(tp)
     ch = '\\'
     key = ch.join(
         [random_str_ascii(max_dict_key_length) for i in range(2)])
     data[key] = random_int()
     out = self.write_readback(data, random_name(), self.options)
     self.assert_equal(out, data)
コード例 #4
0
    def check_dict_like_other_type_key(self, tp, other_tp):
        data = random_dict(tp)

        key_gen = random_str_some_unicode(max_dict_key_length)
        if other_tp == 'numpy.bytes_':
            key = np.bytes_(key_gen.encode('UTF-8'))
        elif other_tp == 'numpy.unicode_':
            key = np.unicode_(key_gen)
        elif other_tp == 'bytes':
            key = key_gen.encode('UTF-8')
        elif other_tp == 'int':
            key = random_int()
        elif other_tp == 'float':
            key = random_float()

        data[key] = random_int()
        out = self.write_readback(data, random_name(), self.options)
        self.assert_equal(out, data)
コード例 #5
0
def check_string_type_non_str_key(tp, other_tp, option_keywords):
    options = hdf5storage.Options(**option_keywords)
    key_value_names = (options.dict_like_keys_name,
                       options.dict_like_values_name)

    data = random_dict(tp)
    for k in key_value_names:
        if k in data:
            del data[k]
    keys = list(data.keys())

    key_gen = random_str_some_unicode(max_dict_key_length)
    if other_tp == 'numpy.bytes_':
        key = np.bytes_(key_gen.encode('UTF-8'))
    elif other_tp == 'numpy.unicode_':
        key = np.unicode_(key_gen)
    elif other_tp == 'bytes':
        key = key_gen.encode('UTF-8')
    data[key] = random_int()
    keys.append(key_gen)

    # Make a random name.
    name = random_name()

    # Write the data to the proper file with the given name with the
    # provided options. The file needs to be deleted after to keep junk
    # from building up.
    fld = None
    try:
        fld = tempfile.mkstemp()
        os.close(fld[0])
        filename = fld[1]
        hdf5storage.write(data, path=name, filename=filename, options=options)

        with h5py.File(filename, mode='r') as f:
            assert_equal_nose(set(keys), set(f[name].keys()))

    except:
        raise
    finally:
        if fld is not None:
            os.remove(fld[1])
コード例 #6
0
def check_str_key_previously_invalid_char(tp, ch, option_keywords):
    options = hdf5storage.Options(**option_keywords)
    key_value_names = (options.dict_like_keys_name,
                       options.dict_like_values_name)

    data = random_dict(tp)
    for k in key_value_names:
        if k in data:
            del data[k]

    # Add a random invalid str key using the provided character
    key = key_value_names[0]
    while key in key_value_names:
        key = ch.join(
            [random_str_ascii(max_dict_key_length) for i in range(2)])
    data[key] = random_int()

    # Make a random name.
    name = random_name()

    # Write the data to the proper file with the given name with the
    # provided options. The file needs to be deleted after to keep junk
    # from building up.
    fld = None
    try:
        fld = tempfile.mkstemp()
        os.close(fld[0])
        filename = fld[1]
        hdf5storage.write(data, path=name, filename=filename, options=options)

        with h5py.File(filename, mode='r') as f:
            for k in key_value_names:
                assert escape_path(k) not in f[name]
            for k in data:
                assert escape_path(k) in f[name]
    except:
        raise
    finally:
        if fld is not None:
            os.remove(fld[1])
コード例 #7
0
 def test_int_or_long_too_big(self):
     data = 2**64 * random_int()
     out = self.write_readback(data, random_name(), self.options)
     self.assert_equal(out, data)
コード例 #8
0
 def test_int_needs_64_bits(self):
     data = (2**32) * random_int()
     out = self.write_readback(data, random_name(), self.options)
     self.assert_equal(out, data)