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

Side by Side Diff: tests/watchlists_unittest.py

Issue 126272: Add unit tests for watchlists (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « PRESUBMIT.py ('k') | watchlists.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Name: svn:executable
+ *
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (c) 2009 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 watchlists.py."""
7
8 import unittest
9 import super_mox
10 import watchlists
11
12
13 class WatchlistsTest(super_mox.SuperMoxTestBase):
14
15 def setUp(self):
16 super_mox.SuperMoxTestBase.setUp(self)
17 self.mox.StubOutWithMock(watchlists.Watchlists, '_HasWatchlistsFile')
18 self.mox.StubOutWithMock(watchlists.Watchlists, '_ContentsOfWatchlistsFile')
19 self.mox.StubOutWithMock(watchlists.logging, 'error')
20
21 def testMissingWatchlistsFileOK(self):
22 """Test that we act gracefully if WATCHLISTS file is missing."""
23 watchlists.Watchlists._HasWatchlistsFile().AndReturn(False)
24 self.mox.ReplayAll()
25
26 wl = watchlists.Watchlists('/some/random/path')
27 self.assertEqual(wl.GetWatchersForPaths(['some_path']), [])
28
29 def testGarbledWatchlistsFileOK(self):
30 """Test that we act gracefully if WATCHLISTS file is garbled."""
31 contents = 'some garbled and unwanted text'
32 watchlists.Watchlists._HasWatchlistsFile().AndReturn(True)
33 watchlists.Watchlists._ContentsOfWatchlistsFile().AndReturn(contents)
34 watchlists.logging.error(super_mox.mox.IgnoreArg())
35 self.mox.ReplayAll()
36
37 wl = watchlists.Watchlists('/a/path')
38 self.assertEqual(wl.GetWatchersForPaths(['some_path']), [])
39
40 def testNoWatchers(self):
41 contents = \
42 """{
43 'WATCHLIST_DEFINITIONS': {
44 'a_module': {
45 'filepath': 'a_module',
46 },
47 },
48
49 'WATCHLISTS': {
50 'a_module': [],
51 },
52 } """
53 watchlists.Watchlists._HasWatchlistsFile().AndReturn(True)
54 watchlists.Watchlists._ContentsOfWatchlistsFile().AndReturn(contents)
55 self.mox.ReplayAll()
56
57 wl = watchlists.Watchlists('/a/path')
58 self.assertEqual(wl.GetWatchersForPaths(['a_module']), [])
59
60 def testValidWatcher(self):
61 watchers = ['abc@def.com', 'x1@xyz.org']
62 contents = \
63 """{
64 'WATCHLIST_DEFINITIONS': {
65 'a_module': {
66 'filepath': 'a_module',
67 },
68 },
69 'WATCHLISTS': {
70 'a_module': %s,
71 },
72 } """ % watchers
73 watchlists.Watchlists._HasWatchlistsFile().AndReturn(True)
74 watchlists.Watchlists._ContentsOfWatchlistsFile().AndReturn(contents)
75 self.mox.ReplayAll()
76
77 wl = watchlists.Watchlists('/a/path')
78 self.assertEqual(wl.GetWatchersForPaths(['a_module']), watchers)
79
80 def testMultipleWatchlistsTrigger(self):
81 """Test that multiple watchlists can get triggered for one filepath."""
82 contents = \
83 """{
84 'WATCHLIST_DEFINITIONS': {
85 'mac': {
86 'filepath': 'mac',
87 },
88 'views': {
89 'filepath': 'views',
90 },
91 },
92 'WATCHLISTS': {
93 'mac': ['x1@chromium.org'],
94 'views': ['x2@chromium.org'],
95 },
96 } """
97 watchlists.Watchlists._HasWatchlistsFile().AndReturn(True)
98 watchlists.Watchlists._ContentsOfWatchlistsFile().AndReturn(contents)
99 self.mox.ReplayAll()
100
101 wl = watchlists.Watchlists('/a/path')
102 self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']),
103 ['x1@chromium.org', 'x2@chromium.org'])
104
105 def testDuplicateWatchers(self):
106 """Test that multiple watchlists can get triggered for one filepath."""
107 watchers = ['someone@chromium.org']
108 contents = \
109 """{
110 'WATCHLIST_DEFINITIONS': {
111 'mac': {
112 'filepath': 'mac',
113 },
114 'views': {
115 'filepath': 'views',
116 },
117 },
118 'WATCHLISTS': {
119 'mac': %s,
120 'views': %s,
121 },
122 } """ % (watchers, watchers)
123 watchlists.Watchlists._HasWatchlistsFile().AndReturn(True)
124 watchlists.Watchlists._ContentsOfWatchlistsFile().AndReturn(contents)
125 self.mox.ReplayAll()
126
127 wl = watchlists.Watchlists('/a/path')
128 self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']), watchers)
129
130
131 if __name__ == '__main__':
132 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | watchlists.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698