Beispiel #1
0
def test_optional_wire(config_type, empty_type, config_empty):
    """
    import "google/protobuf/empty.proto";

    message Configuration {
        google.protobuf.Empty db = 1;
    }
    """

    class DBWire(Wire):
        _value: empty_type

        def configure(self, value: empty_type):
            assert isinstance(value, empty_type), type(value)
            self._value = value

        def __eq__(self, other):
            return self._value == other._value

    @dataclass
    class WiresIn:
        db: Optional[DBWire]

    @dataclass
    class WiresOut:
        pass

    runner = Runner(config_type, WiresIn, WiresOut)

    setup = Mock()
    setup.return_value = awaitable(WiresOut())

    with tempfile.NamedTemporaryFile(suffix=".yaml") as config_yaml:
        if not config_empty:
            config_yaml.write(b"db: {}\n")
            config_yaml.flush()
        assert runner.run(setup, ["test", config_yaml.name]) == 0

    if config_empty:
        setup.assert_called_once_with(
            config_type(), WiresIn(db=None),
        )
    else:
        expected_db = DBWire()
        expected_db.configure(empty_type())
        setup.assert_called_once_with(
            config_type(db=empty_type()), WiresIn(db=expected_db),
        )
Beispiel #2
0
def test_required_wire(config_type, empty_type, config_empty):
    """
    import "google/protobuf/empty.proto";

    message Configuration {
        google.protobuf.Empty db = 1 [(validate.rules).message.required = true];
    }
    """

    class DBWire(Wire):
        _value: empty_type

        def configure(self, value: empty_type):
            assert isinstance(value, empty_type), type(value)
            self._value = value

        def __eq__(self, other):
            return self._value == other._value

    @dataclass
    class WiresIn:
        db: DBWire

    @dataclass
    class WiresOut:
        pass

    runner = Runner(config_type, WiresIn, WiresOut)

    setup = Mock()
    with tempfile.NamedTemporaryFile(suffix=".yaml") as config_yaml:
        if config_empty:
            with pytest.raises(ValidationError, match="db is required"):
                runner.run(setup, ["test", config_yaml.name])
        else:
            setup.return_value = awaitable(WiresOut())
            config_yaml.write(b"db: {}\n")
            config_yaml.flush()
            assert runner.run(setup, ["test", config_yaml.name]) == 0
            expected_db = DBWire()
            expected_db.configure(empty_type())
            setup.assert_called_once_with(
                config_type(db=empty_type()), WiresIn(db=expected_db),
            )
Beispiel #3
0
def test_empty(config_type):
    """
    message Configuration {}
    """

    @dataclass
    class WiresIn:
        pass

    @dataclass
    class WiresOut:
        pass

    runner = Runner(config_type, WiresIn, WiresOut)

    async def setup(config, wires_in):
        return WiresOut()

    with tempfile.NamedTemporaryFile(suffix=".yaml") as config_yaml:
        assert runner.run(setup, ["test", config_yaml.name]) == 0
Beispiel #4
0
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
# source: kirk.proto
# plugin: harness.plugin.python
import sys

from harness.runtime import Runner

import kirk
import kirk_pb2
import kirk_wires

runner = Runner(
    kirk_pb2.Configuration,
    kirk_wires.WiresIn,
    kirk_wires.WiresOut,
)

if __name__ == '__main__':
    sys.exit(runner.run(kirk.setup, sys.argv))
Beispiel #5
0
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
# source: pulsar.proto
# plugin: harness.plugin.python
import sys

from harness.runtime import Runner

import pulsar
import pulsar_pb2
import pulsar_wires

runner = Runner(
    pulsar_pb2.Configuration,
    pulsar_wires.WiresIn,
    pulsar_wires.WiresOut,
)

if __name__ == '__main__':
    sys.exit(runner.run(pulsar.setup, sys.argv))
Beispiel #6
0
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
# source: mccoy.proto
# plugin: harness.plugin.python
import sys

from harness.runtime import Runner

import mccoy
import mccoy_pb2
import mccoy_wires

runner = Runner(
    mccoy_pb2.Configuration,
    mccoy_wires.WiresIn,
    mccoy_wires.WiresOut,
)

if __name__ == '__main__':
    sys.exit(runner.run(mccoy.setup, sys.argv))
Beispiel #7
0
# Generated by the Protocol Buffers compiler. DO NOT EDIT!
# source: scotty.proto
# plugin: harness.plugin.python
import sys

from harness.runtime import Runner

import scotty
import scotty_pb2
import scotty_wires

runner = Runner(
    scotty_pb2.Configuration,
    scotty_wires.WiresIn,
    scotty_wires.WiresOut,
)

if __name__ == '__main__':
    sys.exit(runner.run(scotty.setup, sys.argv))