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

Side by Side Diff: scripts/slave/unittests/get_swarm_results_test.py

Issue 10035003: Split up Each Swarm Test into Two Steps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Renaming broken test :( Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 import os 6 import test_env # pylint: disable=W0403,W0611
7 import sys 7
8 import StringIO
8 import unittest 9 import unittest
9 10
10 HERE = os.path.dirname(os.path.abspath(__file__)) 11 from testing_support.super_mox import mox
11 sys.path.insert(0, os.path.join(HERE, '..', '..', 'site_config')) 12 from testing_support.super_mox import SuperMoxTestBase
12 sys.path.insert(0, os.path.join(HERE, '..'))
13 sys.path.insert(0, HERE)
14 13
15 import slave.run_slavelastic as slavelastic 14 import slave.get_swarm_results as swarm_results
16 15
17 16
18 class TestSummaryTest(unittest.TestCase): 17 class TestRunSummaryTest(unittest.TestCase):
19 def test_correct_output(self): 18 def test_correct_output(self):
20 summary_output = [ 19 summary_output = [
21 ('[ PASSED ] 10 tests.\n' 20 ('[ PASSED ] 10 tests.\n'
22 'YOU HAVE 1 DISABLED TESTS\n' 21 'YOU HAVE 1 DISABLED TESTS\n'
23 'YOU HAVE 1 test with ignored failures (FAILS prefix)'), 22 'YOU HAVE 1 test with ignored failures (FAILS prefix)'),
24 ('[ PASSED ] 10 tests\n' 23 ('[ PASSED ] 10 tests\n'
25 '[ FAILED ] 1 test, listed below:\n' 24 '[ FAILED ] 1 test, listed below:\n'
26 '[ FAILED ] ObserverListThreadSafeTest.RemoveObserver\n' 25 '[ FAILED ] ObserverListThreadSafeTest.RemoveObserver\n'
27 '1 FAILED TEST\n' 26 '1 FAILED TEST\n'
28 'YOU HAVE 2 DISABLED TESTS\n' 27 'YOU HAVE 2 DISABLED TESTS\n'
29 'YOU HAVE 2 test with ignored failures (FAILS prefix)\n')] 28 'YOU HAVE 2 test with ignored failures (FAILS prefix)\n')]
30 29
31 expected_output = ['[ PASSED ] 20 tests.', 30 expected_output = ['[ PASSED ] 20 tests.',
32 '[ FAILED ] failed tests listed below:', 31 '[ FAILED ] failed tests listed below:',
33 '[ FAILED ] ObserverListThreadSafeTest.RemoveObserver', 32 '[ FAILED ] ObserverListThreadSafeTest.RemoveObserver',
34 '1 FAILED TESTS', 33 '1 FAILED TESTS',
35 '3 DISABLED TESTS', 34 '3 DISABLED TESTS',
36 '3 tests with ignored failures (FAILS prefix)'] 35 '3 tests with ignored failures (FAILS prefix)']
37 36
38 summary = slavelastic.TestSummary() 37 summary = swarm_results.TestRunSummary()
39 38
40 for data in summary_output: 39 for data in summary_output:
41 summary.AddSummaryData(data) 40 summary.AddSummaryData(data)
42 41
43 self.assertEquals(expected_output, summary.Output()) 42 self.assertEquals(expected_output, summary.Output())
44 self.assertEquals(1, summary.exit_code())
45 43
46 def test_correct_all_pass(self): 44 def test_correct_all_pass(self):
47 summary_output = [ 45 summary_output = [
48 ('[ PASSED ] 10 tests.'), 46 ('[ PASSED ] 10 tests.'),
49 ('[ PASSED ] 10 tests')] 47 ('[ PASSED ] 10 tests')]
50 48
51 expected_output = ['[ PASSED ] 20 tests.'] 49 expected_output = ['[ PASSED ] 20 tests.']
52 50
53 summary = slavelastic.TestSummary() 51 summary = swarm_results.TestRunSummary()
54 52
55 for data in summary_output: 53 for data in summary_output:
56 summary.AddSummaryData(data) 54 summary.AddSummaryData(data)
57 55
58 self.assertEquals(expected_output, summary.Output()) 56 self.assertEquals(expected_output, summary.Output())
59 57
60 def test_test_run_output(self): 58 def test_test_run_output(self):
61 full_output = ('[==========] Running 1 tests from results test run.\n' 59 full_output = ('[==========] Running 1 tests from results test run.\n'
62 '[ RUN ] results.Run Test\n' 60 '[ RUN ] results.Run Test\n'
63 'DONE\n' 61 'DONE\n'
64 '[ OK ] results.Run Test (10 ms)\n\n' 62 '[ OK ] results.Run Test (10 ms)\n\n'
65 '[----------] results summary\n' 63 '[----------] results summary\n'
66 '[==========] 1 tests ran. (10 ms total)\n' 64 '[==========] 1 tests ran. (10 ms total)\n'
67 '[ PASSED ] 1 tests.\n' 65 '[ PASSED ] 1 tests.\n'
68 '[ FAILED ] 0 tests\n\n' 66 '[ FAILED ] 0 tests\n\n'
69 ' 0 FAILED TESTS') 67 ' 0 FAILED TESTS')
70 68
71 cleaned_output = slavelastic.TestRunOutput(full_output) 69 cleaned_output = swarm_results.TestRunOutput(full_output)
72 70
73 self.assertEquals('DONE', cleaned_output) 71 self.assertEquals('DONE\n', cleaned_output)
72
73
74 class GetTestKetsTest(SuperMoxTestBase):
75 def test_no_keys(self):
76 self.mox.StubOutWithMock(swarm_results.urllib2, 'urlopen')
77 response = StringIO.StringIO('No matching Test Cases')
78 swarm_results.urllib2.urlopen(mox.IgnoreArg()).AndReturn(
79 response)
80 self.mox.ReplayAll()
81
82 self.assertEqual([], swarm_results.GetTestKeys('http://host:9001',
83 'my_test'))
84 self.checkstdout('Error: Unable to find any tests with the name, '
85 'my_test, on swarm server\n')
86
87 self.mox.VerifyAll()
88
89 def test_find_keys(self):
90 keys = ['key_1', 'key_2']
91
92 self.mox.StubOutWithMock(swarm_results.urllib2, 'urlopen')
93 response = StringIO.StringIO('\n'.join(keys))
94 swarm_results.urllib2.urlopen(mox.IgnoreArg()).AndReturn(
95 response)
96 self.mox.ReplayAll()
97
98 self.assertEqual(keys,
99 swarm_results.GetTestKeys('http://host:9001', 'my_test'))
100
101 self.mox.VerifyAll()
102
74 103
75 if __name__ == '__main__': 104 if __name__ == '__main__':
76 unittest.main() 105 unittest.main()
OLDNEW
« no previous file with comments | « scripts/slave/slave_utils_unittest.py ('k') | scripts/slave/unittests/slave_utils_test_broken.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698