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

Side by Side Diff: tests/tree_status_test.py

Issue 68113009: Adding support for NOTREECHECKS (Closed) Base URL: https://src.chromium.org/chrome/trunk/tools/commit-queue/
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « no previous file | verification/tree_status.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 verification/tree_status.py.""" 6 """Unit tests for verification/tree_status.py."""
7 7
8 import calendar 8 import calendar
9 import json 9 import json
10 import logging 10 import logging
(...skipping 14 matching lines...) Expand all
25 25
26 class TreeStatusTest(mocks.TestCase): 26 class TreeStatusTest(mocks.TestCase):
27 def setUp(self): 27 def setUp(self):
28 super(TreeStatusTest, self).setUp() 28 super(TreeStatusTest, self).setUp()
29 reference = calendar.timegm((2010, 1, 1, 12, 0, 0, 0, 0, -1)) 29 reference = calendar.timegm((2010, 1, 1, 12, 0, 0, 0, 0, -1))
30 self.mock(tree_status.time, 'time', lambda: reference) 30 self.mock(tree_status.time, 'time', lambda: reference)
31 self.urlrequests = [] 31 self.urlrequests = []
32 self.mock(urllib2, 'urlopen', self._urlopen) 32 self.mock(urllib2, 'urlopen', self._urlopen)
33 33
34 def tearDown(self): 34 def tearDown(self):
35 self.assertEqual([], self.urlrequests)
36 super(TreeStatusTest, self).setUp() 35 super(TreeStatusTest, self).setUp()
37 36
38 def _urlopen(self, _): 37 def _urlopen(self, _):
39 return StringIO.StringIO(json.dumps(self.urlrequests.pop(0))) 38 return StringIO.StringIO(json.dumps(self.urlrequests.pop(0)))
40 39
41 def test_fail(self): 40 def test_fail(self):
42 self.urlrequests = [ 41 self.urlrequests = [
43 [ 42 [
44 { 43 {
45 'date': '2010-01-01 11:56:00.0', 44 'date': '2010-01-01 11:56:00.0',
46 'general_state': 'open', 45 'general_state': 'open',
47 'message': 'Foo', 46 'message': 'Foo',
48 }, 47 },
49 { 48 {
50 'date': '2010-01-01 11:57:00.0', 49 'date': '2010-01-01 11:57:00.0',
51 'general_state': 'closed', 50 'general_state': 'closed',
52 'message': 'Bar', 51 'message': 'Bar',
53 }, 52 },
54 { 53 {
55 'date': '2010-01-01 11:58:00.0', 54 'date': '2010-01-01 11:58:00.0',
56 'general_state': 'open', 55 'general_state': 'open',
57 'message': 'Baz', 56 'message': 'Baz',
58 }, 57 },
59 ], 58 ],
60 ] 59 ]
61 obj = tree_status.TreeStatus(tree_status_url='foo') 60 obj = tree_status.TreeStatus(tree_status_url='foo')
62 self.assertEqual(True, obj.postpone()) 61 self.assertEqual(True, obj.postpone())
63 self.assertEqual(u'Tree is currently not open: Bar', obj.why_not()) 62 self.assertEqual(u'Tree is currently not open: Bar', obj.why_not())
63 self.assertEqual([], self.urlrequests)
64 64
65 def test_pass(self): 65 def test_pass(self):
66 self.urlrequests = [ 66 self.urlrequests = [
67 [ 67 [
68 { 68 {
69 'date': '2010-01-01 11:54:00.0', 69 'date': '2010-01-01 11:54:00.0',
70 'general_state': 'open', 70 'general_state': 'open',
71 'message': 'Foo', 71 'message': 'Foo',
72 }, 72 },
73 { 73 {
74 'date': '2010-01-01 11:57:00.0', 74 'date': '2010-01-01 11:57:00.0',
75 'general_state': 'open', 75 'general_state': 'open',
76 'message': 'Bar', 76 'message': 'Bar',
77 }, 77 },
78 { 78 {
79 'date': '2010-01-01 11:53:00.0', 79 'date': '2010-01-01 11:53:00.0',
80 'general_state': 'closed', 80 'general_state': 'closed',
81 'message': 'Baz', 81 'message': 'Baz',
82 }, 82 },
83 ], 83 ],
84 ] 84 ]
85 obj = tree_status.TreeStatus(tree_status_url='foo') 85 obj = tree_status.TreeStatus(tree_status_url='foo')
86 self.assertEqual(False, obj.postpone()) 86 self.assertEqual(False, obj.postpone())
87 self.assertEqual(None, obj.why_not()) 87 self.assertEqual(None, obj.why_not())
88 self.assertEqual([], self.urlrequests)
89
90 def test_skip_tree_check(self):
91 self.urlrequests = [
92 [
93 {
94 'date': '2010-01-01 11:56:00.0',
95 'general_state': 'open',
96 'message': 'Foo',
97 },
98 {
99 'date': '2010-01-01 11:57:00.0',
100 'general_state': 'closed',
101 'message': 'Bar',
102 },
103 {
104 'date': '2010-01-01 11:58:00.0',
105 'general_state': 'open',
106 'message': 'Baz',
107 },
108 ],
109 ]
110 # Create a dummy pending obj to pass to the verifier.
111 class dummy_pending:
iannucci 2013/11/14 07:40:51 should derive from object to be a 'new-style' clas
rmistry 2013/11/14 12:40:40 Done.
112 issue = 123
113 description = 'foobarbaz\nNOTREECHECKS=true\nfoobarbaz'
114 verifications = {}
115 def __init__(self):
116 pass
117
118 verifier = tree_status.TreeStatusVerifier('dummy_status_url')
119 verifier.verify(dummy_pending())
120
121 obj = dummy_pending.verifications['tree status']
122
123 self.assertEquals(tree_status.AlwaysOpenTreeStatus, type(obj))
124 self.assertEqual(False, obj.postpone())
125 self.assertEqual(None, obj.why_not())
126 # None of the urls should have been opened since it is a skip request.
127 self.assertTrue(len(self.urlrequests[0]) == 3)
88 128
89 def test_state(self): 129 def test_state(self):
90 t = tree_status.TreeStatus(tree_status_url='foo') 130 t = tree_status.TreeStatus(tree_status_url='foo')
91 self.assertEqual(tree_status.base.SUCCEEDED, t.get_state()) 131 self.assertEqual(tree_status.base.SUCCEEDED, t.get_state())
132 self.assertEqual([], self.urlrequests)
92 133
93 134
94 if __name__ == '__main__': 135 if __name__ == '__main__':
95 logging.basicConfig( 136 logging.basicConfig(
96 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ 137 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][
97 min(sys.argv.count('-v'), 3)], 138 min(sys.argv.count('-v'), 3)],
98 format='%(levelname)5s %(module)15s(%(lineno)3d): %(message)s') 139 format='%(levelname)5s %(module)15s(%(lineno)3d): %(message)s')
99 unittest.main() 140 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | verification/tree_status.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698