示例#1
0
 def test_set_exists_wrong_type(self):
     gb1 = GroupBuilder('gb1')
     gb2 = GroupBuilder('gb2')
     db = DatasetBuilder('gb2')
     gb1.set_group(gb2)
     msg = "'gb2' already exists in gb1.groups, cannot set in datasets."
     with self.assertRaisesWith(ValueError, msg):
         gb1.set_dataset(db)
示例#2
0
 def test_set_group(self):
     gb1 = GroupBuilder('gb1')
     gb2 = GroupBuilder('gb2')
     gb1.set_group(gb2)
     self.assertIs(gb2.parent, gb1)
     self.assertIn('gb2', gb1.obj_type)
     self.assertIn('gb2', gb1.groups)
     self.assertIs(gb1['gb2'], gb2)
示例#3
0
class GroupBuilderSetterTests(TestCase):
    """Tests for setter functions in GroupBuilder class"""
    def setUp(self):
        self.gb = GroupBuilder('gb')
        self.gb2 = GroupBuilder('gb2', source='file1')

    def tearDown(self):
        pass

    def test_setitem_disabled(self):
        """Test __set_item__ is disabled"""
        with self.assertRaises(NotImplementedError):
            self.gb['key'] = 'value'

    def test_add_dataset(self):
        ds = self.gb.add_dataset('my_dataset', list(range(10)))
        self.assertIsInstance(ds, DatasetBuilder)
        self.assertIs(self.gb, ds.parent)

    def test_add_group(self):
        gp = self.gb.add_group('my_subgroup')
        self.assertIsInstance(gp, GroupBuilder)
        self.assertIs(self.gb['my_subgroup'], gp)
        self.assertIs(self.gb, gp.parent)

    def test_add_link(self):
        gp = self.gb.add_group('my_subgroup')
        sl = self.gb.add_link(gp, 'my_link')
        self.assertIsInstance(sl, LinkBuilder)
        self.assertIs(self.gb['my_link'], sl)
        self.assertIs(self.gb, sl.parent)

    def test_add_external_link(self):
        gp = self.gb2.add_group('my_subgroup')
        el = self.gb.add_link(gp, 'my_externallink')
        self.assertIsInstance(el, LinkBuilder)
        self.assertIs(self.gb['my_externallink'], el)
        self.assertIs(self.gb, el.parent)
        self.assertIs(self.gb2, gp.parent)

    # @unittest.expectedFailure
    def test_set_attribute(self):
        self.gb.set_attribute('key', 'value')
        self.assertIn('key', self.gb.obj_type)
        # self.assertEqual(dict.__getitem__(self.gb, 'attributes')['key'], 'value')
        self.assertEqual(self.gb['key'], 'value')

    def test_parent_constructor(self):
        gb2 = GroupBuilder('gb2', parent=self.gb)
        self.assertIs(gb2.parent, self.gb)

    def test_set_group(self):
        self.gb.set_group(self.gb2)
        self.assertIs(self.gb2.parent, self.gb)