Exemplo n.º 1
0
 def test_substitute_params(self):
     section = Section("f", 1, "name", {
         "name": "$(name):pos",
         "exposure": 1.0
     })
     params = {"name": "me"}
     param_dict = section.substitute_params(params)
     expected = {"name": "me:pos", "exposure": 1.0}
     assert param_dict == expected
Exemplo n.º 2
0
    def test_instantiate(self):
        @method_takes("desc", StringMeta("description"), REQUIRED, "foo",
                      StringMeta("optional thing"), "thing")
        def f(extra, params):
            return extra, 2, params.desc, params.foo

        ca = Mock(CAPart=f)
        parts = Mock(ca=ca)
        section = Section("ca.CAPart", dict(desc="my name"))
        result = section.instantiate({}, parts, "extra")
        self.assertEqual(result, ("extra", 2, "my name", "thing"))
Exemplo n.º 3
0
    def test_instantiate(self, mock_import):
        @add_call_types
        def f(desc: ADesc, foo: AThing = "thing") -> Any:
            return 2, desc, foo

        mock_import.return_value = Mock(MyPart=f)

        section = Section("f", 1, "mymodule.parts.MyPart",
                          dict(desc="my name"))
        result = section.instantiate({})
        mock_import.assert_called_once_with("malcolm.modules.mymodule.parts")
        assert result == (2, "my name", "thing")
Exemplo n.º 4
0
    def test_instantiate(self, mock_import):
        @method_takes("desc", StringMeta("description"), REQUIRED, "foo",
                      StringMeta("optional thing"), "thing")
        def f(extra, params):
            return extra, 2, params.desc, params.foo

        mock_import.return_value = Mock(MyPart=f)

        section = Section("f", 1, "mymodule.parts.MyPart",
                          dict(desc="my name"))
        result = section.instantiate({}, "extra")
        mock_import.assert_called_once_with("malcolm.modules.mymodule.parts")
        assert result == ("extra", 2, "my name", "thing")
Exemplo n.º 5
0
 def test_repr(self):
     s = Section("f", 1, "ca.CADoublePart", {"name": "me"})
     expected = "Section(ca.CADoublePart, {'name': 'me'})"
     assert repr(s) == expected
Exemplo n.º 6
0
 def test_repr(self):
     s = Section("ca.CADoublePart", {"name": "me"})
     expected = "Section(ca.CADoublePart, {'name': 'me'})"
     self.assertEqual(repr(s), expected)
Exemplo n.º 7
0
 def test_substitute_params(self):
     section = Section("name", {"name": "$(name):pos", "exposure": 1.0})
     params = {"name": "me"}
     param_dict = section.substitute_params(params)
     expected = {"name": "me:pos", "exposure": 1.0}
     self.assertEqual(param_dict, expected)