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

Side by Side Diff: commit-queue/tests/tree_status_test.py

Issue 135363007: Delete public commit queue to avoid confusion after move to internal repo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Created 6 years, 10 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
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 """Unit tests for verification/tree_status.py."""
7
8 import calendar
9 import json
10 import logging
11 import os
12 import StringIO
13 import sys
14 import unittest
15 import urllib2
16
17 ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
18 sys.path.insert(0, os.path.join(ROOT_DIR, '..'))
19
20 # From tests/
21 import mocks
22
23 from verification import tree_status
24
25
26 class TreeStatusTest(mocks.TestCase):
27 def setUp(self):
28 super(TreeStatusTest, self).setUp()
29 reference = calendar.timegm((2010, 1, 1, 12, 0, 0, 0, 0, -1))
30 self.mock(tree_status.time, 'time', lambda: reference)
31 self.urlrequests = []
32 self.mock(urllib2, 'urlopen', self._urlopen)
33
34 def tearDown(self):
35 super(TreeStatusTest, self).setUp()
36
37 def _urlopen(self, _):
38 return StringIO.StringIO(json.dumps(self.urlrequests.pop(0)))
39
40 def test_fail(self):
41 self.urlrequests = [
42 [
43 {
44 'date': '2010-01-01 11:56:00.0',
45 'general_state': 'open',
46 'message': 'Foo',
47 },
48 {
49 'date': '2010-01-01 11:57:00.0',
50 'general_state': 'closed',
51 'message': 'Bar',
52 },
53 {
54 'date': '2010-01-01 11:58:00.0',
55 'general_state': 'open',
56 'message': 'Baz',
57 },
58 ],
59 ]
60 obj = tree_status.TreeStatus(tree_status_url='foo')
61 self.assertEqual(True, obj.postpone())
62 self.assertEqual(u'Tree is currently not open: Bar', obj.why_not())
63 self.assertEqual([], self.urlrequests)
64
65 def test_pass(self):
66 self.urlrequests = [
67 [
68 {
69 'date': '2010-01-01 11:54:00.0',
70 'general_state': 'open',
71 'message': 'Foo',
72 },
73 {
74 'date': '2010-01-01 11:57:00.0',
75 'general_state': 'open',
76 'message': 'Bar',
77 },
78 {
79 'date': '2010-01-01 11:53:00.0',
80 'general_state': 'closed',
81 'message': 'Baz',
82 },
83 ],
84 ]
85 obj = tree_status.TreeStatus(tree_status_url='foo')
86 self.assertEqual(False, obj.postpone())
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(object):
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)
128
129 def test_state(self):
130 t = tree_status.TreeStatus(tree_status_url='foo')
131 self.assertEqual(tree_status.base.SUCCEEDED, t.get_state())
132 self.assertEqual([], self.urlrequests)
133
134
135 if __name__ == '__main__':
136 logging.basicConfig(
137 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][
138 min(sys.argv.count('-v'), 3)],
139 format='%(levelname)5s %(module)15s(%(lineno)3d): %(message)s')
140 unittest.main()
OLDNEW
« no previous file with comments | « commit-queue/tests/reviewer_lgtm_test.py ('k') | commit-queue/tests/try_job_on_rietveld_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698