def test_when_matches(self): t = Task("testTask", self.proc) f = t.when_matches_async(self.attr, "matchTest") resp = Update(1, None, None) resp.set_value('matchTest') t.q.put(resp) self.assertEqual(f[0].result(0), 'matchTest') t.stop()
def test_Update(self): context = Mock() value = {"attribute": "value"} r = Update(123, context, value) self.assertEquals(123, r.id_) self.assertEquals(context, r.context) self.assertEquals({"attribute": "value"}, r.value) r.set_value({"key": "value2"}) self.assertEquals({"key": "value2"}, r.value)
def test_when_matches(self): t = Task("testTask", self.proc) f = t.when_matches(self.attr, "matchTest") # match (response goes to the subscription at id 1, # not the future at id 0) resp = Update(1, None, None) resp.set_value('matchTest') t.q.put(resp) t.stop() self.assertEqual(f[0].result(0),'matchTest')
def test_when_matches(self): t = Task("testTask", self.proc) f = t.when_matches(self.attr, "matchTest") # match (response goes to the subscription at id 1, # not the future at id 0) resp = Update(1, None, None) resp.set_value('matchTest') t.q.put(resp) t.stop() self.assertEqual(f[0].result(0), 'matchTest')
def test_callback_crash(self): t = Task("testTask", self.proc) resp = Update(0, None, None) resp.set_value('changedVal') t.q.put(resp) t.stop() t.subscribe(self.attr, self._bad_callback) f1 = Future(t) t._futures = {1: f1} self.assertRaises(RuntimeWarning, t.wait_all, f1, 0) self.assertEquals(self.bad_called_back, True)
def test_callback_crash(self): t = Task("testTask", self.proc) resp = Update(0, None, None) resp.set_value('changedVal') t.q.put(resp) t.stop() t.subscribe(self.attr, self._bad_callback) f1 = Future(t) t._futures = {1: f1} self.assertRaises(StopIteration, t.wait_all, f1, 0) self.assertEquals(self.bad_called_back, True)
def test_not_when_matches(self): t = Task("testTask", self.proc) f = t.when_matches(self.attr, "matchTest") # match (response goes to the subscription at id 1, # not the future at id 0) resp = Update(1, None, None) resp.set_value('NOTmatchTest') t.q.put(resp) t.stop() # this will abort the task because f[0] never gets filled self.assertRaises(RuntimeWarning, f[0].result)
def test_not_when_matches(self): t = Task("testTask", self.proc) f = t.when_matches(self.attr, "matchTest") # match (response goes to the subscription at id 1, # not the future at id 0) resp = Update(1, None, None) resp.set_value('NOTmatchTest') t.q.put(resp) t.stop() # this will abort the task because f[0] never gets filled self.assertRaises(StopIteration, f[0].result)
def test_subscribe(self): t = Task("testTask", self.proc) resp = Update(0, None, None) resp.set_value('changedVal') t.q.put(resp) t.stop() new_id = t.subscribe(self.attr, self._callback, 3, 5) f1 = Future(t) t._futures = {1: f1} self.assertRaises(RuntimeWarning, t.wait_all, f1, 0) self.assertEqual(self.callback_value, 'changedVal') self.assertEqual(self.callback_result, 8) t.unsubscribe(new_id)
def test_subscribe(self): t = Task("testTask", self.proc) resp = Update(0, None, None) resp.set_value('changedVal') t.q.put(resp) t.stop() new_id = t.subscribe(self.attr, self._callback, 3, 5) f1 = Future(t) t._futures = {1: f1} self.assertRaises(StopIteration, t.wait_all, f1, 0) self.assertEqual(self.callback_value, 'changedVal') self.assertEqual(self.callback_result, 8) t.unsubscribe(new_id)