Permalink
Browse files

bug 715215 - install robocop.apk; r=bear

  • Loading branch information...
1 parent 90fb37e commit 03d76dcdfcc3ae71f6cda175f0d1cc56fbcc4813 @hwine hwine committed Jan 23, 2012
Showing with 57 additions and 45 deletions.
  1. +25 −22 sut_tools/installApp.py
  2. +32 −23 sut_tools/test_installApp.py
View
@@ -57,7 +57,7 @@ def find_robocop():
extracted_location = 'build/tests/bin/robocop.apk'
self_extracted_location = 'build/robocop.apk'
actual_location = None
-
+
# for better error reporting
global proxyFile, errorFile
@@ -69,25 +69,26 @@ def find_robocop():
else:
expected_zip_location = 'build/fennec*tests.zip'
matches = glob.glob(expected_zip_location)
- if len(matches) != 1:
- setFlag(errorFile, "Can't find just one %s; found '%s'" % (expected_zip_location,
- str(matches)))
- sys.exit(1)
+ if len(matches) == 1:
+ # try to grab the file we need from there, giving up if any
+ # assumption doesn't match
+ try:
+ archive = zipfile.ZipFile(matches[0], 'r')
+ apk_info = archive.getinfo('bin/robocop.apk')
+ # it's in the archive, extract to tmp dir - will be created
+ archive.extract(apk_info, 'build/tmp')
+ shutil.move('build/tmp/bin/robocop.apk', self_extracted_location)
+ actual_location = self_extracted_location
+ # got it
+ except Exception as e:
+ print "WARNING (robocop): zip file not as expected: %s (%s)" % (e.message,
+ str(e.args))
+ print "WARNING (robocop): robocop.apk will not be installed"
+ else:
+ print "WARNING (robocop): Didn't find just one %s; found '%s'" % (expected_zip_location,
+ str(matches))
+ print "WARNING (robocop): will continue using first listed above (if any)"
- # try to grab the file we need from there, giving up if any
- # assumption doesn't match
- try:
- archive = zipfile.ZipFile(matches[0], 'r')
- apk_info = archive.getinfo('bin/robocop.apk')
- # it's in the archive, extract to tmp dir - will be created
- archive.extract(apk_info, 'build/tmp')
- shutil.move('build/tmp/bin/robocop.apk', self_extracted_location)
- actual_location = self_extracted_location
- # got it
- except BaseException as e:
- setFlag(errorFile, "zip file not as exected: %s (%s)" % (e.message,
- str(e.args)))
- sys.exit(1)
return actual_location
def one_time_setup(ip_addr, major_source):
@@ -173,9 +174,11 @@ def main(argv):
path_to_main_apk = argv[2]
dm, devRoot = one_time_setup(ip_addr, path_to_main_apk)
installOneApp(dm, devRoot, path_to_main_apk)
- # also install robocop, after first finishes
- waitForDevice(dm)
- installOneApp(dm, devRoot, find_robocop())
+ # also install robocop if it's available
+ robocop_to_use = find_robocop()
+ if robocop_to_use is not None:
+ waitForDevice(dm)
+ installOneApp(dm, devRoot, robocop_to_use)
# make sure we're all the way back up before we finish
waitForDevice(dm)
@@ -53,6 +53,8 @@ def make_fake_module(name):
import installApp
class InstallAppTestCase(unittest.TestCase):
def setUp(self):
+ # every test should reset the counts
+ the_mock.reset_mock()
# we want to ensure a "success" from the installApp method
the_mock.installApp.return_value = None
# don't exercise find code by default
@@ -88,9 +90,6 @@ def test_three_args_okay(self):
class CheckArguementHandling(InstallAppTestCase):
# N.B. the 3rd arguement to installApp.py is never used, so can
# not be tested
- def setUp(self):
- super(CheckArguementHandling, self).setUp()
- the_mock.reset_mock()
def testIPAddress(self):
for ip in ('hostname', '255.255.255.255'):
@@ -124,11 +123,8 @@ def XXXtestOneSetOfCalls(self):
the_mock.installApp.assert_called_once_with(installed_path)
class CheckNewContract(InstallAppTestCase):
- def setUp(self):
- super(CheckNewContract, self).setUp()
- the_mock.reset_mock()
- def testOneSetOfNewCalls(self):
+ def test_robocop_found(self):
root_path = sut_lib.checkDeviceRoot.return_value
source_file = 'fennec.eggs.arm.apk'
robocop_file = 'robocop.apk'
@@ -148,27 +144,40 @@ def testOneSetOfNewCalls(self):
self.assertEqual(the_mock.pushFile.call_args_list,
expected_pushFile_calls)
-class CheckRobocopFind(InstallAppTestCase):
+ def test_robocop_not_found(self):
+ root_path = sut_lib.checkDeviceRoot.return_value
+ source_file = 'fennec.eggs.arm.apk'
+ robocop_file = 'robocop.apk'
+ source_path = os.path.join('build/', source_file)
+ robocop_source_path = os.path.join('build/tests/bin', robocop_file)
+ installed_path = os.path.join(root_path, source_file)
+ robocop_installed_path = os.path.join(root_path, robocop_file)
+ expected_pushFile_calls = [((source_path, installed_path), {}),]
+ expected_installApp_calls = [((installed_path,), {}),]
- def setUp(self):
- super(CheckRobocopFind, self).setUp()
- self.saved_return_value = os.path.exists.return_value
+ # simulate not finding robocop.apk - should not attempt install
+ # then
+ os.path.exists.return_value = False
+ installApp.main(['app', 1, source_path])
- def tearDown(self):
- os.path.exists.return_value = self.saved_return_value
- super(CheckRobocopFind, self).tearDown()
+ self.assertEqual(the_mock.installApp.call_args_list,
+ expected_installApp_calls)
+ self.assertEqual(the_mock.pushFile.call_args_list,
+ expected_pushFile_calls)
- def call_expecting_sysexit(self):
- try:
- installApp.main(['app',1,'fred'])
- except SystemExit as e:
- self.assertEqual(1, e.code)
- else:
- self.fail('should have thrown SystemExit')
+class CheckRobocopFind(InstallAppTestCase):
- def test_exit_if_not_found(self):
+ def test_null_path_if_not_found(self):
os.path.exists.return_value = False
- self.call_expecting_sysexit()
+ found_path = installApp.find_robocop()
+ self.assertFalse(found_path,
+ "Should not have found robocop.apk")
+
+ def test_correct_path_if_found(self):
+ os.path.exists.return_value = True
+ found_path = installApp.find_robocop()
+ self.assertTrue(found_path,
+ "Should have found robocop.apk")
if __name__ == '__main__':
unittest.main()

0 comments on commit 03d76dc

Please sign in to comment.