Python 3: Add support in webkitpy.common.watchlist
https://bugs.webkit.org/show_bug.cgi?id=202473

Reviewed by Dewei Zhu.

* Scripts/test-webkitpy-python3: Add webkitpy.common.watchlist.
* Scripts/webkitpy/common/watchlist/watchlist.py:
(WatchList.find_matching_definitions): Use items instead of iteritems.
* Scripts/webkitpy/common/watchlist/watchlist_unittest.py:
(WatchListTest.test_filename_definition_no_matches): Back-slash needs to be escaped.
(WatchListTest.test_filename_definition): Ditto.
(WatchListTest.test_cc_rules_simple): Ditto.
(WatchListTest.test_cc_rules_complex): Ditto.
(WatchListTest.test_cc_and_message_rules_complex): Ditto.
(WatchListTest.test_cc_and_message_rules_no_matches): Ditto.
(WatchListTest.test_more_and_less_match): Ditto.
(WatchListTest.test_complex_match): Ditto.
* Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py:
(WatchListParserTest.test_bad_definition): Back-slash needs to be escaped.
(WatchListParserTest.test_bad_filename_regex): Ditto.
(WatchListParserTest.test_bad_more_regex): Ditto.
(WatchListParserTest.test_bad_match_type): Ditto.
(WatchListParserTest.test_match_type_typo): Ditto.
(WatchListParserTest.test_empty_cc_rule): Ditto.
(WatchListParserTest.test_cc_rule_with_invalid_email): Ditto.
(WatchListParserTest.test_cc_rule_with_secondary_email): Ditto.
(WatchListParserTest.test_empty_message_rule): Ditto.
(WatchListParserTest.test_unused_defintion): Ditto.
(WatchListParserTest.test_cc_rule_with_undefined_defintion_with_suggestion): Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251312 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index e3ea89d..ea20e67 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,35 @@
+2019-10-18  Jonathan Bedard  <jbedard@apple.com>
+
+        Python 3: Add support in webkitpy.common.watchlist
+        https://bugs.webkit.org/show_bug.cgi?id=202473
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/test-webkitpy-python3: Add webkitpy.common.watchlist.
+        * Scripts/webkitpy/common/watchlist/watchlist.py:
+        (WatchList.find_matching_definitions): Use items instead of iteritems.
+        * Scripts/webkitpy/common/watchlist/watchlist_unittest.py:
+        (WatchListTest.test_filename_definition_no_matches): Back-slash needs to be escaped.
+        (WatchListTest.test_filename_definition): Ditto.
+        (WatchListTest.test_cc_rules_simple): Ditto.
+        (WatchListTest.test_cc_rules_complex): Ditto.
+        (WatchListTest.test_cc_and_message_rules_complex): Ditto.
+        (WatchListTest.test_cc_and_message_rules_no_matches): Ditto.
+        (WatchListTest.test_more_and_less_match): Ditto.
+        (WatchListTest.test_complex_match): Ditto.
+        * Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py:
+        (WatchListParserTest.test_bad_definition): Back-slash needs to be escaped.
+        (WatchListParserTest.test_bad_filename_regex): Ditto.
+        (WatchListParserTest.test_bad_more_regex): Ditto.
+        (WatchListParserTest.test_bad_match_type): Ditto.
+        (WatchListParserTest.test_match_type_typo): Ditto.
+        (WatchListParserTest.test_empty_cc_rule): Ditto.
+        (WatchListParserTest.test_cc_rule_with_invalid_email): Ditto.
+        (WatchListParserTest.test_cc_rule_with_secondary_email): Ditto.
+        (WatchListParserTest.test_empty_message_rule): Ditto.
+        (WatchListParserTest.test_unused_defintion): Ditto.
+        (WatchListParserTest.test_cc_rule_with_undefined_defintion_with_suggestion): Ditto.
+
 2019-10-18  Raphael Kubo da Costa  <rakuco@webkit.org>
 
         Remove myself from the CMake watchlist
diff --git a/Tools/Scripts/test-webkitpy-python3 b/Tools/Scripts/test-webkitpy-python3
index 2189e68..813fa45 100755
--- a/Tools/Scripts/test-webkitpy-python3
+++ b/Tools/Scripts/test-webkitpy-python3
@@ -37,6 +37,7 @@
   'webkitpy.common.net.bugzilla',
   'webkitpy.common.net.buildbot',
   'webkitpy.common.net.irc',
+  'webkitpy.common.watchlist',
 ]
 
 
diff --git a/Tools/Scripts/webkitpy/common/watchlist/watchlist.py b/Tools/Scripts/webkitpy/common/watchlist/watchlist.py
index 4a81039..b5eb741 100644
--- a/Tools/Scripts/webkitpy/common/watchlist/watchlist.py
+++ b/Tools/Scripts/webkitpy/common/watchlist/watchlist.py
@@ -39,7 +39,7 @@
         matching_definitions = set()
         patch_files = DiffParser(diff.splitlines()).files
 
-        for path, diff_file in patch_files.iteritems():
+        for path, diff_file in patch_files.items():
             for definition in self.definitions:
                 # If a definition has already matched, there is no need to process it.
                 if definition in matching_definitions:
diff --git a/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py b/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py
index 67ff3b0..43e382e 100644
--- a/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py
+++ b/Tools/Scripts/webkitpy/common/watchlist/watchlist_unittest.py
@@ -43,7 +43,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -59,7 +59,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\.h",'
+            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\\.h",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -75,7 +75,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\.h",'
+            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\\.h",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -95,7 +95,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\.h",'
+            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\\.h",'
             '        },'
             '        "WatchList2": {'
             '            "filename": r"WillNotMatch",'
@@ -119,7 +119,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\.h",'
+            '            "filename": r"WebCore/rendering/style/StyleFlexibleBoxData\\.h",'
             '        },'
             '        "WatchList2": {'
             '            "filename": r"WillNotMatch",'
@@ -146,7 +146,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r"WebCore/rendering/style/ThisFileDoesNotExist\.h",'
+            '            "filename": r"WebCore/rendering/style/ThisFileDoesNotExist\\.h",'
             '        },'
             '        "WatchList2": {'
             '            "filename": r"WillNotMatch",'
@@ -218,10 +218,10 @@
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
             # This pattern is in both added and deleted lines, so no match.
-            '            "more": r"userSelect == o\.userSelect",'
+            '            "more": r"userSelect == o\\.userSelect",'
             '        },'
             '        "WatchList2": {'
-            '            "more": r"boxOrient\(o\.boxOrient\)",'
+            '            "more": r"boxOrient\\(o\\.boxOrient\\)",'
             '        },'
             '        "WatchList3": {'
             '            "less": r"unsigned orient"'
@@ -246,13 +246,13 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r"WebCore/rendering/style/StyleRareInheritedData\.cpp",'
-            '            "in_added_lines": r"\&\& boxOrient == o\.boxOrient;",'
-            '            "in_deleted_lines": r"\&\& userSelect == o\.userSelect;",'
-            '            "more": r"boxOrient\(o\.boxOrient\)",'
+            '            "filename": r"WebCore/rendering/style/StyleRareInheritedData\\.cpp",'
+            '            "in_added_lines": r"\\&\\& boxOrient == o\\.boxOrient;",'
+            '            "in_deleted_lines": r"\\&\\& userSelect == o\\.userSelect;",'
+            '            "more": r"boxOrient\\(o\\.boxOrient\\)",'
             '        },'
             '        "WatchList2": {'
-            '            "filename": r"WebCore/rendering/style/StyleRareInheritedData\.cpp",'
+            '            "filename": r"WebCore/rendering/style/StyleRareInheritedData\\.cpp",'
             '            "in_added_lines": r"RenderStyle::initialBoxOrient",'
             '            "less": r"userSelect;"'
             '        },'
diff --git a/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py b/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py
index 676395e..5b7c7eb 100644
--- a/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py
+++ b/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py
@@ -59,7 +59,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1|A": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '}')
@@ -81,8 +81,11 @@
             '     },'
             '}')
 
-        OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
-                                       expected_logs='The regex "*" is invalid due to "nothing to repeat".\n')
+        if sys.version_info > (3, 0):
+            expected_log = 'The regex "*" is invalid due to "nothing to repeat at position 0".\n'
+        else:
+            expected_log = 'The regex "*" is invalid due to "nothing to repeat".\n'
+        OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list], expected_logs=expected_log)
 
     def test_bad_more_regex(self):
         watch_list = (
@@ -98,16 +101,19 @@
             '     },'
             '}')
 
-        OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
-                                       expected_logs='The regex "*" is invalid due to "nothing to repeat".\n')
+        if sys.version_info > (3, 0):
+            expected_log = 'The regex "*" is invalid due to "nothing to repeat at position 0".\n'
+        else:
+            expected_log = 'The regex "*" is invalid due to "nothing to repeat".\n'
+        OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list], expected_logs=expected_log)
 
     def test_bad_match_type(self):
         watch_list = (
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "nothing_matches_this": r".*\\MyFileName\\.cpp",'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "nothing_matches_this": r".*MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -123,7 +129,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "iflename": r".*\\MyFileName\\.cpp",'
+            '            "iflename": r".*MyFileName\\.cpp",'
             '            "more": r"RefCounted",'
             '        },'
             '     },'
@@ -156,7 +162,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -173,7 +179,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -191,7 +197,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "CC_RULES": {'
@@ -207,7 +213,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "MESSAGE_RULES": {'
@@ -225,7 +231,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '}')
@@ -260,7 +266,7 @@
             '{'
             '    "DEFINITIONS": {'
             '        "WatchList1": {'
-            '            "filename": r".*\\MyFileName\\.cpp",'
+            '            "filename": r".*MyFileName\\.cpp",'
             '        },'
             '     },'
             '    "CC_RULES": {'