def setUp(self): self.sf = SyncFactory("sync") self.process = Process("proc", self.sf) DefaultController("hello", self.process, parts=dict(hello=HelloPart(self.process, None))) DefaultController("counter", self.process, parts=dict(counter=CounterPart(self.process, None))) WebsocketServerComms(self.process, dict(port=self.socket)) self.process.start() self.process2 = Process("proc2", self.sf) WebsocketClientComms(self.process2, dict(hostname="localhost", port=self.socket)) self.process2.start()
class TestCounterPart(unittest.TestCase): def setUp(self): self.c = CounterPart(Mock(), None) list(self.c.create_attributes()) def test_increment_increments(self): self.assertEquals(0, self.c.counter.value) self.c.increment() self.assertEquals(1, self.c.counter.value) self.c.increment() self.assertEquals(2, self.c.counter.value) def test_reset_sets_zero(self): self.c.counter.set_endpoint_data("value", 1234, notify=False) self.c.zero() self.assertEquals(0, self.c.counter.value)
class TestCounterPart(unittest.TestCase): def setUp(self): self.c = CounterPart(Mock(), Mock()) list(self.c.create_attributes()) def test_increment_increments(self): self.assertEquals(0, self.c.counter.value) self.c.increment() self.assertEquals(1, self.c.counter.value) self.c.increment() self.assertEquals(2, self.c.counter.value) def test_reset_sets_zero(self): self.c.counter.set_endpoint_data("value", 1234, notify=False) self.c.zero() self.assertEquals(0, self.c.counter.value)
def test_counter_subscribe(self): sync_factory = SyncFactory("sched") process = Process("proc", sync_factory) part = CounterPart(process, None) b = DefaultController("counting", process, parts={ "counter": part }).block process.start() # wait until block is Ready task = Task("counter_ready_task", process) futures = task.when_matches(b["state"], "Ready") task.wait_all(futures, timeout=1) q = sync_factory.create_queue() sub = Subscribe(response_queue=q, context="ClientConnection", endpoint=["counting", "counter"], delta=False) process.q.put(sub) resp = q.get(timeout=1) self.assertIsInstance(resp, Update) attr = NTScalar.from_dict(resp.value) self.assertEqual(0, attr.value) post = Post(response_queue=q, context="ClientConnection", endpoint=["counting", "increment"]) process.q.put(post) resp = q.get(timeout=1) self.assertIsInstance(resp, Update) self.assertEqual(resp.value["value"], 1) resp = q.get(timeout=1) self.assertIsInstance(resp, Return) process.stop()
def setUp(self): self.c = CounterPart(Mock(), Mock()) list(self.c.create_attributes())