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 | 10 import collections |
(...skipping 28 matching lines...) Expand all Loading... |
39 mock.patch('%s._initializeTestCoverageAttributes' % c)): | 39 mock.patch('%s._initializeTestCoverageAttributes' % c)): |
40 return instrumentation_test_instance.InstrumentationTestInstance( | 40 return instrumentation_test_instance.InstrumentationTestInstance( |
41 mock.MagicMock(), mock.MagicMock(), lambda s: None) | 41 mock.MagicMock(), mock.MagicMock(), lambda s: None) |
42 | 42 |
43 _FlagAttributesArgs = collections.namedtuple( | 43 _FlagAttributesArgs = collections.namedtuple( |
44 '_FlagAttributesArgs', | 44 '_FlagAttributesArgs', |
45 [ | 45 [ |
46 'command_line_flags', | 46 'command_line_flags', |
47 'device_flags_file', | 47 'device_flags_file', |
48 'strict_mode', | 48 'strict_mode', |
49 'regenerate_goldens', | |
50 ]) | 49 ]) |
51 | 50 |
52 def createFlagAttributesArgs( | 51 def createFlagAttributesArgs( |
53 self, command_line_flags=None, device_flags_file=None, | 52 self, command_line_flags=None, device_flags_file=None, |
54 strict_mode=None, regenerate_goldens=None): | 53 strict_mode=None): |
55 return self._FlagAttributesArgs( | 54 return self._FlagAttributesArgs( |
56 command_line_flags, device_flags_file, strict_mode, | 55 command_line_flags, device_flags_file, strict_mode) |
57 regenerate_goldens) | |
58 | 56 |
59 def test_initializeFlagAttributes_commandLineFlags(self): | 57 def test_initializeFlagAttributes_commandLineFlags(self): |
60 o = self.createTestInstance() | 58 o = self.createTestInstance() |
61 args = self.createFlagAttributesArgs(command_line_flags=['--foo', '--bar']) | 59 args = self.createFlagAttributesArgs(command_line_flags=['--foo', '--bar']) |
62 o._initializeFlagAttributes(args) | 60 o._initializeFlagAttributes(args) |
63 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar']) | 61 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar']) |
64 | 62 |
65 def test_initializeFlagAttributes_deviceFlagsFile(self): | 63 def test_initializeFlagAttributes_deviceFlagsFile(self): |
66 o = self.createTestInstance() | 64 o = self.createTestInstance() |
67 with tempfile.NamedTemporaryFile() as flags_file: | 65 with tempfile.NamedTemporaryFile() as flags_file: |
68 flags_file.write('\n'.join(['--foo', '--bar'])) | 66 flags_file.write('\n'.join(['--foo', '--bar'])) |
69 flags_file.flush() | 67 flags_file.flush() |
70 | 68 |
71 args = self.createFlagAttributesArgs(device_flags_file=flags_file.name) | 69 args = self.createFlagAttributesArgs(device_flags_file=flags_file.name) |
72 o._initializeFlagAttributes(args) | 70 o._initializeFlagAttributes(args) |
73 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar']) | 71 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar']) |
74 | 72 |
75 def test_initializeFlagAttributes_strictModeOn(self): | 73 def test_initializeFlagAttributes_strictModeOn(self): |
76 o = self.createTestInstance() | 74 o = self.createTestInstance() |
77 args = self.createFlagAttributesArgs(strict_mode='on') | 75 args = self.createFlagAttributesArgs(strict_mode='on') |
78 o._initializeFlagAttributes(args) | 76 o._initializeFlagAttributes(args) |
79 self.assertEquals(o._flags, ['--enable-test-intents', '--strict-mode=on']) | 77 self.assertEquals(o._flags, ['--enable-test-intents', '--strict-mode=on']) |
80 | 78 |
81 def test_initializeFlagAttributes_strictModeOff(self): | 79 def test_initializeFlagAttributes_strictModeOff(self): |
82 o = self.createTestInstance() | 80 o = self.createTestInstance() |
83 args = self.createFlagAttributesArgs(strict_mode='off') | 81 args = self.createFlagAttributesArgs(strict_mode='off') |
84 o._initializeFlagAttributes(args) | 82 o._initializeFlagAttributes(args) |
85 self.assertEquals(o._flags, ['--enable-test-intents']) | 83 self.assertEquals(o._flags, ['--enable-test-intents']) |
86 | 84 |
87 def test_initializeFlagAttributes_regenerateGoldens(self): | |
88 o = self.createTestInstance() | |
89 args = self.createFlagAttributesArgs(regenerate_goldens=True) | |
90 o._initializeFlagAttributes(args) | |
91 self.assertEquals( | |
92 o._flags, ['--enable-test-intents', '--regenerate-goldens']) | |
93 | |
94 def testGetTests_noFilter(self): | 85 def testGetTests_noFilter(self): |
95 o = self.createTestInstance() | 86 o = self.createTestInstance() |
96 raw_tests = [ | 87 raw_tests = [ |
97 { | 88 { |
98 'annotations': {'Feature': {'value': ['Foo']}}, | 89 'annotations': {'Feature': {'value': ['Foo']}}, |
99 'class': 'org.chromium.test.SampleTest', | 90 'class': 'org.chromium.test.SampleTest', |
100 'superclass': 'java.lang.Object', | 91 'superclass': 'java.lang.Object', |
101 'methods': [ | 92 'methods': [ |
102 { | 93 { |
103 'annotations': {'SmallTest': None}, | 94 'annotations': {'SmallTest': None}, |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 }), | 704 }), |
714 ] | 705 ] |
715 results = instrumentation_test_instance.GenerateTestResults( | 706 results = instrumentation_test_instance.GenerateTestResults( |
716 None, None, statuses, 0, 1000) | 707 None, None, statuses, 0, 1000) |
717 self.assertEqual(1, len(results)) | 708 self.assertEqual(1, len(results)) |
718 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType()) | 709 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType()) |
719 | 710 |
720 | 711 |
721 if __name__ == '__main__': | 712 if __name__ == '__main__': |
722 unittest.main(verbosity=2) | 713 unittest.main(verbosity=2) |
OLD | NEW |