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 """Unit tests for instrumentation_test_instance.""" | 6 """Unit tests for instrumentation_test_instance.""" |
7 | 7 |
8 # pylint: disable=protected-access | 8 # pylint: disable=protected-access |
9 | 9 |
| 10 import collections |
| 11 import tempfile |
10 import unittest | 12 import unittest |
11 | 13 |
12 from pylib.base import base_test_result | 14 from pylib.base import base_test_result |
13 from pylib.constants import host_paths | 15 from pylib.constants import host_paths |
14 from pylib.instrumentation import instrumentation_test_instance | 16 from pylib.instrumentation import instrumentation_test_instance |
15 | 17 |
16 with host_paths.SysPath(host_paths.PYMOCK_PATH): | 18 with host_paths.SysPath(host_paths.PYMOCK_PATH): |
17 import mock # pylint: disable=import-error | 19 import mock # pylint: disable=import-error |
18 | 20 |
19 _INSTRUMENTATION_TEST_INSTANCE_PATH = ( | 21 _INSTRUMENTATION_TEST_INSTANCE_PATH = ( |
(...skipping 11 matching lines...) Expand all Loading... |
31 with mock.patch('%s._initializeApkAttributes' % c), ( | 33 with mock.patch('%s._initializeApkAttributes' % c), ( |
32 mock.patch('%s._initializeDataDependencyAttributes' % c)), ( | 34 mock.patch('%s._initializeDataDependencyAttributes' % c)), ( |
33 mock.patch('%s._initializeTestFilterAttributes' % c)), ( | 35 mock.patch('%s._initializeTestFilterAttributes' % c)), ( |
34 mock.patch('%s._initializeFlagAttributes' % c)), ( | 36 mock.patch('%s._initializeFlagAttributes' % c)), ( |
35 mock.patch('%s._initializeDriverAttributes' % c)), ( | 37 mock.patch('%s._initializeDriverAttributes' % c)), ( |
36 mock.patch('%s._initializeTestControlAttributes' % c)), ( | 38 mock.patch('%s._initializeTestControlAttributes' % c)), ( |
37 mock.patch('%s._initializeTestCoverageAttributes' % c)): | 39 mock.patch('%s._initializeTestCoverageAttributes' % c)): |
38 return instrumentation_test_instance.InstrumentationTestInstance( | 40 return instrumentation_test_instance.InstrumentationTestInstance( |
39 mock.MagicMock(), mock.MagicMock(), lambda s: None) | 41 mock.MagicMock(), mock.MagicMock(), lambda s: None) |
40 | 42 |
| 43 _FlagAttributesArgs = collections.namedtuple( |
| 44 '_FlagAttributesArgs', |
| 45 [ |
| 46 'command_line_flags', |
| 47 'device_flags_file', |
| 48 'strict_mode', |
| 49 'regenerate_goldens', |
| 50 'test_arguments', |
| 51 ]) |
| 52 |
| 53 def createFlagAttributesArgs( |
| 54 self, command_line_flags=None, device_flags_file=None, |
| 55 strict_mode=None, regenerate_goldens=None, test_arguments=None): |
| 56 return self._FlagAttributesArgs( |
| 57 command_line_flags, device_flags_file, strict_mode, |
| 58 regenerate_goldens, test_arguments) |
| 59 |
| 60 def test_initializeFlagAttributes_commandLineFlags(self): |
| 61 o = self.createTestInstance() |
| 62 args = self.createFlagAttributesArgs(command_line_flags=['--foo', '--bar']) |
| 63 o._initializeFlagAttributes(args) |
| 64 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar']) |
| 65 |
| 66 def test_initializeFlagAttributes_deviceFlagsFile(self): |
| 67 o = self.createTestInstance() |
| 68 with tempfile.NamedTemporaryFile() as flags_file: |
| 69 flags_file.write('\n'.join(['--foo', '--bar'])) |
| 70 flags_file.flush() |
| 71 |
| 72 args = self.createFlagAttributesArgs(device_flags_file=flags_file.name) |
| 73 o._initializeFlagAttributes(args) |
| 74 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar']) |
| 75 |
| 76 def test_initializeFlagAttributes_strictModeOn(self): |
| 77 o = self.createTestInstance() |
| 78 args = self.createFlagAttributesArgs(strict_mode='on') |
| 79 o._initializeFlagAttributes(args) |
| 80 self.assertEquals(o._flags, ['--enable-test-intents', '--strict-mode=on']) |
| 81 |
| 82 def test_initializeFlagAttributes_strictModeOff(self): |
| 83 o = self.createTestInstance() |
| 84 args = self.createFlagAttributesArgs(strict_mode='off') |
| 85 o._initializeFlagAttributes(args) |
| 86 self.assertEquals(o._flags, ['--enable-test-intents']) |
| 87 |
| 88 def test_initializeFlagAttributes_regenerateGoldens(self): |
| 89 o = self.createTestInstance() |
| 90 args = self.createFlagAttributesArgs(regenerate_goldens=True) |
| 91 o._initializeFlagAttributes(args) |
| 92 self.assertEquals( |
| 93 o._flags, ['--enable-test-intents', '--regenerate-goldens']) |
| 94 |
| 95 def test_initializeFlagAttributes_testArgumentsRaisesException(self): |
| 96 o = self.createTestInstance() |
| 97 args = self.createFlagAttributesArgs(test_arguments='--foo --bar') |
| 98 with self.assertRaises(Exception): |
| 99 o._initializeFlagAttributes(args) |
| 100 |
41 def testGetTests_noFilter(self): | 101 def testGetTests_noFilter(self): |
42 o = self.createTestInstance() | 102 o = self.createTestInstance() |
43 raw_tests = [ | 103 raw_tests = [ |
44 { | 104 { |
45 'annotations': {'Feature': {'value': ['Foo']}}, | 105 'annotations': {'Feature': {'value': ['Foo']}}, |
46 'class': 'org.chromium.test.SampleTest', | 106 'class': 'org.chromium.test.SampleTest', |
47 'superclass': 'java.lang.Object', | 107 'superclass': 'java.lang.Object', |
48 'methods': [ | 108 'methods': [ |
49 { | 109 { |
50 'annotations': {'SmallTest': None}, | 110 'annotations': {'SmallTest': None}, |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 }), | 720 }), |
661 ] | 721 ] |
662 results = instrumentation_test_instance.GenerateTestResults( | 722 results = instrumentation_test_instance.GenerateTestResults( |
663 None, None, statuses, 0, 1000) | 723 None, None, statuses, 0, 1000) |
664 self.assertEqual(1, len(results)) | 724 self.assertEqual(1, len(results)) |
665 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType()) | 725 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType()) |
666 | 726 |
667 | 727 |
668 if __name__ == '__main__': | 728 if __name__ == '__main__': |
669 unittest.main(verbosity=2) | 729 unittest.main(verbosity=2) |
OLD | NEW |