MCPcopy Create free account
hub / github.com/ipython/traitlets / test_basic

Method test_basic

tests/test_traitlets.py:1066–1087  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1064
1065class TestInstance(TestCase):
1066 def test_basic(self):
1067 class Foo:
1068 pass
1069
1070 class Bar(Foo):
1071 pass
1072
1073 class Bah:
1074 pass
1075
1076 class A(HasTraits):
1077 inst = Instance(Foo, allow_none=True)
1078
1079 a = A()
1080 self.assertTrue(a.inst is None)
1081 a.inst = Foo()
1082 self.assertTrue(isinstance(a.inst, Foo))
1083 a.inst = Bar()
1084 self.assertTrue(isinstance(a.inst, Foo))
1085 self.assertRaises(TraitError, setattr, a, "inst", Foo)
1086 self.assertRaises(TraitError, setattr, a, "inst", Bar)
1087 self.assertRaises(TraitError, setattr, a, "inst", Bah())
1088
1089 def test_default_klass(self):
1090 class Foo:

Callers

nothing calls this directly

Calls 4

BahClass · 0.85
AClass · 0.70
FooClass · 0.70
BarClass · 0.70

Tested by

no test coverage detected