Пример #1
0
def test_context_manager():

    app1 = dialite._get_app()
    with dialite.NoDialogs():
        app2 = dialite._get_app()
    app3 = dialite._get_app()

    assert app1 is app3
    assert app1 is not app2
    assert isinstance(app2, StubApp)
Пример #2
0
def test_get_app():

    app1 = dialite._get_app()
    app2 = dialite._get_app()
    app3 = dialite._get_app(True)
    app4 = dialite._get_app()
    assert app1 is app2
    assert app3 is app4
    assert app1 is not app3
    assert type(app1) is type(app3)
Пример #3
0
def test_unsupported_platform1():
    """ Unsupported platform, fallback to terminal. """

    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app

    sys.platform = 'meh'

    sys.stdin = FakeStdin()

    try:

        app = dialite._get_app(True)
        assert app.works()
        assert isinstance(app, TerminalApp)

        assert dialite.is_supported()

        with capture_log('info') as log:
            dialite.inform()
        assert len(log) == 1 and 'Info: ' in log[0]

        with capture_log('info') as log:
            dialite.warn()  # no problem
        assert len(log) == 1 and 'Warning: ' in log[0]

        with capture_log('info') as log:
            dialite.fail()
        assert len(log) == 1 and 'Error: ' in log[0]

        assert dialite.ask_ok()
        assert dialite.ask_retry()
        assert dialite.ask_yesno()

        sys.stdin.answer = 'no'
        assert not dialite.ask_ok()
        assert not dialite.ask_retry()
        assert not dialite.ask_yesno()

    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
Пример #4
0
def test_unsupported_platform2():
    """ Unsupported platform, and also no terminal. """

    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app
    o_open = webbrowser.open

    sys.platform = 'meh'
    sys.stdin = None
    webbrowser.open = lambda x: None

    try:

        app = dialite._get_app(True)
        assert app.works()
        assert isinstance(app, StubApp)

        assert not dialite.is_supported()

        dialite.inform()  # no problem

        dialite.warn()  # no problem

        dialite.fail()  # no problem
        # with raises(SystemExit):
        #     dialite.fail()

        with raises(SystemExit):
            dialite.ask_ok()

        with raises(SystemExit):
            dialite.ask_retry()

        with raises(SystemExit):
            dialite.ask_yesno()

    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
        webbrowser.open = o_open