示例#1
0
    def test_bad(self):
        int32_max = 2 ** 31 - 1

        with pytest.raises(cmdexc.CommandError) as excinfo:
            cmdutils.check_overflow(int32_max + 1, "int")

        expected_str = "Numeric argument is too large for internal int " "representation."

        assert str(excinfo.value) == expected_str
示例#2
0
    def test_bad(self):
        int32_max = 2**31 - 1

        with pytest.raises(cmdexc.CommandError) as excinfo:
            cmdutils.check_overflow(int32_max + 1, 'int')

        expected_str = ("Numeric argument is too large for internal int "
                        "representation.")

        assert str(excinfo.value) == expected_str
示例#3
0
    def scroll(self, dx: {'type': float}, dy: {'type': float}, count=1):
        """Scroll the current tab by 'count * dx/dy'.

        Args:
            dx: How much to scroll in x-direction.
            dy: How much to scroll in x-direction.
            count: multiplier
        """
        dx *= count
        dy *= count
        cmdutils.check_overflow(dx, 'int')
        cmdutils.check_overflow(dy, 'int')
        self._current_widget().page().currentFrame().scroll(dx, dy)
示例#4
0
    def scroll(self, dx: {'type': float}, dy: {'type': float}, count=1):
        """Scroll the current tab by 'count * dx/dy'.

        Args:
            dx: How much to scroll in x-direction.
            dy: How much to scroll in x-direction.
            count: multiplier
        """
        dx *= count
        dy *= count
        cmdutils.check_overflow(dx, 'int')
        cmdutils.check_overflow(dy, 'int')
        self._current_widget().page().currentFrame().scroll(dx, dy)
示例#5
0
    def scroll_page(self, x: {'type': float}, y: {'type': float}, count=1):
        """Scroll the frame page-wise.

        Args:
            x: How many pages to scroll to the right.
            y: How many pages to scroll down.
            count: multiplier
        """
        frame = self._current_widget().page().currentFrame()
        size = frame.geometry()
        dx = count * x * size.width()
        dy = count * y * size.height()
        cmdutils.check_overflow(dx, 'int')
        cmdutils.check_overflow(dy, 'int')
        frame.scroll(dx, dy)
示例#6
0
    def scroll_page(self, x: {'type': float}, y: {'type': float}, count=1):
        """Scroll the frame page-wise.

        Args:
            x: How many pages to scroll to the right.
            y: How many pages to scroll down.
            count: multiplier
        """
        frame = self._current_widget().page().currentFrame()
        size = frame.geometry()
        dx = count * x * size.width()
        dy = count * y * size.height()
        cmdutils.check_overflow(dx, 'int')
        cmdutils.check_overflow(dy, 'int')
        frame.scroll(dx, dy)
示例#7
0
    def _cntwidget(self, count=None):
        """Return a widget based on a count/idx.

        Args:
            count: The tab index, or None.

        Return:
            The current widget if count is None.
            The widget with the given tab ID if count is given.
            None if no widget was found.
        """
        tabbed_browser = self._tabbed_browser()
        if count is None:
            return tabbed_browser.currentWidget()
        elif 1 <= count <= self._count():
            cmdutils.check_overflow(count + 1, 'int')
            return tabbed_browser.widget(count - 1)
        else:
            return None
示例#8
0
    def _cntwidget(self, count=None):
        """Return a widget based on a count/idx.

        Args:
            count: The tab index, or None.

        Return:
            The current widget if count is None.
            The widget with the given tab ID if count is given.
            None if no widget was found.
        """
        tabbed_browser = self._tabbed_browser()
        if count is None:
            return tabbed_browser.currentWidget()
        elif 1 <= count <= self._count():
            cmdutils.check_overflow(count + 1, 'int')
            return tabbed_browser.widget(count - 1)
        else:
            return None
示例#9
0
    def tab_move(self,
                 direction: {'type': ('+', '-')} = None,
                 count: {'special': 'count'} = None):
        """Move the current tab.

        Args:
            direction: `+` or `-` for relative moving, not given for absolute
                       moving.
            count: If moving absolutely: New position (default: 0)
                   If moving relatively: Offset.
        """
        if direction is None:
            new_idx = self._tab_move_absolute(count)
        elif direction in '+-':
            try:
                new_idx = self._tab_move_relative(direction, count)
            except ValueError:
                raise cmdexc.CommandError("Count must be given for relative "
                                          "moving!")
        else:
            raise cmdexc.CommandError(
                "Invalid direction '{}'!".format(direction))
        if not 0 <= new_idx < self._count():
            raise cmdexc.CommandError(
                "Can't move tab to position {}!".format(new_idx))
        tabbed_browser = self._tabbed_browser()
        tab = self._current_widget()
        cur_idx = self._current_index()
        icon = tabbed_browser.tabIcon(cur_idx)
        label = tabbed_browser.tabText(cur_idx)
        cmdutils.check_overflow(cur_idx, 'int')
        cmdutils.check_overflow(new_idx, 'int')
        tabbed_browser.setUpdatesEnabled(False)
        try:
            tabbed_browser.removeTab(cur_idx)
            tabbed_browser.insertTab(new_idx, tab, icon, label)
            self._set_current_index(new_idx)
        finally:
            tabbed_browser.setUpdatesEnabled(True)
示例#10
0
    def tab_focus(self, index: {'type': (int, 'last')}=None, count=None):
        """Select the tab given as argument/[count].

        Args:
            index: The tab index to focus, starting with 1. The special value
                   `last` focuses the last focused tab.
            count: The tab index to focus, starting with 1.
        """
        if index == 'last':
            self._tab_focus_last()
            return
        try:
            idx = cmdutils.arg_or_count(index, count, default=1,
                                        countzero=self._count())
        except ValueError as e:
            raise cmdexc.CommandError(e)
        cmdutils.check_overflow(idx + 1, 'int')
        if 1 <= idx <= self._count():
            self._set_current_index(idx - 1)
        else:
            raise cmdexc.CommandError("There's no tab with index {}!".format(
                idx))
示例#11
0
    def tab_move(self, direction: {'type': ('+', '-')}=None,
                 count: {'special': 'count'}=None):
        """Move the current tab.

        Args:
            direction: `+` or `-` for relative moving, not given for absolute
                       moving.
            count: If moving absolutely: New position (default: 0)
                   If moving relatively: Offset.
        """
        if direction is None:
            new_idx = self._tab_move_absolute(count)
        elif direction in '+-':
            try:
                new_idx = self._tab_move_relative(direction, count)
            except ValueError:
                raise cmdexc.CommandError("Count must be given for relative "
                                          "moving!")
        else:
            raise cmdexc.CommandError("Invalid direction '{}'!".format(
                direction))
        if not 0 <= new_idx < self._count():
            raise cmdexc.CommandError("Can't move tab to position {}!".format(
                new_idx))
        tabbed_browser = self._tabbed_browser()
        tab = self._current_widget()
        cur_idx = self._current_index()
        icon = tabbed_browser.tabIcon(cur_idx)
        label = tabbed_browser.tabText(cur_idx)
        cmdutils.check_overflow(cur_idx, 'int')
        cmdutils.check_overflow(new_idx, 'int')
        tabbed_browser.setUpdatesEnabled(False)
        try:
            tabbed_browser.removeTab(cur_idx)
            tabbed_browser.insertTab(new_idx, tab, icon, label)
            self._set_current_index(new_idx)
        finally:
            tabbed_browser.setUpdatesEnabled(True)
示例#12
0
    def tab_focus(self, index: {'type': (int, 'last')}=None,
                  count: {'special': 'count'}=None):
        """Select the tab given as argument/[count].

        Args:
            index: The tab index to focus, starting with 1. The special value
                   `last` focuses the last focused tab.
            count: The tab index to focus, starting with 1.
        """
        if index == 'last':
            self._tab_focus_last()
            return
        try:
            idx = cmdutils.arg_or_count(index, count, default=1,
                                        countzero=self._count())
        except ValueError as e:
            raise cmdexc.CommandError(e)
        cmdutils.check_overflow(idx + 1, 'int')
        if 1 <= idx <= self._count():
            self._set_current_index(idx - 1)
        else:
            raise cmdexc.CommandError("There's no tab with index {}!".format(
                idx))
示例#13
0
    def test_bad(self):
        int32_max = 2 ** 31 - 1

        with pytest.raises(cmdexc.CommandError, match="Numeric argument is "
                           "too large for internal int representation."):
            cmdutils.check_overflow(int32_max + 1, 'int')
示例#14
0
 def test_good(self):
     cmdutils.check_overflow(1, 'int')