Exemplo n.º 1
0
    def test_not_an_operator(self, operator_config):
        operator_config['implementation'] = __name__ + '.NotAnOperator'

        with pytest.raises(ConfigParsingError) as e:
            create_operator(operator_config)

        assert_terms_in_exception(e, ['not', 'operator'])
Exemplo n.º 2
0
    def test_invalid_implementation_no_dots(self, operator_config):
        operator_config['implementation'] = 'thisisnotanoperator'

        with pytest.raises(ConfigParsingError) as e:
            create_operator(operator_config)

        assert_terms_in_exception(e, ['invalid', 'implementation'])
Exemplo n.º 3
0
    def test_fail_non_param(self, operator_config):
        operator_config['params']['non_param'] = 10

        with pytest.raises(ConfigParsingError) as e:
            create_operator(operator_config)

        assert_terms_in_exception(e, ['invalid'])
Exemplo n.º 4
0
def test_nested_param_config():
    param_value = (3, 4)
    operator = NestedConfigParamTestOperator()
    operator.some_param = param_value
    operator_config = get_operator_config(operator)
    actual_operator = create_operator(operator_config)
    assert actual_operator.some_param == (3, 4)
Exemplo n.º 5
0
    def test_invalid_parameter_value(self, operator_config):
        class FailingParameter(ParameterSpec):
            def to_config(self, value: Any) -> Any:
                raise NotImplementedError()

            def from_config(self, operator_config: Any) -> None:
                assert False

        bak = OperatorForTesting.param1
        OperatorForTesting.param1 = FailingParameter(default_value=None)

        with pytest.raises(ConfigParsingError) as e:
            create_operator(operator_config)

        OperatorForTesting.param1 = bak

        assert_terms_in_exception(e, ['fail', 'pars'])
Exemplo n.º 6
0
    def test_missing_params(self, operator_config):
        del operator_config['params']['param2']

        operator = create_operator(operator_config)
        assert operator.param2 == param2_default_value
Exemplo n.º 7
0
 def test_ignore_non_parameters(self, operator_config):
     operator = create_operator(operator_config)
     assert operator.non_param is unique_object
Exemplo n.º 8
0
 def test_params(self, operator_config):
     operator = create_operator(operator_config)
     assert operator.param1 == param1_value
     assert operator.param2 == param2_value
Exemplo n.º 9
0
 def test_return_type(self, operator_config):
     operator = create_operator(operator_config)
     assert isinstance(operator, OperatorForTesting)
Exemplo n.º 10
0
 def test_unknown_pipeline_attribute(self, pipeline_config):
     pipeline_config['abc'] = 42
     with pytest.raises(ConfigParsingError) as e:
         _ = create_operator(pipeline_config)
     assert_terms_in_exception(e, ['unknown'])
Exemplo n.º 11
0
 def test_return_value(self, operator_config):
     operator = create_operator(operator_config)
     actual_operator_config = get_operator_config(operator)
     assert actual_operator_config == operator_config
Exemplo n.º 12
0
 def test_fail_missing_implementation(self, operator_config):
     del operator_config['implementation']
     with pytest.raises(ConfigParsingError):
         create_operator(operator_config)
Exemplo n.º 13
0
 def test_fail_extra_config_attributes(self, operator_config):
     operator_config['unknown_attribute'] = 42
     with pytest.raises(ConfigParsingError):
         create_operator(operator_config)