Esempio n. 1
0
    def test_raise(self):
        """If there's a Firefox window open but it's not focused,
        `flitter firefox` should focus the Firefox window.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        focused_window = wmctrl.Window('1', '0', 'pid',
                                       'Navigator.Thunderbird', 'mistakenot',
                                       'My Thunderbird Window')
        firefox_window = wmctrl.Window('2', '0', 'pid', 'Navigator.Firefox',
                                       'mistakenot', 'My Firefox Window')
        windows = [
            firefox_window,
            focused_window,
            wmctrl.Window('1', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  focused_window, focus_window_function)

        assert not run_function.called
        focus_window_function.assert_called_once_with(firefox_window)
Esempio n. 2
0
    def test_with_no_matching_windows(self):
        """`flitter firefox` should run `firefox` if no firefox windows.

        If there are no open windows that match the given window spec, it
        should run the window spec's command.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        focused_window = wmctrl.Window('2', '0', 'pid',
                                       'Navigator.Thunderbird', 'mistakenot',
                                       'My Thunderbird Window')
        windows = [
            wmctrl.Window('1', '0', 'pid', 'Navigator.Gvim', 'mistakenot',
                          'My GVim Window'),
            focused_window,
            wmctrl.Window('2', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  focused_window, focus_window_function)

        run_function.assert_called_once_with('firefox')
        assert not focus_window_function.called
Esempio n. 3
0
    def test_with_command_only(self):
        """`flitter -c firefox` should run the `firefox` command.

        If just a command is given and no window spec or alias, it should just
        run that command.

        """
        run_function = mock.MagicMock()
        focused_window = wmctrl.Window('2', '0', 'pid',
                                       'Navigator.Thunderbird', 'mistakenot',
                                       'My Thunderbird Window')
        windows = [
            wmctrl.Window('1', '0', 'pid', 'Navigator.Firefox', 'mistakenot',
                          'My Firefox Window'),
            focused_window,
            wmctrl.Window('2', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext({'command': 'firefox'}, run_function,
                                  windows, focused_window,
                                  focus_window_function)

        run_function.assert_called_once_with('firefox')
        assert not focus_window_function.called
Esempio n. 4
0
    def test_with_command_only(self):
        """`flitter -c firefox` should run the `firefox` command.

        If just a command is given and no window spec or alias, it should just
        run that command.

        """
        run_function = mock.MagicMock()
        focused_window = wmctrl.Window('2', '0', 'pid',
                                       'Navigator.Thunderbird', 'mistakenot',
                                       'My Thunderbird Window')
        windows = [
            wmctrl.Window('1', '0', 'pid', 'Navigator.Firefox', 'mistakenot',
                          'My Firefox Window'),
            focused_window,
            wmctrl.Window('2', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext({'command': 'firefox'}, run_function,
                                  windows, focused_window,
                                  focus_window_function)

        run_function.assert_called_once_with('firefox')
        assert not focus_window_function.called
Esempio n. 5
0
    def test_with_no_matching_windows(self):
        """`flitter firefox` should run `firefox` if no firefox windows.

        If there are no open windows that match the given window spec, it
        should run the window spec's command.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        focused_window = wmctrl.Window('2', '0', 'pid',
                                       'Navigator.Thunderbird', 'mistakenot',
                                       'My Thunderbird Window')
        windows = [
            wmctrl.Window('1', '0', 'pid', 'Navigator.Gvim', 'mistakenot',
                          'My GVim Window'),
            focused_window,
            wmctrl.Window('2', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  focused_window, focus_window_function)

        run_function.assert_called_once_with('firefox')
        assert not focus_window_function.called
Esempio n. 6
0
    def test_go_to_other_window(self):
        """Test moving from a known to an "other" window with --others."""
        known_window_1 = wmctrl.Window(
            "1", "0", "pid", "Navigator.Thunderbird", "mistakenot",
            "Thunderbird")
        known_window_2 = wmctrl.Window(
            "2", "0", "pid", "Navigator.Firefox", "mistakenot", "Firefox")
        other_window = wmctrl.Window(
            "3", "0", "pid",
            "org.gnome.Weather.Application.Org.gnome.Weather.Application",
            "mistakenot", "Weather")
        known_window_3 = wmctrl.Window(
            "4", "0", "pid", "Terminal.Terminal", "mistakenot", "Terminal")

        window_specs = [
            dict(wm_class=".Thunderbird"),
            dict(wm_class=".Firefox"),
            dict(wm_class=".Terminal"),
        ]

        run_function = mock.MagicMock()
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(
            window_spec={},
            run_function=run_function,
            open_windows=[known_window_1, known_window_2, other_window,
                          known_window_3],
            focused_window=known_window_1,
            focus_window_function=focus_window_function,
            others=True,
            window_specs=window_specs)

        assert not run_function.called
        focus_window_function.assert_called_once_with(other_window)
Esempio n. 7
0
    def test_looping(self):
        """If there are multiple Firefox windows open and one of them is
        focused, `flitter firefox` should focus the next Firefox windows.

        Repeated calls should loop through all the Firefox windows, going back
        to the first one after the last one.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        firefox_window_1 = wmctrl.Window('2', '0', 'pid', 'Navigator.Firefox',
                                         'mistakenot', 'My Firefox Window')
        firefox_window_2 = wmctrl.Window('3', '0', 'pid', 'Navigator.Firefox',
                                         'mistakenot',
                                         'My Other Firefox Window')
        windows = [
            firefox_window_1,
            firefox_window_2,
            wmctrl.Window('4', '0', 'pid', 'Navigator.Thunderbird',
                          'mistakenot', 'My Thunderbird Window'),
            wmctrl.Window('5', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  firefox_window_1, focus_window_function)

        assert not run_function.called
        focus_window_function.assert_called_once_with(firefox_window_2)
Esempio n. 8
0
    def test_raise(self):
        """If there's a Firefox window open but it's not focused,
        `flitter firefox` should focus the Firefox window.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        focused_window = wmctrl.Window('1', '0', 'pid',
                                       'Navigator.Thunderbird', 'mistakenot',
                                       'My Thunderbird Window')
        firefox_window = wmctrl.Window('2', '0', 'pid', 'Navigator.Firefox',
                                       'mistakenot', 'My Firefox Window')
        windows = [
            firefox_window,
            focused_window,
            wmctrl.Window('1', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  focused_window, focus_window_function)

        assert not run_function.called
        focus_window_function.assert_called_once_with(firefox_window)
Esempio n. 9
0
    def test_looping(self):
        """If there are multiple Firefox windows open and one of them is
        focused, `flitter firefox` should focus the next Firefox windows.

        Repeated calls should loop through all the Firefox windows, going back
        to the first one after the last one.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        firefox_window_1 = wmctrl.Window('2', '0', 'pid', 'Navigator.Firefox',
                                         'mistakenot', 'My Firefox Window')
        firefox_window_2 = wmctrl.Window('3', '0', 'pid', 'Navigator.Firefox',
                                         'mistakenot',
                                         'My Other Firefox Window')
        windows = [
            firefox_window_1,
            firefox_window_2,
            wmctrl.Window('4', '0', 'pid', 'Navigator.Thunderbird',
                          'mistakenot', 'My Thunderbird Window'),
            wmctrl.Window('5', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  firefox_window_1, focus_window_function)

        assert not run_function.called
        focus_window_function.assert_called_once_with(firefox_window_2)
Esempio n. 10
0
 def request_window(wm_class, focused_window, expected_window):
     run_function = mock.MagicMock()
     focus_window_function = mock.MagicMock()
     runraisenext.runraisenext(
         window_spec={"wm_class": wm_class},
         run_function=run_function, open_windows=windows,
         focused_window=focused_window,
         focus_window_function=focus_window_function)
     assert not run_function.called
     focus_window_function.assert_called_once_with(expected_window)
     return expected_window
Esempio n. 11
0
 def request_window(wm_class, focused_window, expected_window):
     run_function = mock.MagicMock()
     focus_window_function = mock.MagicMock()
     runraisenext.runraisenext(
         window_spec={"wm_class": wm_class},
         run_function=run_function,
         open_windows=windows,
         focused_window=focused_window,
         focus_window_function=focus_window_function)
     assert not run_function.called
     focus_window_function.assert_called_once_with(expected_window)
     return expected_window
Esempio n. 12
0
    def test_with_no_open_windows(self):
        """`flitter firefox` should run `firefox` if no open windows.

        If there are no open windows it should just run the command associated
        with the given window spec.

        """
        run_function = mock.MagicMock()
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext({'command': 'firefox'}, run_function, [],
                                  None, focus_window_function)

        run_function.assert_called_once_with('firefox')
        assert not focus_window_function.called
Esempio n. 13
0
    def test_with_no_open_windows(self):
        """`flitter firefox` should run `firefox` if no open windows.

        If there are no open windows it should just run the command associated
        with the given window spec.

        """
        run_function = mock.MagicMock()
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext({'command': 'firefox'}, run_function, [],
                                  None, focus_window_function)

        run_function.assert_called_once_with('firefox')
        assert not focus_window_function.called
Esempio n. 14
0
        def request_other(focused_window, expected_window):
            """Do `flitter --others`.

            And assert that the expected_window was raised.

            """
            focus_window_function = mock.MagicMock()
            runraisenext.runraisenext(
                window_spec={},
                run_function=run_function,
                open_windows=windows,
                focused_window=focused_window,
                focus_window_function=focus_window_function,
                others=True, ignore=ignore,
                window_specs=window_specs)
            assert not run_function.called
            focus_window_function.assert_called_once_with(expected_window)
            return expected_window
Esempio n. 15
0
        def request_other(focused_window, expected_window):
            """Do `flitter --others`.

            And assert that the expected_window was raised.

            """
            focus_window_function = mock.MagicMock()
            runraisenext.runraisenext(
                window_spec={},
                run_function=run_function,
                open_windows=windows,
                focused_window=focused_window,
                focus_window_function=focus_window_function,
                others=True,
                window_specs=window_specs)
            assert not run_function.called
            focus_window_function.assert_called_once_with(expected_window)
            return expected_window
Esempio n. 16
0
    def test_already_raised(self):
        """If there's one Firefox window open and it's already focused,
        `flitter firefox` should do nothing.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        firefox_window = wmctrl.Window('2', '0', 'pid', 'Navigator.Firefox',
                                       'mistakenot', 'My Firefox Window')
        windows = [
            firefox_window,
            wmctrl.Window('2', '0', 'pid', 'Navigator.Thunderbird',
                          'mistakenot', 'My Thunderbird Window'),
            wmctrl.Window('1', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  firefox_window, focus_window_function)

        assert not run_function.called
        assert not focus_window_function.called
Esempio n. 17
0
    def test_already_raised(self):
        """If there's one Firefox window open and it's already focused,
        `flitter firefox` should do nothing.

        """
        window_spec = {"command": "firefox", "wm_class": ".Firefox"}
        run_function = mock.MagicMock()
        firefox_window = wmctrl.Window('2', '0', 'pid', 'Navigator.Firefox',
                                       'mistakenot', 'My Firefox Window')
        windows = [
            firefox_window,
            wmctrl.Window('2', '0', 'pid', 'Navigator.Thunderbird',
                          'mistakenot', 'My Thunderbird Window'),
            wmctrl.Window('1', '0', 'pid', 'Terminal.Terminal', 'mistakenot',
                          'My Terminal Window'),
        ]
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec, run_function, windows,
                                  firefox_window, focus_window_function)

        assert not run_function.called
        assert not focus_window_function.called
Esempio n. 18
0
    def test_go_to_other_window(self):
        """Test moving from a known to an "other" window with --others."""
        known_window_1 = wmctrl.Window("1", "0", "pid",
                                       "Navigator.Thunderbird", "mistakenot",
                                       "Thunderbird")
        known_window_2 = wmctrl.Window("2", "0", "pid", "Navigator.Firefox",
                                       "mistakenot", "Firefox")
        other_window = wmctrl.Window(
            "3", "0", "pid",
            "org.gnome.Weather.Application.Org.gnome.Weather.Application",
            "mistakenot", "Weather")
        known_window_3 = wmctrl.Window("4", "0", "pid", "Terminal.Terminal",
                                       "mistakenot", "Terminal")

        window_specs = [
            dict(wm_class=".Thunderbird"),
            dict(wm_class=".Firefox"),
            dict(wm_class=".Terminal"),
        ]

        run_function = mock.MagicMock()
        focus_window_function = mock.MagicMock()

        runraisenext.runraisenext(window_spec={},
                                  run_function=run_function,
                                  open_windows=[
                                      known_window_1, known_window_2,
                                      other_window, known_window_3
                                  ],
                                  focused_window=known_window_1,
                                  focus_window_function=focus_window_function,
                                  others=True,
                                  window_specs=window_specs)

        assert not run_function.called
        focus_window_function.assert_called_once_with(other_window)