Esempio n. 1
0
def test_process_registry_add_hidden():
    reg = ProcessRegistry()

    @reg.add_hidden
    def foo(*args):
        return 42

    new_foo = reg.get_function('foo')
    assert new_foo() == 42
    with pytest.raises(ProcessUnsupportedException):
        reg.get_spec('foo')
Esempio n. 2
0
def test_process_registry_add_by_name_and_namespace():
    reg = ProcessRegistry()
    reg.add_spec_by_name("max", namespace="foo")
    assert not reg.contains("max")
    assert reg.contains("max", namespace="foo")
    with pytest.raises(ProcessUnsupportedException):
        reg.get_spec('max')
    spec = reg.get_spec('max', namespace="foo")
    assert spec['id'] == 'max'
    assert 'largest value' in spec['description']
    assert all(k in spec for k in ['parameters', 'returns'])
def test_process_registry_add_deprecated():
    reg = ProcessRegistry()

    @reg.add_deprecated
    def foo(*args):
        return 42

    new_foo = reg.get_function('foo')
    with pytest.warns(UserWarning, match="deprecated process"):
        assert new_foo() == 42
    with pytest.raises(ProcessUnsupportedException):
        reg.get_spec('foo')
Esempio n. 4
0
def test_process_registry_add_hidden_with_namespace():
    reg = ProcessRegistry()

    def bar(*args):
        return 42

    reg.add_hidden(bar, name="boz", namespace="secret")

    new_bar = reg.get_function('boz', namespace="secret")
    assert new_bar() == 42
    with pytest.raises(ProcessUnsupportedException):
        reg.get_spec('bar', namespace="secret")
    with pytest.raises(ProcessUnsupportedException):
        reg.get_spec('boz', namespace="secret")
def test_process_registry_add_by_name():
    reg = ProcessRegistry()
    reg.add_spec_by_name("max")
    assert set(reg._processes.keys()) == {"max"}
    spec = reg.get_spec('max')
    assert spec['id'] == 'max'
    assert 'largest value' in spec['description']
    assert all(k in spec for k in ['parameters', 'returns'])
def test_process_registry_add_function():
    reg = ProcessRegistry()

    @reg.add_function
    def max(*args):
        return max(*args)

    assert set(reg._processes.keys()) == {"max"}
    spec = reg.get_spec('max')
    assert spec['id'] == 'max'
    assert 'largest value' in spec['description']
    assert all(k in spec for k in ['parameters', 'returns'])

    assert reg.get_function('max') is max
Esempio n. 7
0
def test_process_registry_add_function_other_name():
    reg = ProcessRegistry()

    @reg.add_function(name="max")
    def madmax(*args):
        return max(*args)

    assert reg.contains("max")
    spec = reg.get_spec('max')
    assert spec['id'] == 'max'
    assert 'largest value' in spec['description']
    assert all(k in spec for k in ['parameters', 'returns'])

    assert reg.get_function('max') is madmax
def test_process_registry_with_spec_100():
    reg = ProcessRegistry()

    def add_function_with_spec(spec: ProcessSpec):
        def decorator(f):
            reg.add_function(f=f, spec=spec.to_dict_100())
            return f

        return decorator

    @add_function_with_spec(
        ProcessSpec("foo", "bar").param("input",
                                        "Input",
                                        schema=ProcessSpec.RASTERCUBE).returns(
                                            description="Output",
                                            schema=ProcessSpec.RASTERCUBE))
    def foo(*args):
        return 42

    assert reg.get_spec('foo') == {
        "id":
        "foo",
        "description":
        "bar",
        "parameters": [
            {
                "name": "input",
                "description": "Input",
                "schema": {
                    "type": "object",
                    "format": "raster-cube"
                },
                "optional": False
            },
        ],
        "returns": {
            "description": "Output",
            "schema": {
                "type": "object",
                "format": "raster-cube"
            }
        }
    }
Esempio n. 9
0
def test_process_registry_add_function_argument_names():
    reg = ProcessRegistry(argument_names=["args", "env"])

    @reg.add_function
    def max(args, env=None):
        return max(*args)

    with pytest.raises(ProcessRegistryException):

        @reg.add_function
        def min(args):
            return min(*args)

    assert reg.contains("max")
    spec = reg.get_spec('max')
    assert spec['id'] == 'max'
    assert 'largest value' in spec['description']
    assert all(k in spec for k in ['parameters', 'returns'])
    assert reg.get_function('max') is max
def test_process_registry_get_spec():
    reg = ProcessRegistry()
    reg.add_spec_by_name("min")
    reg.add_spec_by_name("max")
    with pytest.raises(ProcessUnsupportedException):
        reg.get_spec('foo')