class TestAttribute(unittest.TestCase): def setUp(self): self.data = NTScalar(StringMeta()) self.data.set_notifier_path(Mock(), ["block", "attr"]) self.controller = Mock() self.context = Mock() self.o = Attribute(self.controller, self.context, self.data) def test_init(self): self.assertIsInstance(self.o, Attribute) assert hasattr(self.o, "meta") assert hasattr(self.o, "subscribe_meta") assert hasattr(self.o, "value") assert hasattr(self.o, "subscribe_value") def test_put(self): self.o.put_value(32) self.context.put.assert_called_once_with(["block", "attr", "value"], 32, timeout=None) def test_put_async(self): f = self.o.put_value_async(32) self.context.put_async.assert_called_once_with( ["block", "attr", "value"], 32) assert f == self.context.put_async.return_value def test_repr(self): self.controller.make_view.return_value = "foo" assert repr(self.o) == "<Attribute value='foo'>" self.controller.make_view.assert_called_once_with( self.context, self.o, "value")
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()
def setUp(self): self.data = NTScalar(StringMeta()) self.data.set_notifier_path(Mock(), ["block", "attr"]) self.controller = Mock() self.context = Mock() self.o = Attribute(self.controller, self.context, self.data)
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")
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"