def test_io_haskey(self): "io_haskey" io = IO(self.filename) x = larry([1, 2, 3]) y = larry([7, 8, 9]) io['x'] = x io['y'] = y self.assertTrue(io.has_key('x'), 'keys do not match') self.assertTrue(io.has_key('y'), 'keys do not match') self.assertTrue(~io.has_key('z'), 'keys do not match')
def test_io_haskey(self): "io_haskey" io = IO(self.filename) x = larry([1,2,3]) y = larry([7,8,9]) io['x'] = x io['y'] = y self.assertTrue(io.has_key('x'), 'keys do not match') self.assertTrue(io.has_key('y'), 'keys do not match') self.assertTrue(~io.has_key('z'), 'keys do not match')
def test_io_iterkeys(self): "io_iterkeys" io = IO(self.filename) x = larry([1,2,3]) y = larry([7,8,9]) io['x'] = x io['y'] = y itk = io.iterkeys() keys = [k for k in itk] self.assertTrue(keys == ['x', 'y'], 'keys do not match')
def test_io_iterkeys(self): "io_iterkeys" io = IO(self.filename) x = larry([1, 2, 3]) y = larry([7, 8, 9]) io['x'] = x io['y'] = y itk = io.iterkeys() keys = [k for k in itk] self.assertTrue(keys == ['x', 'y'], 'keys do not match')
def test_io_itervalues(self): "io_itervalues" io = IO(self.filename) x = larry([1,2,3]) y = larry([7,8,9]) io['x'] = x io['y'] = y itv = io.itervalues() values = [v[:] for v in itv] assert_larry_equal(values[0], x) assert_larry_equal(values[1], y)
def test_io_3(self): "io_keys" io = IO(self.filename) io["1"] = larry([1, 2, 3]) io["2"] = larry([1, 2, 3]) io.f["3"] = [1, 2, 3] io["1/2/3/4"] = larry([1, 2, 3]) keys = io.keys() keys.sort() theory = ["1", "1/2/3/4", "2"] self.assert_(keys == theory, "keys do not match")
def test_io_3(self): "io_keys" io = IO(self.filename) io['1'] = larry([1, 2, 3]) io['2'] = larry([1, 2, 3]) io.f['3'] = [1, 2, 3] io['1/2/3/4'] = larry([1, 2, 3]) keys = io.keys() keys.sort() theory = ['1', '1/2/3/4', '2'] self.assert_(keys == theory, 'keys do not match')
def test_io_3(self): "io_keys" io = IO(self.filename) io['1'] = larry([1,2,3]) io['2'] = larry([1,2,3]) io.f['3'] = [1,2,3] io['1/2/3/4'] = larry([1,2,3]) keys = io.keys() keys.sort() theory = ['1', '1/2/3/4', '2'] self.assertTrue(keys == theory, 'keys do not match')
def test_io_itervalues(self): "io_itervalues" io = IO(self.filename) x = larry([1, 2, 3]) y = larry([7, 8, 9]) io['x'] = x io['y'] = y itv = io.itervalues() values = [v[:] for v in itv] assert_larry_equal(values[0], x) assert_larry_equal(values[1], y)
def test_io_1(self): "io_general" io = IO(self.filename) x = larry([1, 2, 3]) io["x"] = x self.assert_("x" in io, "key missing") self.assert_((x == io["x"][:]).all(), "save and load difference") self.assert_(["x"] == io.keys(), "keys are different") self.assert_(x.dtype == io["x"].dtype, "dtype changed") del io["x"] self.assert_(io.keys() == [], "key still present")
def test_io_1(self): "io_general" io = IO(self.filename) x = larry([1, 2, 3]) io['x'] = x self.assertTrue('x' in io, 'key missing') self.assertTrue((x == io['x'][:]).all(), 'save and load difference') self.assertTrue(['x'] == list(io.keys()), 'keys are different') self.assertTrue(x.dtype == io['x'].dtype, 'dtype changed') del io['x'] self.assertTrue(list(io.keys()) == [], 'key still present')
def test_io_1(self): "io_general" io = IO(self.filename) x = larry([1,2,3]) io['x'] = x self.assertTrue('x' in io, 'key missing') self.assertTrue((x == io['x'][:]).all(), 'save and load difference') self.assertTrue(['x'] == io.keys(), 'keys are different') self.assertTrue(x.dtype == io['x'].dtype, 'dtype changed') del io['x'] self.assertTrue(io.keys() == [], 'key still present')
def test_io_2(self): "io_repack" io = IO(self.filename) io['larry'] = la.rand(100, 100) fs1 = io.freespace sp1 = io.space del io['larry'] io.repack() fs2 = io.freespace sp2 = io.space self.assertTrue(fs2 < fs1, 'repack did not reduce freespace') self.assertTrue(sp2 < sp1, 'repack did not reduce space')
def test_io_2(self): "io_repack" io = IO(self.filename) io["larry"] = la.rand(100, 100) fs1 = io.freespace sp1 = io.space del io["larry"] io.repack() fs2 = io.freespace sp2 = io.space self.assert_(fs2 < fs1, "repack did not reduce freespace") self.assert_(sp2 < sp1, "repack did not reduce space")
def test_io_items(self): "io_items" io = IO(self.filename) x = larry([1,2,3]) y = larry([7,8,9]) io['x'] = x io['y'] = y items = io.items() values = [v[1][:] for v in items] assert_larry_equal(values[0], x) assert_larry_equal(values[1], y) keys = [v[0] for v in items] self.assertTrue(keys == ['x', 'y'], 'keys do not match')
def test_io_3(self): "io_keys" io = IO(self.filename) io['1'] = larry([1,2,3]) io['2'] = larry([1,2,3]) f = h5py.File(self.filename) f['3'] = [1,2,3] f.close() io['1/2/3/4'] = larry([1,2,3]) keys = list(io.keys()) keys.sort() theory = ['1', '1/2/3/4', '2'] self.assertTrue(keys == theory, 'keys do not match')
def test_io_3(self): "io_keys" io = IO(self.filename) io['1'] = larry([1, 2, 3]) io['2'] = larry([1, 2, 3]) f = h5py.File(self.filename) f['3'] = [1, 2, 3] f.close() io['1/2/3/4'] = larry([1, 2, 3]) keys = list(io.keys()) keys.sort() theory = ['1', '1/2/3/4', '2'] self.assertTrue(keys == theory, 'keys do not match')
def test_io_items(self): "io_items" io = IO(self.filename) x = larry([1, 2, 3]) y = larry([7, 8, 9]) io['x'] = x io['y'] = y items = io.items() values = [v[1][:] for v in items] assert_larry_equal(values[0], x) assert_larry_equal(values[1], y) keys = [v[0] for v in items] self.assertTrue(keys == ['x', 'y'], 'keys do not match')
def test_io_lara_1(self): "lara indexing bug #40" io = IO(self.filename) io['a'] = la.lrange(3) b = io['a'] # b[[0, 2]] raised: # AttributeError: 'Dataset' object has no attribute 'take' b[[0, 2]]
def test_io_len(self): "io_len" io = IO(self.filename) x = larry([1, 2, 3]) y = larry([7, 8, 9]) io['x'] = x io['y'] = y self.assertTrue(len(io) == 2, 'number of keys is wrong')
def test_io_4(self): "io_dates" io = IO(self.filename) x = [1, 2] label = [[datetime.date(2010, 3, 1), datetime.date(2010, 3, 2)]] desired = larry(x, label) io['desired'] = desired actual = io['desired'][:] assert_larry_equal(actual, desired)
def test_io_7(self): "io_empty (gh #68)" io = IO(self.filename) desired = larry([]) io['desired'] = desired actual = io['desired'] if actual.size == 0: actual = la.larry([]) assert_larry_equal(actual, desired)
def test_io_6(self): "io_datetimes" io = IO(self.filename) x = [1, 2] label = [[datetime.time(13, 15, 59, 9998), datetime.time(11, 23)]] desired = larry(x, label) io['desired'] = desired actual = io['desired'][:] assert_larry_equal(actual, desired)