Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / build / android / pylib / instrumentation / instrumentation_test_instance_test.py
blob752e4d3d0e4fee769a2f70e9efc1fa7776eef76d
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
7 """Unit tests for instrumentation.TestRunner."""
9 # pylint: disable=W0212
11 import os
12 import sys
13 import unittest
15 from pylib import constants
16 from pylib.base import base_test_result
17 from pylib.instrumentation import instrumentation_test_instance
19 sys.path.append(os.path.join(
20 constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
21 import mock # pylint: disable=F0401
24 class InstrumentationTestInstanceTest(unittest.TestCase):
26 def setUp(self):
27 options = mock.Mock()
28 options.tool = ''
30 def testGenerateTestResults_noStatus(self):
31 results = instrumentation_test_instance.GenerateTestResults(
32 None, None, [], 0, 1000)
33 self.assertEqual([], results)
35 def testGenerateTestResults_testPassed(self):
36 statuses = [
37 (1, {
38 'class': 'test.package.TestClass',
39 'test': 'testMethod',
40 }),
41 (0, {
42 'class': 'test.package.TestClass',
43 'test': 'testMethod',
44 }),
46 results = instrumentation_test_instance.GenerateTestResults(
47 None, None, statuses, 0, 1000)
48 self.assertEqual(1, len(results))
49 self.assertEqual(base_test_result.ResultType.PASS, results[0].GetType())
51 def testGenerateTestResults_testSkipped_true(self):
52 statuses = [
53 (1, {
54 'class': 'test.package.TestClass',
55 'test': 'testMethod',
56 }),
57 (0, {
58 'test_skipped': 'true',
59 'class': 'test.package.TestClass',
60 'test': 'testMethod',
61 }),
62 (0, {
63 'class': 'test.package.TestClass',
64 'test': 'testMethod',
65 }),
67 results = instrumentation_test_instance.GenerateTestResults(
68 None, None, statuses, 0, 1000)
69 self.assertEqual(1, len(results))
70 self.assertEqual(base_test_result.ResultType.SKIP, results[0].GetType())
72 def testGenerateTestResults_testSkipped_false(self):
73 statuses = [
74 (1, {
75 'class': 'test.package.TestClass',
76 'test': 'testMethod',
77 }),
78 (0, {
79 'test_skipped': 'false',
80 }),
81 (0, {
82 'class': 'test.package.TestClass',
83 'test': 'testMethod',
84 }),
86 results = instrumentation_test_instance.GenerateTestResults(
87 None, None, statuses, 0, 1000)
88 self.assertEqual(1, len(results))
89 self.assertEqual(base_test_result.ResultType.PASS, results[0].GetType())
91 def testGenerateTestResults_testFailed(self):
92 statuses = [
93 (1, {
94 'class': 'test.package.TestClass',
95 'test': 'testMethod',
96 }),
97 (-2, {
98 'class': 'test.package.TestClass',
99 'test': 'testMethod',
102 results = instrumentation_test_instance.GenerateTestResults(
103 None, None, statuses, 0, 1000)
104 self.assertEqual(1, len(results))
105 self.assertEqual(base_test_result.ResultType.FAIL, results[0].GetType())
108 if __name__ == '__main__':
109 unittest.main(verbosity=2)