コード例 #1
0
def test_empty():
    args = OrderedDict((
        ("String Value", None),
        ("Bool Value", None),
        ("Int Value", None),
        ("Float Value", None),
        ("Object Value", None),
        ("Data Value", None),
    ))

    comp = TestComp()

    comp.assert_failure(NotStartedError("The proxy has not been started yet."))
    comp.start(args)

    assert_failure(comp.string_value,
                   ValueError("Missing required argument 'String Value'."))
    assert_failure(comp.bool_value,
                   ValueError("Missing required argument 'Bool Value'."))
    assert_failure(comp.int_value,
                   ValueError("Missing required argument 'Int Value'."))
    assert_failure(comp.float_value,
                   ValueError("Missing required argument 'Float Value'."))
    assert_failure(comp.object_value,
                   ValueError("Missing required argument 'Object Value'."))
    assert_failure(comp.data_value,
                   ValueError("Missing required argument 'Data Value'."))

    comp.dispose()
    comp.assert_failure(
        AlreadyDisposedError("The proxy instance has been disposed already."))
コード例 #2
0
def test_success():
    other = KX_GameObject(None)
    camera = Camera()

    args = OrderedDict((
        ("String Value", "DEF"),
        ("Bool Value", False),
        ("Int Value", 321),
        ("Float Value", 1.5),
        ("Object Value", other),
        ("Data Value", camera),
    ))

    comp = TestComp()

    comp.assert_failure(NotStartedError("The proxy has not been started yet."))
    comp.start(args)

    assert comp.string_value == Success("DEF")
    assert comp.bool_value == Success(False)
    assert comp.int_value == Success(321)
    assert comp.float_value == Success(1.5)
    assert comp.object_value == Success(other)
    assert comp.data_value == Success(camera)

    comp.dispose()
    comp.assert_failure(
        AlreadyDisposedError("The proxy instance has been disposed already."))
コード例 #3
0
ファイル: test_args.py プロジェクト: mysticfall/alleycat
def test_invalid():
    args = OrderedDict((
        ("String Value", True),
        ("Bool Value", 123),
        ("Int Value", "ABC"),
        ("Float Value", dict()),
        ("Object Value", list()),
        ("Data Value", 1.2),
    ))

    comp = TestComp()

    comp.assert_exception(
        NotStartedError("The proxy has not been started yet."))
    comp.start(args)

    error = InvalidTypeError

    assert_exception(
        comp, "string_value",
        error("Value True is not of expected type 'str' (actual: 'bool')."))
    assert_exception(
        comp, "bool_value",
        error("Value 123 is not of expected type 'bool' (actual: 'int')."))
    assert_exception(
        comp, "int_value",
        error("Value ABC is not of expected type 'int' (actual: 'str')."))
    assert_exception(
        comp, "float_value",
        error("Value {} is not of expected type 'float' (actual: 'dict')."))
    assert_exception(
        comp, "object_value",
        error(
            "Value [] is not of expected type 'KX_GameObject' (actual: 'list')."
        ))
    assert_exception(
        comp, "data_value",
        error("Value 1.2 is not of expected type 'Camera' (actual: 'float')."))

    comp.dispose()
    comp.assert_exception(
        AlreadyDisposedError("The proxy instance has been disposed already."))
コード例 #4
0
ファイル: base.py プロジェクト: mysticfall/alleycat
from abc import ABC
from collections import OrderedDict
from typing import Final, final

from bge.types import KX_GameObject, KX_PythonComponent
from returns.result import Result, ResultE

from alleycat.common import AlreadyDisposedError, LoggingSupport, NotStartedError
from alleycat.core import ArgumentsHolder

RESULT_NOT_STARTED: Final = Result.from_failure(
    NotStartedError("The proxy has not been started yet."))

RESULT_DISPOSED: Final = Result.from_failure(
    AlreadyDisposedError("The proxy instance has been disposed already."))


class BaseProxy(ArgumentsHolder, LoggingSupport, ABC):
    _start_args: ResultE[OrderedDict] = RESULT_NOT_STARTED

    @final
    @property
    def start_args(self) -> ResultE[OrderedDict]:
        return self._start_args

    @property
    def valid(self) -> bool:
        return isinstance(self.start_args, Result.success_type)

    def start(self, args: OrderedDict) -> None:
        self._start_args = Result.from_value(args)