def test_set_label(self): meta = VMeta("test_description") meta.on_changed = Mock(wrap=meta.on_changed) label = "my label" notify = Mock() meta.set_label(label, notify=notify) self.assertEquals(meta.label, label) meta.on_changed.assert_called_once_with([["label"], label], notify)
def test_set_writeable(self): meta = VMeta("test_description") meta.on_changed = Mock(wrap=meta.on_changed) writeable = True notify = Mock() meta.set_writeable(writeable, notify=notify) self.assertEquals(meta.writeable, writeable) meta.on_changed.assert_called_once_with([["writeable"], writeable], notify)
def test_set_label(self): meta = VMeta("test_description") meta.on_changed = Mock(wrap=meta.on_changed) label = "my label" notify = Mock() meta.set_label(label, notify=notify) self.assertEquals(meta.label, label) meta.on_changed.assert_called_once_with( [["label"], label], notify)
def test_set_writeable(self): meta = VMeta("test_description") meta.on_changed = Mock(wrap=meta.on_changed) writeable = True notify = Mock() meta.set_writeable(writeable, notify=notify) self.assertEquals(meta.writeable, writeable) meta.on_changed.assert_called_once_with( [["writeable"], writeable], notify)
class TestVMeta(unittest.TestCase): def setUp(self): self.meta = VMeta("test description") def test_values_after_init(self): assert "test description" == self.meta.description assert not self.meta.writeable def test_given_validate_called_then_raise_error(self): with self.assertRaises(NotImplementedError): self.meta.validate(1)
class TestValidate(unittest.TestCase): def setUp(self): self.meta = VMeta("test_description") def test_given_validate_called_then_raise_error(self): expected_error_message = "Abstract validate function must be implemented in child classes" with self.assertRaises(NotImplementedError) as error: self.meta.validate(1) self.assertEqual(expected_error_message, error.exception.args[0])
class TestValidate(unittest.TestCase): def setUp(self): self.meta = VMeta("test_description") def test_given_validate_called_then_raise_error(self): expected_error_message = \ "Abstract validate function must be implemented in child classes" with self.assertRaises(NotImplementedError) as error: self.meta.validate(1) self.assertEqual(expected_error_message, error.exception.args[0])
def setUp(self): self.callback_result = 0 self.callback_value = '' meta = VMeta("meta for unit tests") self.proc = MagicMock(q=queue.Queue()) self.proc.create_queue = MagicMock(side_effect=queue.Queue) self.block = Block() self.block.set_parent(self.proc, "testBlock") self.attr = meta.make_attribute() self.attr.set_parent(self.block, "testAttr") self.attr2 = meta.make_attribute() self.attr2.set_parent(self.block, "testAttr2") self.method = MethodMeta("method for unit tests") self.method.set_parent(self.block, "testFunc") self.method2 = MethodMeta("method for unit tests") self.method2.set_parent(self.block, "testFunc") self.bad_called_back = False
def test_to_dict(self): m = VMeta("desc", writeable=True, label="my label") m.typeid = "filled_in_by_subclass" self.assertEqual(m.to_dict(), self.serialized)
def setUp(self): self.meta = VMeta("test_description")
import os import sys import unittest from collections import OrderedDict sys.path.append(os.path.join(os.path.dirname(__file__), "..")) from mock import Mock from malcolm.core.serializable import Serializable from malcolm.core.vmeta import VMeta # Register ScalarMeta as a sublcass of itself so we # can instantiate it for testing purposes. VMeta.register_subclass("scalarmeta:test")(VMeta) class TestInit(unittest.TestCase): def setUp(self): self.meta = VMeta("test description") def test_values_after_init(self): self.assertEqual("test description", self.meta.description) self.assertFalse(self.meta.writeable) class TestValidate(unittest.TestCase): def setUp(self): self.meta = VMeta("test_description") def test_given_validate_called_then_raise_error(self):