<s> from PIL import Image <EOL> import random <EOL> import sys <EOL> import os <EOL> import time <EOL> import cStringIO <EOL> try : <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . join ( os . environ [ '<STR_LIT>' ] , '<STR_LIT:src>' ) ) <EOL> except : <EOL> pass <EOL> from com . dtmilano . android . viewclient import ViewClient <EOL> from com . dtmilano . android . uiautomator . uiautomatorhelper import UiAutomatorHelper <EOL> __author__ = '<STR_LIT>' <EOL> import unittest <EOL> DEBUG = False <EOL> class UiAutomatorHelperTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> if DEBUG : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> ( self . device , self . serialno ) = ViewClient . connectToDeviceOrExit ( serialno = '<STR_LIT>' ) <EOL> self . assertIsNotNone ( self . device ) <EOL> self . uiAutomatorHelper = UiAutomatorHelper ( self . device ) <EOL> def tearDown ( self ) : <EOL> if DEBUG : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> self . uiAutomatorHelper . quit ( ) <EOL> def testDumpWindowHierarchy ( self ) : <EOL> dump = self . uiAutomatorHelper . dumpWindowHierarchy ( ) <EOL> self . assertIsNotNone ( dump ) <EOL> def testDumpWindowHierarchy_repeat ( self ) : <EOL> for _ in range ( <NUM_LIT:10> ) : <EOL> dump = self . uiAutomatorHelper . dumpWindowHierarchy ( ) <EOL> self . assertIsNotNone ( dump ) <EOL> def testPressKeyCode ( self ) : <EOL> response = self . uiAutomatorHelper . pressKeyCode ( <NUM_LIT:4> ) <EOL> '''<STR_LIT>''' <EOL> if DEBUG : <EOL> print >> sys . stderr , "<STR_LIT>" , response <EOL> def testTakeScreenshot ( self ) : <EOL> buf = self . uiAutomatorHelper . takeScreenshot ( ) <EOL> self . assertIsNotNone ( buf ) <EOL> self . assertTrue ( len ( buf ) > <NUM_LIT:0> ) <EOL> image = Image . open ( cStringIO . StringIO ( buf ) ) <EOL> self . assertIsNotNone ( image ) <EOL> self . assertEqual ( image . format , '<STR_LIT>' ) <EOL> def testClick_random ( self ) : <EOL> x = random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> y = random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> response = self . uiAutomatorHelper . click ( x = x , y = y ) <EOL> if DEBUG : <EOL> print >> sys . stderr , "<STR_LIT>" , response <EOL> def testSwipe_random ( self ) : <EOL> x0 = random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> y0 = random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> x1 = random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> y1 = random . randint ( <NUM_LIT:0> , <NUM_LIT:1000> ) <EOL> steps = random . randint ( <NUM_LIT:10> , <NUM_LIT:100> ) <EOL> response = self . uiAutomatorHelper . swipe ( startX = x0 , startY = y0 , endX = x1 , endY = y1 , steps = steps ) <EOL> if DEBUG : <EOL> print >> sys . stderr , "<STR_LIT>" , response <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
