diff --git a/tests/watchlists_unittest.py b/tests/watchlists_unittest.py index ecc16e251..968de038f 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 77b63eabc..9d38faf49 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')