| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 from devil import devil_env |
| 10 from devil.android import device_errors | 11 from devil.android import device_errors |
| 11 from devil.android import md5sum | 12 from devil.android import md5sum |
| 12 from pylib import constants | |
| 13 | 13 |
| 14 sys.path.append( | 14 sys.path.append(devil_env.config.LocalPath('pymock')) |
| 15 os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 'pymock')) | |
| 16 import mock # pylint: disable=import-error | 15 import mock # pylint: disable=import-error |
| 17 | 16 |
| 18 TEST_OUT_DIR = os.path.join('test', 'out', 'directory') | 17 TEST_OUT_DIR = os.path.join('test', 'out', 'directory') |
| 19 HOST_MD5_EXECUTABLE = os.path.join(TEST_OUT_DIR, 'md5sum_bin_host') | 18 HOST_MD5_EXECUTABLE = os.path.join(TEST_OUT_DIR, 'md5sum_bin_host') |
| 19 MD5_DIST = os.path.join(TEST_OUT_DIR, 'md5sum_dist') |
| 20 | 20 |
| 21 class Md5SumTest(unittest.TestCase): | 21 class Md5SumTest(unittest.TestCase): |
| 22 | 22 |
| 23 def setUp(self): | 23 def setUp(self): |
| 24 mocked_attrs = { |
| 25 'md5sum_host': HOST_MD5_EXECUTABLE, |
| 26 'md5sum_device': MD5_DIST, |
| 27 } |
| 24 self._patchers = [ | 28 self._patchers = [ |
| 25 mock.patch('pylib.constants.GetOutDirectory', | 29 mock.patch('devil.devil_env._Environment.FetchPath', |
| 26 new=mock.Mock(return_value=TEST_OUT_DIR)), | 30 mock.Mock(side_effect=lambda a, device=None: mocked_attrs[a])), |
| 27 mock.patch('os.path.exists', | 31 mock.patch('os.path.exists', |
| 28 new=mock.Mock(return_value=True)), | 32 new=mock.Mock(return_value=True)), |
| 29 ] | 33 ] |
| 30 for p in self._patchers: | 34 for p in self._patchers: |
| 31 p.start() | 35 p.start() |
| 32 | 36 |
| 33 def tearDown(self): | 37 def tearDown(self): |
| 34 for p in self._patchers: | 38 for p in self._patchers: |
| 35 p.stop() | 39 p.stop() |
| 36 | 40 |
| 37 def testCalculateHostMd5Sums_singlePath(self): | 41 def testCalculateHostMd5Sums_singlePath(self): |
| 38 test_path = '/test/host/file.dat' | 42 test_path = '/test/host/file.dat' |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' | 214 'WARNING: linker: /data/local/tmp/md5sum/md5sum_bin: ' |
| 211 'unused DT entry: type 0x1d arg 0x15db', | 215 'unused DT entry: type 0x1d arg 0x15db', |
| 212 'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text', | 216 'THIS_IS_NOT_A_VALID_CHECKSUM_ZZZ some random text', |
| 213 '0123456789abcdeffedcba9876543210 ' | 217 '0123456789abcdeffedcba9876543210 ' |
| 214 '/storage/emulated/legacy/test/file.dat', | 218 '/storage/emulated/legacy/test/file.dat', |
| 215 ] | 219 ] |
| 216 error = device_errors.AdbShellCommandFailedError('cmd', 'out', 2) | 220 error = device_errors.AdbShellCommandFailedError('cmd', 'out', 2) |
| 217 device.RunShellCommand = mock.Mock( | 221 device.RunShellCommand = mock.Mock( |
| 218 side_effect=(error, '', device_md5sum_output)) | 222 side_effect=(error, '', device_md5sum_output)) |
| 219 | 223 |
| 220 with mock.patch('os.path.getsize', return_value=1337): | 224 with mock.patch('os.path.isdir', return_value=True), ( |
| 225 mock.patch('os.path.getsize', return_value=1337)): |
| 221 out = md5sum.CalculateDeviceMd5Sums(test_path, device) | 226 out = md5sum.CalculateDeviceMd5Sums(test_path, device) |
| 222 self.assertEquals(1, len(out)) | 227 self.assertEquals(1, len(out)) |
| 223 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) | 228 self.assertTrue('/storage/emulated/legacy/test/file.dat' in out) |
| 224 self.assertEquals('0123456789abcdeffedcba9876543210', | 229 self.assertEquals('0123456789abcdeffedcba9876543210', |
| 225 out['/storage/emulated/legacy/test/file.dat']) | 230 out['/storage/emulated/legacy/test/file.dat']) |
| 226 self.assertEquals(3, len(device.RunShellCommand.call_args_list)) | 231 self.assertEquals(3, len(device.RunShellCommand.call_args_list)) |
| 227 device.adb.Push.assert_called_once_with( | 232 device.adb.Push.assert_called_once_with( |
| 228 'test/out/directory/md5sum_dist', '/data/local/tmp/md5sum') | 233 'test/out/directory/md5sum_dist', '/data/local/tmp/md5sum') |
| 229 | 234 |
| 230 | 235 |
| 231 if __name__ == '__main__': | 236 if __name__ == '__main__': |
| 232 unittest.main(verbosity=2) | 237 unittest.main(verbosity=2) |
| 233 | 238 |
| OLD | NEW |