Beispiel #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'])
Beispiel #2
0
 def test_invalid_index(self, idx):
     pipeline = CompVizPipeline()
     pipeline.add_operator('op0', TestOperator())
     pipeline.add_operator('op1', TestOperator())
     with pytest.raises(ValueError) as e:
         pipeline.get_operator_name(idx)
     assert_terms_in_exception(e, ['invalid', 'index'])
Beispiel #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'])
Beispiel #4
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'])
Beispiel #5
0
 def test_invalid_target(self, target):
     pipeline = CompVizPipeline()
     pipeline.add_operator('op0', TestOperator())
     pipeline.add_operator('op1', TestOperator())
     with pytest.raises(ValueError) as e:
         pipeline.move_operator('op0', target)
     assert_terms_in_exception(e, ['invalid', 'target'])
Beispiel #6
0
    def test_duplicated_name(self):
        pipeline = CompVizPipeline()
        pipeline.add_operator('test_op', TestOperator())
        with pytest.raises(ValueError) as e:
            pipeline.add_operator('test_op', TestOperator())

        assert_terms_in_exception(e, ['duplicated'])
Beispiel #7
0
def test_double_parameter_invalid_step_size(step_size):
    with pytest.raises(ValueError) as e:
        DoubleParameter(default_value=1,
                        lower=0,
                        upper=10,
                        step_size=step_size)
    assert_terms_in_exception(e, ["invalid", "step"])
Beispiel #8
0
    def test_rename_nonexistent_name(self):
        pipeline = CompVizPipeline()

        with pytest.raises(ValueError) as e:
            pipeline.rename_operator('nonexistent', 'foo')

        assert_terms_in_exception(e, ['operator', 'name'])
Beispiel #9
0
    def test_invalid_class(self):
        class NotAnOperator(object):
            pass

        with pytest.raises(ValueError) as e:
            register_operator(NotAnOperator)
        assert_terms_in_exception(e, ['not', 'operator'])
Beispiel #10
0
def test_pipeline_context_add_info_repeated_names(ctx):
    info_object = object()
    name = 'info_name'
    ctx.add_info(name, info_object)
    with pytest.raises(ValueError) as e:
        another_object = object()
        ctx.add_info(name, another_object)

    assert_terms_in_exception(e, ['duplicated', 'name'])
Beispiel #11
0
    def test_rename_to_existent_name(self):
        pipeline = CompVizPipeline()

        pipeline.add_operator('op1', TestOperator())
        pipeline.add_operator('op2', TestOperator())

        with pytest.raises(ValueError) as e:
            pipeline.rename_operator('op1', 'op2')

        assert_terms_in_exception(e, ['name'])
Beispiel #12
0
def test_boolean_invalid_values(value):
    with pytest.raises(ValueError) as e:
        BooleanParameter(default_value=value)
    assert_terms_in_exception(e, ['invalid', 'default', 'value'])

    param = BooleanParameter(True)
    with pytest.raises(AssertionError) as e:
        param.from_config(value)

    with pytest.raises(AssertionError) as e:
        param.to_config(value)
Beispiel #13
0
    def test_check_op_return(self, return_value):
        class TestWrongReturnOperator(Operator):
            def run(self, img: np.ndarray, ctx: PipelineContext) -> Any:
                return return_value

        pipeline = CompVizPipeline()
        pipeline.add_operator('test_op', TestWrongReturnOperator())

        with pytest.raises(BadImageError) as e:
            pipeline.run(build_img((16, 16)))

        assert_terms_in_exception(e, ['return', 'invalid'])
Beispiel #14
0
    def test_gray_only_flag(self):
        @settings.GRAY_ONLY(True)
        class TestOnlyGrayFlagOperator(Operator):
            def run(self, img: Image, ctx: PipelineContext) -> Image:
                return img

        pipeline = CompVizPipeline()
        pipeline.add_operator('test_op', TestOnlyGrayFlagOperator())

        with pytest.raises(OperatorFailedError) as e:
            pipeline.run(build_img((16, 16), rgb=True))

        assert_terms_in_exception(e, ["expect", "gray"])
Beispiel #15
0
    def test_operator_cant_alter_original_img(self):
        class TestCtxOriginalImg(Operator):
            def run(self, img: Image, ctx: PipelineContext) -> Image:
                original_img = ctx.original_img
                original_img[10, ...] = 255
                return img

        pipeline = CompVizPipeline()
        pipeline.add_operator('test_op', TestCtxOriginalImg())

        test_img = build_img((128, 128), kind='black')
        with pytest.raises(OperatorFailedError) as e:
            pipeline.run(test_img)

        assert_terms_in_exception(e, ['read-only'])
Beispiel #16
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'])
Beispiel #17
0
def test_pipeline_context_invalid_img(img):
    with pytest.raises(ValueError) as e:
        PipelineContext(img)

    assert_terms_in_exception(e, ['invalid', 'image'])
Beispiel #18
0
def test_img2qimg_invalid_img(img):
    with pytest.raises(ValueError) as e:
        img2QImage(img)
    assert_terms_in_exception(e, ['invalid', 'image'])
Beispiel #19
0
def test_integer_parameter_invalid_lower_upper_limits(limits):
    with pytest.raises(ValueError) as e:
        IntegerParameter(default_value=5, lower=limits[0], upper=limits[1])
    assert_terms_in_exception(e, ['invalid'])
Beispiel #20
0
def test_enum_invalid_default_param(value):
    with pytest.raises(ValueError) as e:
        _ = EnumParameter(['1', '2', '3'], default_value=value)

    assert_terms_in_exception(e, ['invalid', 'default', 'value'])
Beispiel #21
0
def test_pipeline_context_invalid_name(ctx, invalid_name):
    with pytest.raises(ValueError) as e:
        ctx.add_info(invalid_name, object())

    assert_terms_in_exception(e, ['invalid', 'name'])
Beispiel #22
0
def test_double_parameter_invalid_default_value(value):
    with pytest.raises(ValueError) as e:
        DoubleParameter(default_value=value, lower=0, upper=5)
    assert_terms_in_exception(e, ['invalid', 'default'])
Beispiel #23
0
def test_integer_parameter_invalid_default_value(default_value):
    with pytest.raises(ValueError) as e:
        IntegerParameter(default_value=default_value, lower=0, upper=10)
    assert_terms_in_exception(e, ['invalid', 'default'])
Beispiel #24
0
 def test_invalid_idx(self, idx):
     pipeline = CompVizPipeline()
     pipeline.add_operator('test_op', TestOperator())
     with pytest.raises(ValueError) as e:
         pipeline.remove_operator(idx)
     assert_terms_in_exception(e, ['invalid', 'operator'])
Beispiel #25
0
    def test_invalid_img(self, img):
        pipeline = CompVizPipeline()
        with pytest.raises(BadImageError) as e:
            pipeline.run(img)

        assert_terms_in_exception(e, ['invalid', 'image'])
Beispiel #26
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'])
Beispiel #27
0
def test_pipeline_context_original_img_read_only(ctx):
    with pytest.raises(ValueError) as e:
        ctx.original_img[:] = 0

    assert_terms_in_exception(e, ['read-only'])