Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / examples / browser_tests / simple_numeric_test.py
blobe301a1b1fce44dc9c00bde6a1751dcbe087bc081
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import string
6 import sys
7 import time
9 from telemetry.testing import serially_executed_browser_test_case
12 _prev_test_name = None
14 class SimpleTest(
15 serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase):
17 @classmethod
18 def AddCommandlineArgs(cls, parser):
19 parser.add_option('--adder-sum', type=int, default=5)
21 def setUp(self):
22 self.extra = 5
24 @classmethod
25 def GenerateTestCases_AdderTest(cls, options):
26 yield 'add_1_and_2', (1, 2, options.adder_sum)
27 yield 'add_2_and_3', (2, 3, options.adder_sum)
28 yield 'add_7_and_3', (7, 3, options.adder_sum)
29 # Filtered out in browser_test_runner_unittest.py
30 yield 'dontrun_add_1_and_2', (1, 2, options.adder_sum)
32 @classmethod
33 def GenerateTestCases_AlphabeticalTest(cls, options):
34 del options # unused
35 prefix = 'Alphabetical_'
36 test_names = []
37 for character in string.lowercase[:26]:
38 test_names.append(prefix + character)
39 for character in string.uppercase[:26]:
40 test_names.append(prefix + character)
41 for num in xrange(20):
42 test_names.append(prefix + str(num))
44 # Shuffle |test_names| so the tests will be generated in a random order.
45 test_names = (test_names[25:40] + test_names[40:70] + test_names[:25] +
46 test_names[70:])
47 for t in test_names:
48 yield t, ()
50 def AlphabeticalTest(self):
51 test_name = self.id()
52 global _prev_test_name
53 self.assertLess(_prev_test_name, test_name)
54 _prev_test_name = test_name
56 def AdderTest(self, a, b, partial_sum):
57 self.assertEqual(a + b, partial_sum)
59 @classmethod
60 def GenerateTestCases_MultiplierTest(cls, options):
61 del options # unused
62 yield 'multiplier_simple', (10, 2, 4)
63 yield 'multiplier_simple_2', (2, 3, 5)
64 yield 'multiplier_simple_3', (10, 3, 6)
65 # Filtered out in browser_test_runner_unittest.py
66 yield 'dontrun_multiplier_simple', (10, 2, 4)
68 def MultiplierTest(self, a, b, partial_sum):
69 self.assertEqual(a * b, partial_sum * self.extra)
71 def TestSimple(self):
72 time.sleep(0.5)
73 self.assertEqual(1, self.extra)
75 def TestException(self):
76 raise Exception('Expected exception')
79 def load_tests(loader, tests, pattern):
80 del loader, tests, pattern # Unused.
81 return serially_executed_browser_test_case.LoadAllTestsInModule(
82 sys.modules[__name__])