def test_get_frame_press_tap_and_swipe(real_adb_device):  # pylint:disable=redefined-outer-name
    adb = real_adb_device

    def match_any(basename):
        f = adb.get_frame()
        return (match("images/android/galaxy-ace-2/" + basename, f)
                or match("images/android/moto-x2/" + basename, f))

    adb.press("KEYCODE_HOME")
    m = wait_until(lambda: match_any("app-icon.png"))
    assert m
    adb.tap(m.region)
    assert wait_until(lambda: match_any("app.png"))
    adb.swipe((240, 0), (240, 600))
    assert wait_until(lambda: match_any("settings-icon.png"))
Beispiel #2
0
def test_that_wait_until_returns_first_stable_value(mock_time):
    def MR(match, x):
        time.sleep(1)  # advance the mock time by 1 second
        return stbt.MatchResult(time.time(),
                                match,
                                stbt.Region(x=x, y=0, width=10, height=2),
                                first_pass_result=1,
                                frame=numpy.random.randint(
                                    0, 255, (2, 2, 3)).astype(numpy.uint8),
                                image="reference.png")

    def g():
        yield MR(False, x=1)
        yield MR(True, x=2)
        yield MR(True, x=3)
        yield MR(True, x=4)
        yield MR(True, x=4)
        yield MR(True, x=4)
        yield MR(True, x=4)
        yield MR(True, x=4)

    results = g()

    def match():
        return next(results)

    result = wait_until(match,
                        predicate=lambda x: x and x.region,
                        stable_secs=2)
    assert result.match
    assert result.region.x == 4
    assert result.time == 1497000004
Beispiel #3
0
def test_that_wait_until_doesnt_compare_return_values(mock_time):
    class MR(object):
        def __init__(self, eq_allowed=False):
            time.sleep(1)  # advance the mock time by 1 second
            self.eq_allowed = eq_allowed

        def __eq__(self, other):
            if self.eq_allowed:
                return isinstance(other, MR)
            else:
                assert False, "Got unexpected call to MR.__eq__"

        def __ne__(self, other):
            return not self.__eq__(other)

    result = wait_until(MR)
    assert isinstance(result, MR)

    # But it does compare values if you specify `stable_secs`
    with pytest.raises(AssertionError):
        result = wait_until(MR, stable_secs=2)
def lircd():
    with named_temporary_directory("stbt-lirc-test") as tmpdir:
        socket = os.path.join(tmpdir, "lircd.socket")
        logfile = os.path.join(tmpdir, "lircd.log")
        proc = subprocess.Popen([
            "lircd",
            "--nodaemon",
            "--loglevel=info",
            "--logfile=/dev/stderr",
            "--driver=file",
            "--device",
            logfile,  # lircd output
            "--output",
            socket,  # lircd reads instructions from here
            "--pidfile=%s/lircd.pid" % tmpdir,
            _find_file("Apple_TV.lircd.conf")
        ])
        wait_until(lambda: (os.path.exists(socket) or proc.poll() is not None))

        with scoped_process(proc):
            yield namedtuple("Lircd", "socket logfile")(socket, logfile)
Beispiel #5
0
def test_that_wait_until_times_out(mock_time):
    assert not wait_until(Zero, interval_secs=1)
    assert time.time() == 1497000010
Beispiel #6
0
def test_wait_until(mock_time, f, kwargs, expected):
    assert wait_until(f, **kwargs) == expected