Example #1
0
    def test_find_trait_and_value(self):
        class MyClass(object):
            pass

        class MyHT(HasTraits):
            pass

        obj = MyClass()
        obj.sub = MyClass()
        obj.sub.sub = MyHT()
        obj.sub.csub = Container()
        obj.a = 1
        obj.sub.b = 2
        obj.sub.sub.c = 3
        obj.sub.csub.add('d', Float(4, iotype='in'))
        result = find_trait_and_value(obj, 'sub.sub.c')
        self.assertEqual(result[0].type, 'python')
        self.assertEqual(result[1], 3)
        result = find_trait_and_value(obj, 'sub.csub.d')
        self.assertEqual(result[0].type, 'trait')
        self.assertEqual(result[1], 4)
        try:
            result = find_trait_and_value(obj, 'sub.foo')
        except AttributeError as err:
            self.assertEqual(str(err),
                             "'MyClass' object has no attribute 'foo'")
        else:
            self.fail("expected AttributeError")
 def test_find_trait_and_value(self):
     class MyClass(object):
         pass
     class MyHT(HasTraits):
         pass
     
     obj = MyClass()
     obj.sub = MyClass()
     obj.sub.sub = MyHT()
     obj.sub.csub = Container()
     obj.a = 1
     obj.sub.b = 2
     obj.sub.sub.c = 3
     obj.sub.csub.add('d',Float(4, iotype='in'))
     result = find_trait_and_value(obj, 'sub.sub.c')
     self.assertEqual(result[0].type, 'python')
     self.assertEqual(result[1], 3)
     result = find_trait_and_value(obj, 'sub.csub.d')
     self.assertEqual(result[0].type, 'trait')
     self.assertEqual(result[1], 4)
     try:
         result = find_trait_and_value(obj, 'sub.foo')
     except AttributeError as err:
         self.assertEqual(str(err), "'MyClass' object has no attribute 'foo'")
     else:
         self.fail("expected AttributeError")