Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
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])
Ejemplo n.º 7
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])
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 def setUp(self):
     self.meta = VMeta("test_description")
Ejemplo n.º 11
0
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):
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 def setUp(self):
     self.meta = VMeta("test_description")
Ejemplo n.º 14
0
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):