1 #!/usr/bin/python2.4 2 # 3 # Copyright 2010, The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the 'License'); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an 'AS IS' BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 """Test cases for com.android.monkeyrunner.MonkeyRunner.""" 18 19 import time 20 import unittest 21 22 from com.android.monkeyrunner import MonkeyRunner 23 24 25 class TestMonkeyRunnerArgParsing(unittest.TestCase): 26 """Test ArgParsing for the MonkeyRunner methods.""" 27 def testWaitForConnectionNoArgs(self): 28 MonkeyRunner.waitForConnection() 29 30 def testWaitForConnectionSingleArg(self): 31 MonkeyRunner.waitForConnection(2) 32 33 def testWaitForConnectionDoubleArg(self): 34 MonkeyRunner.waitForConnection(2, '*') 35 36 def testWaitForConnectionKeywordArg(self): 37 MonkeyRunner.waitForConnection(timeout=2, deviceId='foo') 38 39 def testWaitForConnectionKeywordArgTooMany(self): 40 try: 41 MonkeyRunner.waitForConnection(timeout=2, deviceId='foo', extra='fail') 42 except TypeError: 43 return 44 self.fail('Should have raised TypeError') 45 46 def testSleep(self): 47 start = time.time() 48 MonkeyRunner.sleep(1.5) 49 end = time.time() 50 51 self.assertTrue(end - start >= 1.5) 52 53 if __name__ == '__main__': 54 unittest.main() 55