def test_b_preadd_model(self): a1 = BlahModel() mg = ModelGroup() mg.add_model(a1) om = mg.create_multi_observer(MockMultiObserver) for a in a1.__model_attrs_map__: self.assert_(om in a1.__model_observers__[a])
def __init__(self, *a, **kw): super(PropertyPage, self).__init__(*a, **kw) mg = ModelGroup() self.mo = mg.create_multi_observer(TreeObserver) self.mo.set_parent_page(self) rootp = '/tmp/address_a-%s' self.a1 = Address() self.a2 = Address() self.a3 = Address() for i, a in enumerate([self.a1, self.a2, self.a3]): load_model_from_ini(rootp % i, a) mg.add_model(a) self.p = mg.create_multi_observer(IniFileObserver) self.o = mg.create_single_observer(ElementObserver) self.o.set_parent_page(self) self.o.setup_with_model(Address())
default = '/' def __markup__(self): from cgi import escape mu = '<b>%s</b>' % escape(self.general__name) if self.source__uses: mu = ('%s (<span color="#0000c0">%s</span>)\n%s' % (mu, escape(self.source__vc_name), escape(self.source__directory))) return mu Project = Model.__model_from_definition__(ProjectDefinition) if __name__ == '__main__': mg = ModelGroup() tv = mg.create_multi_observer(TreeObserver) pp = mg.create_single_observer(PropertyPage) ini = mg.create_multi_observer(IniFileObserver) for n in ['Tom', 'Dick', 'Harry']: m = Project() m = load_model_from_ini('/tmp/foo_model%s2' % n, m) m.general__name = n mg.add_model(m) m = Project() load_model_from_ini('/home/ali/tmp/food', m) mg.add_model(m) # pack the tree and the property page
def setUp(self): self.mg = ModelGroup() self.om = self.mg.create_multi_observer(MockMultiObserver) self.os = self.mg.create_single_observer(MockSingleObserver)
class test_model_group(unittest.TestCase): def setUp(self): self.mg = ModelGroup() self.om = self.mg.create_multi_observer(MockMultiObserver) self.os = self.mg.create_single_observer(MockSingleObserver) def test_a_add_model(self): a1 = BlahModel() self.mg.add_model(a1) for a in a1.__model_attrs_map__: self.assert_(self.om in a1.__model_observers__[a]) def test_b_preadd_model(self): a1 = BlahModel() mg = ModelGroup() mg.add_model(a1) om = mg.create_multi_observer(MockMultiObserver) for a in a1.__model_attrs_map__: self.assert_(om in a1.__model_observers__[a]) def test_c_set_current(self): a1 = BlahModel() om = self.mg.create_multi_observer(MockMultiObserver) self.mg.add_model(a1) self.mg.set_current(a1) self.assertEqual(a1, self.om._current) self.assertEqual(a1, om._current) def test_d_set_model(self): a1 = BlahModel() os = self.mg.create_single_observer(MockSingleObserver) self.mg.add_model(a1) self.mg.set_current(a1) self.assertEqual(a1, self.os._model) self.assertEqual(a1, os._model)
def __markup__(self): from cgi import escape mu = '<b>%s</b>' % escape(self.general__name) if self.source__uses: mu = ('%s (<span color="#0000c0">%s</span>)\n%s' % (mu, escape( self.source__vc_name), escape(self.source__directory))) return mu Project = Model.__model_from_definition__(ProjectDefinition) if __name__ == '__main__': mg = ModelGroup() tv = mg.create_multi_observer(TreeObserver) pp = mg.create_single_observer(PropertyPage) ini = mg.create_multi_observer(IniFileObserver) for n in ['Tom', 'Dick', 'Harry']: m = Project() m = load_model_from_ini('/tmp/foo_model%s2' % n, m) m.general__name = n mg.add_model(m) m = Project() load_model_from_ini('/home/ali/tmp/food', m) mg.add_model(m) # pack the tree and the property page