Example #1
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
Example #2
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
Example #3
0
def test_osx():
    """ Pretend that this is OS X. """

    o_platform = sys.platform
    o_app = dialite._the_app
    sys.platform = 'darwin'

    try:

        app = FakeOSXApp()
        # assert app.works()
        assert isinstance(app, OSXApp)
        dialite._the_app = app

        assert dialite.is_supported()

        dialite.inform()
        assert len(app._messages) == 1

        dialite.warn()
        assert len(app._messages) == 2

        dialite.fail()
        assert len(app._messages) == 3

        assert dialite.ask_ok()
        assert len(app._messages) == 4

        assert dialite.ask_retry()
        assert len(app._messages) == 5

        assert dialite.ask_yesno()
        assert len(app._messages) == 6

    finally:
        sys.platform = o_platform
        dialite._the_app = o_app
Example #4
0
def test_linux():
    """ Pretend that this is Linux. """

    o_platform = sys.platform
    o_app = dialite._the_app
    sys.platform = 'linux'

    try:

        app = FakeLinuxApp()
        # assert app.works()
        assert isinstance(app, LinuxApp)
        dialite._the_app = app

        assert dialite.is_supported()

        dialite.inform()
        assert len(app._messages) == 1 and 'info' in app._messages[-1]

        dialite.warn()
        assert len(app._messages) == 2 and 'warn' in app._messages[-1]

        dialite.fail()
        assert len(app._messages) == 3 and 'error' in app._messages[-1]

        assert dialite.ask_ok()
        assert len(app._messages) == 4 and 'question' in app._messages[-1]

        assert dialite.ask_retry()
        assert len(app._messages) == 5 and 'question' in app._messages[-1]

        assert dialite.ask_yesno()
        assert len(app._messages) == 6 and 'question' in app._messages[-1]

    finally:
        sys.platform = o_platform
        dialite._the_app = o_app