Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(679)

Side by Side Diff: build/android/pylib/instrumentation/instrumentation_test_instance_test.py

Issue 2743033002: [android] Add support for providing flags to instrumentation tests directly. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 'device_flags',
47 'device_flags_file',
48 'strict_mode',
49 'regenerate_goldens'
50 ])
51
52 def createFlagAttributesArgs(
53 self, device_flags=None, device_flags_file=None, strict_mode=None,
54 regenerate_goldens=None):
55 return self._FlagAttributesArgs(
56 device_flags, device_flags_file, strict_mode, regenerate_goldens)
57
58 def test_initializeFlagAttributes_oneDeviceFlag(self):
59 o = self.createTestInstance()
60 args = self.createFlagAttributesArgs(device_flags='--foo')
61 o._initializeFlagAttributes(args)
62 self.assertEquals(o._flags, ['--enable-test-intents', '--foo'])
63
64 def test_initializeFlagAttributes_multipleDeviceFlags(self):
65 o = self.createTestInstance()
66 args = self.createFlagAttributesArgs(device_flags='--foo --bar')
67 o._initializeFlagAttributes(args)
68 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar'])
69
70 def test_initializeFlagAttributes_deviceFlagsFile(self):
71 o = self.createTestInstance()
72 with tempfile.NamedTemporaryFile() as flags_file:
73 flags_file.write('\n'.join(['--foo', '--bar']))
74 flags_file.flush()
75
76 args = self.createFlagAttributesArgs(device_flags_file=flags_file.name)
77 o._initializeFlagAttributes(args)
78 self.assertEquals(o._flags, ['--enable-test-intents', '--foo', '--bar'])
79
80 def test_initializeFlagAttributes_strictModeOn(self):
81 o = self.createTestInstance()
82 args = self.createFlagAttributesArgs(strict_mode='on')
83 o._initializeFlagAttributes(args)
84 self.assertEquals(o._flags, ['--enable-test-intents', '--strict-mode=on'])
85
86 def test_initializeFlagAttributes_strictModeOff(self):
87 o = self.createTestInstance()
88 args = self.createFlagAttributesArgs(strict_mode='off')
89 o._initializeFlagAttributes(args)
90 self.assertEquals(o._flags, ['--enable-test-intents'])
91
92 def test_initializeFlagAttributes_regenerateGoldens(self):
93 o = self.createTestInstance()
94 args = self.createFlagAttributesArgs(regenerate_goldens=True)
95 o._initializeFlagAttributes(args)
96 self.assertEquals(
97 o._flags, ['--enable-test-intents', '--regenerate-goldens'])
98
41 def testGetTests_noFilter(self): 99 def testGetTests_noFilter(self):
42 o = self.createTestInstance() 100 o = self.createTestInstance()
43 raw_tests = [ 101 raw_tests = [
44 { 102 {
45 'annotations': {'Feature': {'value': ['Foo']}}, 103 'annotations': {'Feature': {'value': ['Foo']}},
46 'class': 'org.chromium.test.SampleTest', 104 'class': 'org.chromium.test.SampleTest',
47 'superclass': 'java.lang.Object', 105 'superclass': 'java.lang.Object',
48 'methods': [ 106 'methods': [
49 { 107 {
50 'annotations': {'SmallTest': None}, 108 'annotations': {'SmallTest': None},
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 }), 718 }),
661 ] 719 ]
662 results = instrumentation_test_instance.GenerateTestResults( 720 results = instrumentation_test_instance.GenerateTestResults(
663 None, None, statuses, 0, 1000) 721 None, None, statuses, 0, 1000)
664 self.assertEqual(1, len(results)) 722 self.assertEqual(1, len(results))
665 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType()) 723 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType())
666 724
667 725
668 if __name__ == '__main__': 726 if __name__ == '__main__':
669 unittest.main(verbosity=2) 727 unittest.main(verbosity=2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698