From 76256af3ce2303bf629ce8bb459ff6f6faaf183f Mon Sep 17 00:00:00 2001 From: "nirnimesh@chromium.org" Date: Thu, 18 Jun 2009 22:52:12 +0000 Subject: [PATCH] Review URL: http://codereview.chromium.org/132022 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18764 0039d316-1c4b-4281-b951-d872f2087c98 --- tests/watchlists_unittest.py | 27 +++++++++++++++++++++++++++ watchlists.py | 1 + 2 files changed, 28 insertions(+) diff --git a/tests/watchlists_unittest.py b/tests/watchlists_unittest.py index ecc16e2512..968de038f8 100755 --- a/tests/watchlists_unittest.py +++ b/tests/watchlists_unittest.py @@ -5,6 +5,7 @@ """Unit tests for watchlists.py.""" +import os import unittest import super_mox import watchlists @@ -127,6 +128,32 @@ class WatchlistsTest(super_mox.SuperMoxTestBase): wl = watchlists.Watchlists('/a/path') self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']), watchers) + def testWinPathWatchers(self): + """Test watchers for a windows path (containing backward slashes).""" + watchers = ['abc@def.com', 'x1@xyz.org'] + contents = \ + """{ + 'WATCHLIST_DEFINITIONS': { + 'browser': { + 'filepath': 'chrome/browser/.*', + }, + }, + 'WATCHLISTS': { + 'browser': %s, + }, + } """ % watchers + saved_sep = os.sep + os.sep = '\\' # to pose as win32 + watchlists.Watchlists._HasWatchlistsFile().AndReturn(True) + watchlists.Watchlists._ContentsOfWatchlistsFile().AndReturn(contents) + self.mox.ReplayAll() + + wl = watchlists.Watchlists(r'a\path') + returned_watchers = wl.GetWatchersForPaths( + [r'chrome\browser\renderer_host\render_widget_host.h']) + os.sep = saved_sep # revert back os.sep before asserts + self.assertEqual(returned_watchers, watchers) + if __name__ == '__main__': unittest.main() diff --git a/watchlists.py b/watchlists.py index 77b63eabc3..9d38faf49f 100755 --- a/watchlists.py +++ b/watchlists.py @@ -104,6 +104,7 @@ class Watchlists(object): """ watchers = set() # A set, to avoid duplicates for path in paths: + path = path.replace(os.sep, '/') for name, rule in self._defns.iteritems(): if name not in self._watchlists: continue rex_str = rule.get('filepath')