Example #1
0
def test_parse_display_dimensions():
    moto_x2_portrait = dedent("""\
        [...]
        WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
          Display: mDisplayId=0
            init=1080x1920 480dpi cur=1080x1920 app=1080x1776 rng=1080x1008-1794x1704
            deferred=false layoutNeeded=false
          [...]
        """)
    assert _parse_display_dimensions(moto_x2_portrait) == \
        _Dimensions(width=1080, height=1920)

    moto_x2_landscape = dedent("""\
        [...]
        WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
          Display: mDisplayId=0
            init=1080x1920 480dpi cur=1920x1080 app=1794x1080 rng=1080x1008-1794x1704
            deferred=false layoutNeeded=false
          [...]
        """)
    assert _parse_display_dimensions(moto_x2_landscape) == \
        _Dimensions(width=1920, height=1080)

    samsung_galaxy_ace_2 = dedent("""\
        [...]
        WINDOW MANAGER WINDOWS (dumpsys window windows)
          Window #4 Window{43073770 RecentsPanel paused=false}:
          [...]

          Display: init=480x800 cur=480x800 app=480x800 rng=480x442-800x762
          [...]
        """)
    assert _parse_display_dimensions(samsung_galaxy_ace_2) == \
        _Dimensions(width=480, height=800)
Example #2
0
def test_to_native_coordinates(orientation, device_resolution,
                               expected_coordinates, coordinate_system):

    description = "{source}-{orientation}".format(
        source=coordinate_system.name.lower().replace("_", "-"),
        orientation=orientation)
    screenshot = cv2.imread(
        _find_file("images/android-%s-screenshot.png" % description))
    icon = "images/android-%s-reference.png" % description

    m = match(icon, screenshot)
    screenshot_x, screenshot_y = _region_to_tuple(m.region)
    native_x, native_y = _to_native_coordinates(
        screenshot_x, screenshot_y, coordinate_system,
        _Dimensions(*device_resolution))
    print(native_x, native_y)
    assert isclose(native_x, expected_coordinates[0], absolute_tolerance=1)
    assert isclose(native_y, expected_coordinates[1], absolute_tolerance=1)
Example #3
0
def test_to_native_coordinates(
        orientation, device_resolution, expected_coordinates,
        coordinate_system):

    description = "{source}-{orientation}".format(
        source=coordinate_system.name.lower().replace("_", "-"),
        orientation=orientation)
    screenshot = cv2.imread(_find_file(
        "images/android/coordinates/%s-screenshot.png" % description))
    icon = "images/android/coordinates/%s-reference.png" % description

    m = match(icon, screenshot)
    screenshot_x, screenshot_y = _centre_point(m.region)
    native_x, native_y = _to_native_coordinates(
        screenshot_x, screenshot_y, coordinate_system,
        _Dimensions(*device_resolution))
    print(native_x, native_y)
    assert isclose(native_x, expected_coordinates[0], atol=1)
    assert isclose(native_y, expected_coordinates[1], atol=1)