Example #1
0
def test_run():
    """
    Ensure the run function sets things up in the expected way.

    Why check this?

    We need to know if something fundamental has inadvertently changed and
    these tests highlight such a case.

    Testing the call_count and mock_calls allows us to measure the expected
    number of instantiations and method calls.
    """
    with mock.patch('mu.app.setup_logging') as set_log, \
            mock.patch('mu.app.QApplication') as qa, \
            mock.patch('mu.app.QSplashScreen') as qsp, \
            mock.patch('mu.app.Editor') as ed, \
            mock.patch('mu.app.load_pixmap'), \
            mock.patch('mu.app.Window') as win, \
            mock.patch('sys.exit') as ex:
        run()
        assert set_log.call_count == 1
        # foo.call_count is instantiating the class
        assert qa.call_count == 1
        # foo.mock_calls are method calls on the object
        assert len(qa.mock_calls) == 2
        assert qsp.call_count == 1
        assert len(qsp.mock_calls) == 3
        assert ed.call_count == 1
        assert len(ed.mock_calls) == 2
        assert win.call_count == 1
        assert len(win.mock_calls) == 14
        assert ex.call_count == 1
Example #2
0
def test_run():
    """
    Ensure the run function sets things up in the expected way.

    Why check this?

    We need to know if something fundamental has inadvertently changed and
    these tests highlight such a case.

    Testing the call_count and mock_calls allows us to measure the expected
    number of instantiations and method calls.
    """
    with mock.patch('mu.app.setup_logging') as set_log, \
            mock.patch('mu.app.QApplication') as qa, \
            mock.patch('mu.app.QSplashScreen') as qsp, \
            mock.patch('mu.app.Editor') as ed, \
            mock.patch('mu.app.load_pixmap'), \
            mock.patch('mu.app.Window') as win, \
            mock.patch('mu.app.QTimer') as timer, \
            mock.patch('sys.exit') as ex:
        run()
        assert set_log.call_count == 1
        # foo.call_count is instantiating the class
        assert qa.call_count == 1
        # foo.mock_calls are method calls on the object
        assert len(qa.mock_calls) == 2
        assert qsp.call_count == 1
        assert len(qsp.mock_calls) == 2
        assert timer.call_count == 1
        assert len(timer.mock_calls) == 4
        assert ed.call_count == 1
        assert len(ed.mock_calls) == 3
        assert win.call_count == 1
        assert len(win.mock_calls) == 5
        assert ex.call_count == 1
Example #3
0
def test_run():
    """
    Ensure the run function sets things up in the expected way.

    Why check this?

    We need to know if something fundamental has inadvertently changed and
    these tests highlight such a case.

    Testing the call_count and mock_calls allows us to measure the expected
    number of instantiations and method calls.
    """
    class DumSig:
        def __init__(self):
            @self.connect
            def default(*args):
                raise Exception('No signal handler connected')

        def connect(self, func):
            self.func = func
            return func

        def emit(self, *args):
            self.func(*args)

    class Win(mock.MagicMock):
        load_theme = DumSig()

    window = Win()

    with mock.patch('mu.app.setup_logging') as set_log, \
            mock.patch('mu.app.QApplication') as qa, \
            mock.patch('mu.app.QSplashScreen') as qsp, \
            mock.patch('mu.app.Editor') as ed, \
            mock.patch('mu.app.load_pixmap'), \
            mock.patch('mu.app.Window', window) as win, \
            mock.patch('mu.app.QTimer') as timer, \
            mock.patch('sys.argv', ['mu']), \
            mock.patch('sys.exit') as ex:
        run()
        assert set_log.call_count == 1
        # foo.call_count is instantiating the class
        assert qa.call_count == 1
        # foo.mock_calls are method calls on the object
        assert len(qa.mock_calls) == 8
        assert qsp.call_count == 1
        assert len(qsp.mock_calls) == 2
        assert timer.call_count == 1
        assert len(timer.mock_calls) == 4
        assert ed.call_count == 1
        assert len(ed.mock_calls) == 3
        assert win.call_count == 1
        assert len(win.mock_calls) == 11
        assert ex.call_count == 1
        window.load_theme.emit('day')
        qa.assert_has_calls([mock.call().setStyleSheet(DAY_STYLE)])
        window.load_theme.emit('night')
        qa.assert_has_calls([mock.call().setStyleSheet(NIGHT_STYLE)])
        window.load_theme.emit('contrast')
        qa.assert_has_calls([mock.call().setStyleSheet(CONTRAST_STYLE)])
Example #4
0
def test_run():
    """
    Ensure the run function sets things up in the expected way.

    Why check this?

    We need to know if something fundamental has inadvertently changed and
    these tests highlight such a case.

    Testing the call_count and mock_calls allows us to measure the expected
    number of instantiations and method calls.
    """
    class DumSig:
        def __init__(self):
            @self.connect
            def default(*args):
                raise Exception('No signal handler connected')

        def connect(self, func):
            self.func = func
            return func

        def emit(self, *args):
            self.func(*args)

    class Win(mock.MagicMock):
        load_theme = DumSig()

    window = Win()

    with mock.patch('mu.app.setup_logging') as set_log, \
            mock.patch('mu.app.QApplication') as qa, \
            mock.patch('mu.app.QSplashScreen') as qsp, \
            mock.patch('mu.app.Editor') as ed, \
            mock.patch('mu.app.load_pixmap'), \
            mock.patch('mu.app.Window', window) as win, \
            mock.patch('mu.app.QTimer') as timer, \
            mock.patch('sys.argv', ['mu']), \
            mock.patch('sys.exit') as ex:
        run()
        assert set_log.call_count == 1
        # foo.call_count is instantiating the class
        assert qa.call_count == 1
        # foo.mock_calls are method calls on the object
        assert len(qa.mock_calls) == 8
        assert qsp.call_count == 1
        assert len(qsp.mock_calls) == 2
        assert timer.call_count == 1
        assert len(timer.mock_calls) == 4
        assert ed.call_count == 1
        assert len(ed.mock_calls) == 3
        assert win.call_count == 1
        assert len(win.mock_calls) == 11
        assert ex.call_count == 1
        window.load_theme.emit('day')
        qa.assert_has_calls([mock.call().setStyleSheet(DAY_STYLE)])
        window.load_theme.emit('night')
        qa.assert_has_calls([mock.call().setStyleSheet(NIGHT_STYLE)])
        window.load_theme.emit('contrast')
        qa.assert_has_calls([mock.call().setStyleSheet(CONTRAST_STYLE)])
Example #5
0
def test_run():
    """
    Ensure the run function sets things up in the expected way.

    Why check this?

    We need to know if something fundamental has inadvertently changed and
    these tests highlight such a case.

    Testing the call_count and mock_calls allows us to measure the expected
    number of instantiations and method calls.
    """

    class Win(mock.MagicMock):
        load_theme = DumSig()
        icon = "icon"

    window = Win()

    with mock.patch("mu.app.setup_logging") as set_log, mock.patch(
        "mu.app.QApplication"
    ) as qa, mock.patch("mu.app.AnimatedSplash") as qsp, mock.patch(
        "mu.app.Editor"
    ) as ed, mock.patch(
        "mu.app.load_movie"
    ), mock.patch(
        "mu.app.Window", window
    ) as win, mock.patch(
        "sys.argv", ["mu"]
    ), mock.patch(
        "sys.exit"
    ) as ex, mock.patch.object(
        VE, "ensure_and_create"
    ) as mock_ensure_and_create:
        run()
        assert set_log.call_count == 1
        # foo.call_count is instantiating the class
        assert qa.call_count == 1
        # foo.mock_calls are method calls on the object
        if hasattr(Qt, "AA_EnableHighDpiScaling"):
            assert len(qa.mock_calls) == 10
        else:
            assert len(qa.mock_calls) == 9
        assert qsp.call_count == 1
        assert len(qsp.mock_calls) == 3
        assert ed.call_count == 1
        assert len(ed.mock_calls) == 4
        assert win.call_count == 1
        assert len(win.mock_calls) == 6
        assert ex.call_count == 1
        assert mock_ensure_and_create.call_count == 1
        window.load_theme.emit("day")
        qa.assert_has_calls([mock.call().setStyleSheet(DAY_STYLE)])
        window.load_theme.emit("night")
        qa.assert_has_calls([mock.call().setStyleSheet(NIGHT_STYLE)])
        window.load_theme.emit("contrast")
        qa.assert_has_calls([mock.call().setStyleSheet(CONTRAST_STYLE)])
Example #6
0
def test_run(qtapp):
    """
    Ensure the run function sets things up in the expected way.

    Why check this?

    We need to know if something fundamental has inadvertently changed and
    these tests highlight such a case.

    Testing the call_count and mock_calls allows us to measure the expected
    number of instantiations and method calls.
    """
    class Win(mock.MagicMock):
        load_theme = DumSig()
        icon = "icon"

    window = Win()

    with mock.patch("mu.app.setup_logging") as set_log, mock.patch(
            "mu.app.QApplication"
    ) as qa, mock.patch("mu.app.QSplashScreen") as qsp, mock.patch(
            "mu.app.Editor"
    ) as ed, mock.patch("mu.app.load_pixmap"), mock.patch(
            "mu.app.Window",
            window) as win, mock.patch("mu.app.QTimer") as timer, mock.patch(
                "sys.argv", ["mu"]), mock.patch("sys.exit") as ex:
        run()
        assert set_log.call_count == 1
        # foo.call_count is instantiating the class
        assert qa.call_count == 1
        # foo.mock_calls are method calls on the object
        assert len(qa.mock_calls) == 8
        assert qsp.call_count == 1
        assert len(qsp.mock_calls) == 2
        assert timer.call_count == 1
        assert len(timer.mock_calls) == 4
        assert ed.call_count == 1
        assert len(ed.mock_calls) == 4
        assert win.call_count == 1
        assert len(win.mock_calls) == 5
        assert ex.call_count == 1
        window.load_theme.emit("day")
        qa.assert_has_calls([mock.call().setStyleSheet(DAY_STYLE)])
        window.load_theme.emit("night")
        qa.assert_has_calls([mock.call().setStyleSheet(NIGHT_STYLE)])
        window.load_theme.emit("contrast")
        qa.assert_has_calls([mock.call().setStyleSheet(CONTRAST_STYLE)])
Example #7
0
def test_close_splash_screen():
    """
    Test that the splash screen is closed.
    """

    # Create a dummy window
    class Win(mock.MagicMock):
        load_theme = DumSig()
        icon = "icon"

    window = Win()

    # Create a dummy timer class
    class DummyTimer:
        def __init__(self):
            self.callback = lambda x: None
            self.stop = lambda: None
            self.setSingleShot = lambda x: None

            def set_callback(fun):
                self.callback = fun

            class Object(object):
                pass

            self.timeout = Object()
            self.timeout.connect = set_callback

        def start(self, t):
            # Just call the callback immediately
            self.callback()

    # Mock Splash screen
    splash = mock.MagicMock()

    # Mock QTimer, QApplication, Window, Editor, sys.exit
    with mock.patch("mu.app.Window", window), mock.patch(
        "mu.app.QApplication"
    ), mock.patch("sys.exit"), mock.patch("mu.app.Editor"), mock.patch(
        "mu.app.AnimatedSplash", return_value=splash
    ), mock.patch.object(
        VE, "ensure_and_create"
    ):
        run()
        assert splash.finish.call_count == 1
Example #8
0
File: run.py Project: muou55555/mu
#!/usr/bin/env python
from mu.app import run


if __name__ == "__main__":
    run()
Example #9
0
#!/usr/bin/env python3
from mu.app import run

if __name__ == "__main__":
    run()
Example #10
0
def main():
    run()