예제 #1
0
    def test_counter_subscribe(self):
        sync_factory = SyncFactory("sched")
        process = Process("proc", sync_factory)
        b = Counter(process, dict(mri="counting"))[0]
        process.start()
        # wait until block is Ready
        task = Task("counter_ready_task", process)
        task.when_matches(b["state"], "Ready", 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()
예제 #2
0
 def test_from_dict(self):
     a = NTScalar.from_dict(self.serialized)
     self.assertEquals(a.meta.to_dict(), StringMeta("desc").to_dict())
     self.assertEquals(a.value, "some string")
예제 #3
0
 def test_from_dict(self):
     a = NTScalar.from_dict(self.serialized)
     assert a.meta.to_dict() == StringMeta("desc").to_dict()
     assert a.value == "some string"