def get_bottom_text_region(region):
    """Return the text area of a menu item"""
    text_region = Region(region.x + 8,
                         region.bottom - 45,
                         right=region.right - 6,
                         bottom=region.bottom - 5)
    return text_region
def get_default_image_region(region):
    """Return the text area of a menu item"""
    image_region = Region(region.x + 8,
                          region.y + 5,
                          right=region.right - 6,
                          bottom=region.bottom - 45)
    return image_region
Exemple #3
0
def getText(xx,yy,right1,bottom1):
    try:
       value=ocr(mode=OcrMode.PAGE_SEGMENTATION_WITHOUT_OSD,lang='eng',region=Region(x=xx, y=yy, right=right1, bottom=bottom1))
       return value
    except Exception,e:
        print  "Error While extracting the Text. Exception/  %s "%e.args
        raise e        
def test_grid():
    g = Grid(Region(0, 0, 6, 2), cols=6, rows=2)
    assert g.area == 12
    assert len(g) == 12

    def check_conversions(g, region, position, index):
        c = g.get(index=index)
        assert c.region == region
        assert c.position == position
        assert c.data is None
        assert c == g.get(region=region)
        assert c == g.get(position=position)
        assert c == g[index]
        assert c == g[position]
        assert c == g[region]

    check_conversions(g, Region(0, 0, 1, 1), (0, 0), 0)
    check_conversions(g, Region(5, 1, 1, 1), (5, 1), 11)
    check_conversions(g, Region(5, 1, 1, 1), Position(5, 1), 11)

    assert g.get(region=Region(4, 0, 3, 3)).position == (5, 1)
    for x, y in [(-1, 0), (0, -1), (6, 0), (0, 2), (6, 2)]:
        with raises(IndexError):
            g.get(region=Region(x, y, 1, 1))

    with raises(IndexError):
        g.get(index=12)
    with raises(IndexError):
        g.get(index=-13)
    with raises(IndexError):
        g.get(position=(6, 1))
    with raises(IndexError):
        g.get(data="J")

    g = Grid(Region(x=99, y=212, width=630, height=401), cols=5, rows=3)
    check_conversions(g, Region(351, 212, 126, 133), (2, 0), 2)
    check_conversions(g, Region(477, 345, 126, 134), (3, 1), 8)

    for r1, r2 in combinations(g.cells, 2):
        assert Region.intersect(r1.region, r2.region) is None

    for i, c in enumerate(g):
        assert i == c.index
Exemple #5
0
def test_grid_with_data():
    layout = ["ABCDEFG", "HIJKLMN", "OPQRSTU", "VWXYZ-'"]
    g = Grid(Region(0, 0, 100, 50), data=layout)
    assert g.cols == 7
    assert g.rows == 4
    assert g.get(index=9).data == "J"
    assert g.get(position=Position(x=2, y=1)).data == "J"
    assert g.get(data="J").index == 9
    assert g["J"].index == 9
    assert g[Position(x=2, y=1)].data == "J"
    assert g[2, 1].data == "J"
    assert g[-1].data == "'"
    for x in ["a", layout[0], layout]:
        with raises(IndexError):
            print(g[x])
Exemple #6
0
def test_grid():
    g = Grid(Region(0, 0, 6, 2), cols=6, rows=2)
    assert g.area == 12
    assert len(g) == 12

    def check_conversions(g, region, position, index):
        c = g.get(index=index)
        assert c.region == region
        assert c.position == position
        assert c.data is None
        assert c == g.get(region=region)
        assert c == g.get(position=position)
        assert c == g[index]
        assert c == g[position]
        assert c == g[region]

    check_conversions(g, Region(0, 0, 1, 1), (0, 0), 0)
    check_conversions(g, Region(5, 1, 1, 1), (5, 1), 11)
    check_conversions(g, Region(5, 1, 1, 1), Position(5, 1), 11)

    assert g.get(region=Region(4, 0, 3, 3)).position == (5, 1)
    for x, y in [(-1, 0), (0, -1), (6, 0), (0, 2), (6, 2)]:
        with raises(IndexError):
            g.get(region=Region(x, y, 1, 1))

    with raises(IndexError):
        g.get(index=12)
    with raises(IndexError):
        g.get(index=-13)
    with raises(IndexError):
        g.get(position=(6, 1))
    with raises(IndexError):
        g.get(data="J")

    g = Grid(Region(x=99, y=212, width=630, height=401), cols=5, rows=3)
    check_conversions(g, Region(351, 212, 126, 133), (2, 0), 2)
    check_conversions(g, Region(477, 345, 126, 134), (3, 1), 8)

    # If you use a region from a different source (e.g. stbt.match) then the
    # region you get *back* from the Grid should be the region defined by the
    # grid.
    r = Region(x=99, y=212, width=126, height=133)
    assert r == g.get(region=r.extend(right=5, bottom=5)).region

    for r1, r2 in combinations(g.cells, 2):
        assert Region.intersect(r1.region, r2.region) is None

    for i, c in enumerate(g):
        assert i == c.index
Exemple #7
0
from textwrap import dedent
from unittest import SkipTest

import cv2
import pytest
from numpy import isclose

from stbt import match, Region, wait_until
from stbt.android import (_centre_point, _Dimensions,
                          _parse_display_dimensions, _resize,
                          _to_native_coordinates, AdbDevice, AdbError,
                          CoordinateSystem)


@pytest.mark.parametrize("r", [
    Region(10, 10, width=30, height=5),
    (25, 12),
    ("25", "12"),
])
def test_centre_point(r):
    assert _centre_point(r) == (25, 12)


@pytest.mark.parametrize("r", [
    25,
    (25,),
    (25, 12, 15),
    "25",
])
def test_centre_point_raises(r):
    with pytest.raises(TypeError):
Exemple #8
0
import interactive_constants
import sky_plus_strings
from mysky_test_utils import get_bottom_text_region, get_default_image_region

# ##################### #
# ##### Constants ##### #
# ##################### #

INTERACTIVE_SKY_LOGO = 'images/InteractiveSkyLogo.png'
MM_PIN_ENTRY = 'images/PinEntry.png'
MA_BACKGROUND = 'images/MyAccountBackground.png'

# Colors:
YELLOW_BACKGROUND_RGB = np.array([235, 189, 0])

TITLE_REGION = Region(45, 30, width=170, height=45)

MAIN_MENU_ITEM_REGIONS = [
    Region(100, 338, width=530, height=32),
    Region(100, 374, width=530, height=32),
    Region(100, 410, width=530, height=32),
    Region(100, 446, width=530, height=32),
    Region(100, 482, width=530, height=32),
    Region(100, 518, width=530, height=32),
    Region(100, 554, width=530, height=32),
    Region(100, 590, width=530, height=32),
    Region(647, 338, width=530, height=32)
]

# My Messages Regions:
MM_TITLE_REGION = Region(90, 60, width=180, height=40)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test cases for MySky
"""

from time import sleep
import stbt
from stbt import Region, wait_for_match
import cv2
import interactive_constants
import interactive_test_utils as itu

TRIGGER_REGION = Region(931, 42, width=244, height=35)
TRIGGER_IMAGE = 'images/Trigger.png'


def test_smoke_trigger_open():
    """Open MySky app"""
    itu.clear_test()
    try:
        itu.go_to_channel(interactive_constants.CHANNEL_SKY_ONE_HD)
        match_result = wait_for_match(TRIGGER_IMAGE,
                                      timeout_secs=15,
                                      region=TRIGGER_REGION)
        assert match_result.match, '[Trigger] Could not find trigger icon'
        stbt.press('KEY_GREEN')
        sleep(5)
        for i in range(10):
            frame = stbt.get_frame()
            # Save image for testing manually later
from sky_plus_utils import debug, IMAGE_DEBUG_MODE
import mysky_constants
from mysky_constants import MY_SKY_OPEN_TIMEOUT
import mysky_test_utils
import interactive_constants
import interactive_test_utils as itu
import sky_plus_strings
from interactive_frame_objects import ImageMenuItem, InteractiveFrameObject

# ##################### #
# ##### Constants ##### #
# ##################### #

# MySky constants:
MY_SKY_REGION = Region(
    880, 0, width=400, height=720
)  # The 400 pixels to the right and the whole height of the screen
MAIN_MENU_LOADING_REGION = Region(1015, 280, width=140, height=50)
MAIN_MENU_REGIONS = [
    Region(930, 95, width=300, height=150),
    Region(930, 255, width=300, height=130),
    Region(930, 395, width=300, height=130),
    Region(930, 535, width=300, height=130)
]

# Secret Scene constants:
SECRET_SCENE_TITLE_REGION = Region(970, 120, width=230, height=40)
SS_MAIN_REGIONS = [
    Region(940, 425, width=280, height=40),
    Region(940, 475, width=280, height=40)
]
Exemple #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Contants for MySky testing
"""

from stbt import Region

# Misc:
MY_SKY_OPEN_TIMEOUT = 25

# Regions:
TRAFFIC_LIGHTS_REGION = Region(29, 21, width=20, height=33)

# Images:
SKY_TOP_LOGO = 'images/SkyTopLogo.png'
MENU_MANAGE_YOUR_ACCOUNT = 'images/ManageYourAccount.png'
MENU_FIX_A_PROBLEM = 'images/FixAProblem.png'
TL_RED = 'images/TL_Red.png'
TL_YELLOW = 'images/TL_Yellow.png'
TL_GREEN = 'images/TL_Green.png'