|
| 1 | +import unittest2 as unittest |
| 2 | + |
| 3 | +from pynwb.form.container import Container |
| 4 | + |
| 5 | + |
| 6 | +class MyTestClass(Container): |
| 7 | + |
| 8 | + def __init__(self, src, name, parent=None): |
| 9 | + super(MyTestClass, self).__init__(src, name, parent=parent) |
| 10 | + |
| 11 | + def basic_add(self, **kwargs): |
| 12 | + return kwargs |
| 13 | + |
| 14 | + def basic_add2(self, **kwargs): |
| 15 | + return kwargs |
| 16 | + |
| 17 | + def basic_add2_kw(self, **kwargs): |
| 18 | + return kwargs |
| 19 | + |
| 20 | + |
| 21 | +class MyTestSubclass(MyTestClass): |
| 22 | + |
| 23 | + def basic_add(self, **kwargs): |
| 24 | + return kwargs |
| 25 | + |
| 26 | + def basic_add2_kw(self, **kwargs): |
| 27 | + return kwargs |
| 28 | + |
| 29 | + |
| 30 | +class TestNWBContainer(unittest.TestCase): |
| 31 | + |
| 32 | + def test_constructor(self): |
| 33 | + """Test that constructor properly sets parent |
| 34 | + """ |
| 35 | + parent_obj = MyTestClass('test source', 'obj1') |
| 36 | + child_obj = MyTestSubclass('test source', 'obj2', parent=parent_obj) |
| 37 | + self.assertIs(child_obj.parent, parent_obj) |
| 38 | + |
| 39 | + def test_set_parent_parent(self): |
| 40 | + """Test that parent setter properly sets parent |
| 41 | + """ |
| 42 | + parent_obj = MyTestClass('test source', 'obj1') |
| 43 | + child_obj = MyTestSubclass('test source', 'obj2') |
| 44 | + child_obj.parent = parent_obj |
| 45 | + self.assertIs(child_obj.parent, parent_obj) |
| 46 | + |
| 47 | + def test_slash_restriction(self): |
| 48 | + self.assertRaises(ValueError, Container, 'bad/name') |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == '__main__': |
| 52 | + unittest.main() |
0 commit comments