Ejemplo n.º 1
0
    def test_raise_on_empty(self):
        Features(self.feat)
        empty1 = self.feat
        empty1.append(np.array([]))
        empty2 = [np.array([])]*3

        for arg in [empty1, empty2]:
            assert_raise(Features, arg, 'all features must be non-empty')
Ejemplo n.º 2
0
    def test_on_empty_group(self):
        group = self.h5file.create_group('group')
        assert_raise(self.items.is_appendable_to, group,
                     "open object", KeyError)

        # Create an empty items group
        self.items.create_dataset(group, 10)
        assert self.items.is_appendable_to(group)
Ejemplo n.º 3
0
    def test_on_empty_group(self):
        group = self.h5file.create_group('group')
        assert_raise(self.items.is_appendable_to, group, "open object",
                     KeyError)

        # Create an empty items group
        self.items.create_dataset(group, 10)
        _items = copy.deepcopy(self.items.data)
        assert self.items.is_appendable_to(group)
        assert _items == self.items.data
Ejemplo n.º 4
0
    def test_sort_1D(self):
        l = [np.array([i for i in range(9)])]
        Labels.check(l)

        l[0][[0, 1]] = l[0][[1, 0]]
        assert_raise(Labels.check, l, 'not sorted')

        l.append(np.array([i for i in range(9)]))
        assert_raise(Labels.check, l, 'not sorted')

        l[0][[1, 0]] = l[0][[0, 1]]
        Labels.check(l)
Ejemplo n.º 5
0
    def test_sorted_2D(self):
        # dont use generate.labels to ensure 2 elements.
        l = [
            np.array([[0., 1.], [0.33333333, 1.33333333],
                      [0.66666667, 1.66666667], [1., 2.]]),
            np.array([[0., 1.], [1., 2.]])
        ]

        # sorted, pass
        Labels.check(l)

        # unsorted, fails
        l[0][[0, 1], :] = l[0][[1, 0], :]
        assert_raise(Labels.check, l, 'not sorted')
Ejemplo n.º 6
0
 def test_bad(self):
     args = [[1, 1], [1, 2, 2], ['a', 'b', 'c', 'a']]
     msg = 'all items must have different names.'
     for arg in args:
         assert_raise(Items, arg, msg)
Ejemplo n.º 7
0
 def test_bad_dims(self):
     for arg in [self.t1+self.t2,
                 self.t2+self.t1,
                 self.t2+[np.array([1, 2, 3])]]:
         assert_raise(self.parse, arg, 'dimensions must be equal')
Ejemplo n.º 8
0
 def test_bad_format(self):
     # 3D
     assert_raise(self.parse, [randn(2, 2, 2)], 'must be 1 or 2')
Ejemplo n.º 9
0
 def test_bad(self):
     args = [[1, 1], [1, 2, 2], ['a', 'b', 'c', 'a']]
     msg = 'all items must have different names.'
     for arg in args:
         assert_raise(Items, arg, msg)
Ejemplo n.º 10
0
 def test_not_hdf5_file(self):
     with open(self.filename, 'w') as temp:
         temp.write('This is not a HDF5 file')
     assert_raise(Writer, self.filename, 'not a HDF5 file')
Ejemplo n.º 11
0
 def test_bad_format(self):
     # 3D
     assert_raise(Labels.check, [randn(2, 2, 2)], 'must be 1 or 2')
Ejemplo n.º 12
0
 def test_bad(self):
     bad = self.data[2] + self.data[3]
     assert_raise(parse_dim, bad, 'must have the same')
Ejemplo n.º 13
0
 def test_not_iterable(self):
     args = [self.data.append(np.array([])), 1]
     for arg in args:
         assert_raise(parse_dtype, arg, '', TypeError)
Ejemplo n.º 14
0
 def test_bad(self):
     arg = self.data
     arg[0] = arg[0].astype(int)
     assert_raise(parse_dtype, arg, 'homogeneous')
Ejemplo n.º 15
0
 def test_dim_bad(self):
     bad_feat = self.feat
     bad_feat[5] = bad_feat[5][:,:-1]
     assert_raise(parse_dim, bad_feat, 'same feature dimension')
Ejemplo n.º 16
0
 def test_bad_dims(self):
     for arg in [
             self.t1 + self.t2, self.t2 + self.t1,
             self.t2 + [np.array([1, 2, 3])]
     ]:
         assert_raise(Labels.check, arg, 'dimensions must be equal')
Ejemplo n.º 17
0
 def test_same_items_twice(self):
     group = self.h5file.create_group('group')
     self.items.create_dataset(group, 10)
     self.items.write_to(group)
     assert_raise(self.items.is_appendable_to, group,
                  'more than one shared items')
Ejemplo n.º 18
0
 def test_not_hdf5_file(self):
     with open(self.filename, 'w') as temp:
         temp.write('This is not a HDF5 file')
     assert_raise(Writer, self.filename, 'not a HDF5 file')