def test_signal(self): address = 'tcp://127.0.0.1:6008' s = Server(Example(), rep_endpoint=address) proxy = Proxy(address) class MemMethod(object): def __init__(self_): self_.called = 0 def __call__(self_, value, old_value, others): self_.called += 1 fun1 = MemMethod() self.assertEqual(fun1.called, 0) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 0) proxy.rw_prop_changed.connect(fun1) time.sleep(SLEEP_SECS) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 1) proxy.rw_prop = 28 time.sleep(SLEEP_SECS) self.assertEqual(proxy.rw_prop, 28) self.assertEqual(fun1.called, 1) fun2 = MemMethod() self.assertEqual(fun2.called, 0) proxy.rw_prop_changed.connect(fun2) time.sleep(SLEEP_SECS) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 1) proxy.rw_prop = 29 time.sleep(SLEEP_SECS) self.assertEqual(proxy.rw_prop, 29) self.assertEqual(fun1.called, 2) self.assertEqual(fun2.called, 1) proxy.rw_prop_changed.disconnect(fun1) time.sleep(SLEEP_SECS) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 1) proxy.rw_prop = 30 self.assertEqual(fun1.called, 2) proxy.rw_prop_changed.disconnect(fun2) time.sleep(SLEEP_SECS) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 0) proxy.rw_prop_changed.connect(fun1) proxy.rw_prop_changed.connect(fun2) time.sleep(SLEEP_SECS) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 1) proxy.rw_prop_changed.disconnect(None) time.sleep(SLEEP_SECS) self.assertEqual(len(s.served_object.rw_prop_changed.slots), 0) proxy._proxy_stop_server() proxy._proxy_stop_me()
def test_server(self): s = Server(Example()) proxy = Proxy(s.rep_endpoint) self.assertEqual(s.served_object.simple_attribute, 12) self.assertEqual(proxy.simple_attribute, 12) proxy.simple_attribute = 24 self.assertEqual(s.served_object.simple_attribute, 24) self.assertEqual(proxy.simple_attribute, 24) self.assertRaises(AttributeError, getattr, proxy, 'not_an_attribute') self.assertEqual(s.served_object.dict_attribute[1], 2) self.assertEqual(proxy.dict_attribute[1], 2) self.assertRaises(KeyError, operator.getitem, proxy.dict_attribute, 2) proxy.dict_attribute[2] = 4 self.assertEqual(s.served_object.dict_attribute[2], 4) self.assertEqual(proxy.dict_attribute[2], 4) self.assertEqual(s.served_object.rw_prop, 42) self.assertEqual(proxy.rw_prop, 42) proxy.rw_prop = 21 self.assertEqual(s.served_object.rw_prop, 21) self.assertEqual(proxy.rw_prop, 21) self.assertEqual(proxy.fun_simple(), 46) self.assertEqual(proxy.fun_arg1(2), 4) self.assertEqual(proxy.fun_arg2(2, 3), 8) self.assertEqual(proxy.fun_arg2(y=2), 4) self.assertRaises(ValueError, proxy.fun_raise) proxy._proxy_stop_server() proxy._proxy_stop_me()