Esempio n. 1
0
    def test_custom_timeout_can_be_set(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")
        element = Element(ElementConfig(name="my_element"), region)

        element.is_visible(timeout_seconds=15)

        retry_with_timeout.assert_called_with(mocker.ANY, 15, log=mocker.ANY)
Esempio n. 2
0
    def test_default_timeout_is_0(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")
        element = Element(ElementConfig(name="my_element"), region)

        element.is_visible()

        retry_with_timeout.assert_called_with(mocker.ANY, 0, log=mocker.ANY)
Esempio n. 3
0
    def test_mouse_is_moved_away_from_failsafe(self, mocker, region):
        Mouse = mocker.patch("clickshot.element.Mouse")
        position_mock = mocker.PropertyMock(return_value=(0, 0))
        type(Mouse()).position = position_mock

        Locater = mocker.patch("clickshot.element.Locater")
        Locater().locate.return_value = Rect(left=0, top=15, width=10, height=20)

        element = Element(ElementConfig(name="my_element"), region)

        element.is_visible(30)

        assert_that(position_mock.mock_calls, has_item(mock.call((10, 10))))
Esempio n. 4
0
    def test_returns_false_if_element_not_found(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")
        retry_with_timeout.side_effect = ElementNotFoundError()
        element = Element(ElementConfig(name="my_element"), region)

        result = element.is_visible()

        assert_that(result, is_(False))
Esempio n. 5
0
    def test_returns_true_if_element_is_found(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        Locater = mocker.patch("clickshot.element.Locater")
        Locater().locate.return_value = Rect(left=0, top=15, width=10, height=20)
        element = Element(ElementConfig(name="my_element"), region)

        result = element.is_visible()

        assert_that(result, is_(True))
        Locater().locate.assert_called_with(
            Path("images/my_region-my_element.png"), region._boundary
        )
Esempio n. 6
0
    def test_failsafe_aborts_is_visible_attempt(self, mocker, region):
        Mouse = mocker.patch("clickshot.element.Mouse")
        position_mock = mocker.PropertyMock(return_value=(0, 0))
        type(Mouse()).position = position_mock

        Locater = mocker.patch("clickshot.element.Locater")
        Locater().locate.side_effect = ElementNotFoundError()

        element = Element(ElementConfig(name="my_element"), region)

        with pytest.warns(UserWarning):
            result = element.is_visible(30)

        assert_that(result, is_(False))