Esempio n. 1
0
 def test_migrate_params_impl_extra_output(self):
     lm = LoadedModule('x',
                       '1',
                       ParamDType.Dict({}),
                       migrate_params_impl=lambda x: x)
     with self.assertRaises(ValueError):
         lm.migrate_params({'x': 'should not be here'})
Esempio n. 2
0
 def test_migrate_params_impl_wrong_output_type(self):
     lm = LoadedModule('x', '1', migrate_params_impl=lambda x: x)
     with self.assertRaises(ValueError):
         lm.migrate_params(
             ParamDTypeDict({'x': ParamDTypeString()}),
             {'x': 2}  # should be str
         )
Esempio n. 3
0
 def test_migrate_params_impl_missing_output(self):
     lm = LoadedModule('x', '1', migrate_params_impl=lambda x: x)
     with self.assertRaises(ValueError):
         lm.migrate_params(
             ParamDTypeDict({'x': ParamDTypeString()}),
             {}  # should have 'x' key
         )
Esempio n. 4
0
    def test_migrate_params_impl_exception(self):
        def migrate_params(params):
            {}['a']

        lm = LoadedModule('x', '1', migrate_params_impl=migrate_params)
        with self.assertRaisesRegex(ValueError,
                                    r'migrate_params\(\) raised KeyError'):
            lm.migrate_params([], {})
Esempio n. 5
0
    def test_migrate_params_impl_exception(self):
        def migrate_params(params):
            {}["a"]

        lm = LoadedModule(
            "x", "1", ParamDType.Dict({}), migrate_params_impl=migrate_params
        )
        with self.assertRaisesRegex(ValueError, r"migrate_params\(\) raised KeyError"):
            lm.migrate_params({})
Esempio n. 6
0
 def test_migrate_params_impl_wrong_output_type(self):
     lm = LoadedModule(
         "x",
         "1",
         ParamDType.Dict({"x": ParamDType.String()}),
         migrate_params_impl=lambda x: x,
     )
     with self.assertRaises(ValueError):
         # should be str
         lm.migrate_params({"x": 2})
Esempio n. 7
0
 def test_migrate_params_impl_missing_output(self):
     lm = LoadedModule(
         "x",
         "1",
         ParamDType.Dict({"x": ParamDType.String()}),
         migrate_params_impl=lambda x: x,
     )
     with self.assertRaises(ValueError):
         # should have 'x' key
         lm.migrate_params({})
Esempio n. 8
0
    def test_migrate_params_impl(self):
        def migrate_params(params):
            return {"x": params["a"], "y": params["b"]}

        lm = LoadedModule(
            "x",
            "1",
            ParamDType.Dict({"x": ParamDType.Integer(), "y": ParamDType.Integer()}),
            migrate_params_impl=migrate_params,
        )
        result = lm.migrate_params({"a": 1, "b": 2})
        self.assertEqual(result, {"x": 1, "y": 2})
Esempio n. 9
0
    def test_migrate_params_impl(self):
        def migrate_params(params):
            return {'x': params['a'], 'y': params['b']}

        schema = ParamDTypeDict({
            'x': ParamDTypeInteger(),
            'y': ParamDTypeInteger(),
        })

        lm = LoadedModule('x', '1', migrate_params_impl=migrate_params)
        result = lm.migrate_params(schema, {'a': 1, 'b': 2})
        self.assertEqual(result, {'x': 1, 'y': 2})
Esempio n. 10
0
 def test_migrate_params_default(self):
     lm = LoadedModule('x', '1', migrate_params_impl=None)
     result = lm.migrate_params(
         ParamDTypeDict({
             'missing': ParamDTypeString(default='x'),
             'wrong_type': ParamDTypeBoolean(),
             'ok': ParamDTypeInteger(),
         }), {
             'wrong_type': 'true',
             'ok': 3
         })
     self.assertEqual(result, {'missing': 'x', 'wrong_type': True, 'ok': 3})
Esempio n. 11
0
 def test_migrate_params_default(self):
     lm = LoadedModule(
         "x",
         "1",
         ParamDType.Dict(
             {
                 "missing": ParamDType.String(default="x"),
                 "wrong_type": ParamDType.Boolean(),
                 "ok": ParamDType.Integer(),
             }
         ),
         migrate_params_impl=None,
     )
     result = lm.migrate_params({"wrong_type": "true", "ok": 3})
     self.assertEqual(result, {"missing": "x", "wrong_type": True, "ok": 3})
Esempio n. 12
0
 def test_migrate_params_impl_extra_output(self):
     lm = LoadedModule(
         "x", "1", ParamDType.Dict({}), migrate_params_impl=lambda x: x
     )
     with self.assertRaises(ValueError):
         lm.migrate_params({"x": "should not be here"})