Esempio n. 1
0
def test_multiple_state_application(monkeypatch):
    app = Application()
    app.register(StateMock)
    app.register(AnotherStateMock)

    assert len(app.states) == 2
    # Ensure that Application._state hasn't changed
    assert isinstance(app.state, StateMock)

    app.state = AnotherStateMock.__name__
    assert isinstance(app.state, AnotherStateMock)

    # Test Application.trigger_state
    called_with = []

    def new_trigger(self, *args, **kwargs):
        called_with.extend([args, kwargs])

    monkeypatch.setattr(StateMock, "trigger", new_trigger)
    app.trigger_state(StateMock.__name__, 10, test=20)
    assert isinstance(app.state, StateMock)
    assert called_with == [(10, ), {"test": 20}]

    # Test Application.trigger_reinit
    app.state.marker = "something"
    assert hasattr(app.state, "marker") is True
    app.trigger_reinit(StateMock.__name__)
    assert isinstance(app.state, StateMock)
    assert hasattr(app.state, "marker") is False

    assert pytest.raises(ValueError, lambda: setattr(app, "fps", "thirty"))
Esempio n. 2
0
def test_application_loop():
    app = Application()
    app.register(StateMock)
    # FIXME: test loop properly
    # assert app.start() is None

    app.register(AnotherStateMock)
    app.state = AnotherStateMock.__name__
    # FIXME: test loop properly
    # assert app.start() is None
    assert app.stop() is None
Esempio n. 3
0
def test_single_state_application():
    app = Application()
    app.register(StateMock)

    assert len(app._states) == 1  # pylint: disable=protected-access
    assert isinstance(app.state, StateMock)

    assert pytest.raises(
        eaf.errors.ApplicationStateIsNotRegistered,
        lambda: setattr(app, "state", "test"),
    )
Esempio n. 4
0
def test_empty_application():
    assert pytest.raises(eaf.errors.ApplicationNotInitializedError,
                         eaf.app.current)
    assert pytest.raises(eaf.errors.ApplicationNotInitializedError,
                         Application.current)

    app = Application()
    assert eaf.app.current() is app
    assert Application.current() is app

    assert pytest.raises(eaf.errors.ApplicationIsEmpty, lambda: app.state)
    assert pytest.raises(eaf.errors.ApplicationIsEmpty, app.start)

    assert app.renderer is not None
    assert app.event_queue is None

    assert app.fps is not None
    app.fps = 40
    assert app.fps == 40

    assert eaf.app.current() is app
    del app
    assert pytest.raises(eaf.errors.ApplicationNotInitializedError,
                         eaf.app.current)
Esempio n. 5
0
 def stop():
     try:
         Application.current().deregister(MockedState.__name__)
     except eaf.errors.ApplicationNotInitializedError:
         pass
Esempio n. 6
0
 def inner(mock_app=False):
     if mock_app:
         mock_application()
     Application.current().register(MockedState)
     return Application.current().state
Esempio n. 7
0
 def _finalize():
     try:
         app = Application.current()
         app.stop()
     except eaf.errors.ApplicationNotInitializedError:
         pass