Repository: coala/coala

Issue:
escaping stuff: scrutinizer issues
https://scrutinizer-ci.com/g/coala-analyzer/coala/inspections/8589a071-2905-40dd-a562-bfae3b8f40e5/issues/

need to fix after merging the escaping stuff



Discussion:
plus you wanted to add another test

What shall I fix explicitly? Many things are just complexities which I can't change.
Okay duplicated code is obvious, but rename methods to conform the naming convention?

some renamings should probably be done too, yes. We already talked about the rest on gitter.


Resolving patch:
diff --git a/coalib/parsing/StringProcessing.py b/coalib/parsing/StringProcessing.py
--- a/coalib/parsing/StringProcessing.py
+++ b/coalib/parsing/StringProcessing.py
@@ -53,7 +53,6 @@ def trim_empty_matches(iterator, groups=[0]):
         for group in groups:
             if len(elem.group(group)) != 0:
                 yield elem
-
                 continue
 
 


Test patch:
diff --git a/coalib/tests/parsing/StringProcessingTest.py b/coalib/tests/parsing/StringProcessingTest.py
--- a/coalib/tests/parsing/StringProcessingTest.py
+++ b/coalib/tests/parsing/StringProcessingTest.py
@@ -350,6 +350,122 @@ def assertSearchForResultEqual(self,
 
             self.assertEqual(n, len(expected_strings[i]))
 
+    def assertSplitEquals(self,
+                          test_strings,
+                          expected_results,
+                          pattern,
+                          max_split=0,
+                          remove_empty_matches=False):
+        """
+        Checks whether all supplied test strings are returned as expected from
+        split().
+
+        :param test_strings:         The list of test strings.
+        :param expected_results:     The list of the expected results.
+        :param pattern:              The pattern to invoke split() with.
+        :param max_split:            The maximum number of splits to perform
+                                     when invoking split().
+        :param remove_empty_matches: Whether to remove empty entries or not.
+        """
+        self.assertEqual(len(expected_results), len(test_strings))
+        for i in range(0, len(expected_results)):
+            return_value = split(pattern,
+                                 test_strings[i],
+                                 max_split,
+                                 remove_empty_matches)
+            self.assertIteratorElementsEqual(iter(expected_results[i]),
+                                             return_value)
+
+    def assertUnescapedSplitEquals(self,
+                                   test_strings,
+                                   expected_results,
+                                   pattern,
+                                   max_split=0,
+                                   remove_empty_matches=False):
+        """
+        Checks whether all supplied test strings are returned as expected from
+        unescaped_split().
+
+        :param test_strings:         The list of test strings.
+        :param expected_results:     The list of the expected results.
+        :param pattern:              The pattern to invoke unescaped_split()
+                                     with.
+        :param max_split:            The maximum number of splits to perform
+                                     when invoking unescaped_split().
+        :param remove_empty_matches: Whether to remove empty entries or not.
+        """
+        self.assertEqual(len(expected_results), len(test_strings))
+        for i in range(0, len(expected_results)):
+            return_value = unescaped_split(pattern,
+                                           test_strings[i],
+                                           max_split,
+                                           remove_empty_matches)
+            self.assertIteratorElementsEqual(iter(expected_results[i]),
+                                             return_value)
+
+    def assertSearchInBetweenEquals(self,
+                                    test_strings,
+                                    expected_results,
+                                    begin,
+                                    end,
+                                    max_match=0,
+                                    remove_empty_matches=False):
+        """
+        Checks whether all supplied test strings are returned as expected from
+        search_in_between().
+
+        :param test_strings:         The list of test strings.
+        :param expected_results:     The list of the expected results.
+        :param begin:                The beginning pattern to invoke
+                                     search_in_between() with.
+        :param end:                  The ending pattern to invoke
+                                     search_in_between() with.
+        :param max_match:            The maximum number of matches to perform
+                                     when invoking search_in_between().
+        :param remove_empty_matches: Whether to remove empty entries or not.
+        """
+        self.assertEqual(len(expected_results), len(test_strings))
+        for i in range(0, len(expected_results)):
+            return_value = search_in_between(begin,
+                                             end,
+                                             test_strings[i],
+                                             max_match,
+                                             remove_empty_matches)
+            self.assertIteratorElementsEqual(iter(expected_results[i]),
+                                             return_value)
+
+    def assertUnescapedSearchInBetweenEquals(self,
+                                             test_strings,
+                                             expected_results,
+                                             begin,
+                                             end,
+                                             max_match=0,
+                                             remove_empty_matches=False):
+        """
+        Checks whether all supplied test strings are returned as expected from
+        unescaped_search_in_between().
+
+        :param test_strings:         The list of test strings.
+        :param expected_results:     The list of the expected results.
+        :param begin:                The beginning pattern to invoke
+                                     unescaped_search_in_between() with.
+        :param end:                  The ending pattern to invoke
+                                     unescaped_search_in_between() with.
+        :param max_match:            The maximum number of matches to perform
+                                     when invoking
+                                     unescaped_search_in_between().
+        :param remove_empty_matches: Whether to remove empty entries or not.
+        """
+        self.assertEqual(len(expected_results), len(test_strings))
+        for i in range(0, len(expected_results)):
+            return_value = unescaped_search_in_between(begin,
+                                                       end,
+                                                       test_strings[i],
+                                                       max_match,
+                                                       remove_empty_matches)
+            self.assertIteratorElementsEqual(iter(expected_results[i]),
+                                             return_value)
+
     def assertIteratorElementsEqual(self, iterator1, iterator2):
         """
         Checks whether each element in the iterators and their length do equal.
@@ -407,15 +523,9 @@ def test_search_for_max_match(self):
 
     # Test the basic split() functionality.
     def test_split(self):
-        separator_pattern = self.test_split_pattern
-        expected_results = self.test_split_expected_results
-
-        self.assertEqual(len(expected_results), len(self.test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = split(separator_pattern,
-                                 self.test_strings[i])
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertSplitEquals(self.test_strings,
+                               self.test_split_expected_results,
+                               self.test_split_pattern)
 
     # Test the split() function while varying the max_split parameter.
     def test_split_max_split(self):
@@ -436,13 +546,10 @@ def test_split_max_split(self):
                         str.join(separator_pattern,
                                  expected_master_results[j][max_split : ]))
 
-            self.assertEqual(len(expected_results), len(self.test_strings))
-            for x in range(0, len(expected_results)):
-                return_value = split(separator_pattern,
-                                     self.test_strings[x],
-                                     max_split)
-                self.assertIteratorElementsEqual(iter(expected_results[x]),
-                                                 return_value)
+            self.assertSplitEquals(self.test_strings,
+                                   expected_results,
+                                   separator_pattern,
+                                   max_split)
 
     # Test the split() function with different regex patterns.
     def test_split_regex_pattern(self):
@@ -457,30 +564,18 @@ def test_split_regex_pattern(self):
 
     # Test the split() function for its remove_empty_matches feature.
     def test_split_auto_trim(self):
-        separator = self.test_split_auto_trim_pattern
-        expected_results = self.test_split_auto_trim_expected_results
-
-        self.assertEqual(len(expected_results),
-                         len(self.auto_trim_test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = split(separator,
-                                 self.auto_trim_test_strings[i],
-                                 0,
-                                 True)
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertSplitEquals(self.auto_trim_test_strings,
+                               self.test_split_auto_trim_expected_results,
+                               self.test_split_auto_trim_pattern,
+                               0,
+                               True)
 
     # Test the basic unescaped_split() functionality.
     def test_unescaped_split(self):
-        separator_pattern = self.test_unescaped_split_pattern
-        expected_results = self.test_unescaped_split_expected_results
-
-        self.assertEqual(len(expected_results), len(self.test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = unescaped_split(separator_pattern,
-                                           self.test_strings[i])
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertUnescapedSplitEquals(
+            self.test_strings,
+            self.test_unescaped_split_expected_results,
+            self.test_unescaped_split_pattern)
 
     # Test the unescaped_split() function while varying the max_split
     # parameter.
@@ -502,13 +597,10 @@ def test_unescaped_split_max_split(self):
                         str.join(separator_pattern,
                                  expected_master_results[j][max_split : ]))
 
-            self.assertEqual(len(expected_results), len(self.test_strings))
-            for x in range(0, len(expected_results)):
-                return_value = unescaped_split(separator_pattern,
-                                               self.test_strings[x],
-                                               max_split)
-                self.assertIteratorElementsEqual(iter(expected_results[x]),
-                                                 return_value)
+            self.assertUnescapedSplitEquals(self.test_strings,
+                                            expected_results,
+                                            separator_pattern,
+                                            max_split)
 
     # Test the unescaped_split() function with different regex patterns.
     def test_unescaped_split_regex_pattern(self):
@@ -524,36 +616,25 @@ def test_unescaped_split_regex_pattern(self):
 
     # Test the unescaped_split() function for its remove_empty_matches feature.
     def test_unescaped_split_auto_trim(self):
-        separator = self.test_unescaped_split_auto_trim_pattern
-        expected_results = self.test_unescaped_split_auto_trim_expected_results
-
-        self.assertEqual(len(expected_results),
-                         len(self.auto_trim_test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = unescaped_split(separator,
-                                           self.auto_trim_test_strings[i],
-                                           0,
-                                           True)
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertUnescapedSplitEquals(
+            self.auto_trim_test_strings,
+            self.test_unescaped_split_auto_trim_expected_results,
+            self.test_unescaped_split_auto_trim_pattern,
+            0,
+            True)
 
     # Test the basic search_in_between() functionality.
     def test_search_in_between(self):
-        sequence = self.test_search_in_between_pattern
-        expected_results = self.test_search_in_between_expected_results
-
-        self.assertEqual(len(expected_results), len(self.test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = search_in_between(sequence,
-                                             sequence,
-                                             self.test_strings[i])
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertSearchInBetweenEquals(
+            self.test_strings,
+            self.test_search_in_between_expected_results,
+            self.test_search_in_between_pattern,
+            self.test_search_in_between_pattern)
 
     # Test the search_in_between() while varying the max_match
     # parameter.
+
     def test_search_in_between_max_match(self):
-        sequence = self.test_search_in_between_max_match_pattern
         expected_master_results = (
             self.test_search_in_between_max_match_expected_master_results)
 
@@ -562,14 +643,12 @@ def test_search_in_between_max_match(self):
                 expected_master_results[j][0 : max_match]
                 for j in range(len(expected_master_results))]
 
-            self.assertEqual(len(expected_results), len(self.test_strings))
-            for x in range(0, len(expected_results)):
-                return_value = search_in_between(sequence,
-                                                 sequence,
-                                                 self.test_strings[x],
-                                                 max_match)
-                self.assertIteratorElementsEqual(iter(expected_results[x]),
-                                                 return_value)
+            self.assertSearchInBetweenEquals(
+                self.test_strings,
+                expected_results,
+                self.test_search_in_between_max_match_pattern,
+                self.test_search_in_between_max_match_pattern,
+                max_match)
 
     # Test the search_in_between() function with different regex
     # patterns.
@@ -589,40 +668,25 @@ def test_search_in_between_regex_pattern(self):
     # Test the search_in_between() function for its
     # remove_empty_matches feature.
     def test_search_in_between_auto_trim(self):
-        sequence = self.test_search_in_between_auto_trim_pattern
-        expected_results = (
-            self.test_search_in_between_auto_trim_expected_results)
-
-        self.assertEqual(len(expected_results),
-                         len(self.auto_trim_test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = search_in_between(sequence,
-                                             sequence,
-                                             self.auto_trim_test_strings[i],
-                                             0,
-                                             True)
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertSearchInBetweenEquals(
+            self.auto_trim_test_strings,
+            self.test_search_in_between_auto_trim_expected_results,
+            self.test_search_in_between_auto_trim_pattern,
+            self.test_search_in_between_auto_trim_pattern,
+            0,
+            True)
 
     # Test the basic unescaped_search_in_between() functionality.
     def test_unescaped_search_in_between(self):
-        sequence = self.test_unescaped_search_in_between_pattern
-        expected_results = (
-            self.test_unescaped_search_in_between_expected_results)
-
-        self.assertEqual(len(expected_results), len(self.test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = unescaped_search_in_between(sequence,
-                                                       sequence,
-                                                       self.test_strings[i])
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertUnescapedSearchInBetweenEquals(
+            self.test_strings,
+            self.test_unescaped_search_in_between_expected_results,
+            self.test_unescaped_search_in_between_pattern,
+            self.test_unescaped_search_in_between_pattern)
 
     # Test the unescaped_search_in_between() while varying the max_match
     # parameter.
     def test_unescaped_search_in_between_max_match(self):
-        sequence = self.test_unescaped_search_in_between_max_match_pattern
-
         expected_master_results = (
             self.test_unescaped_search_in_between_max_match_expected_m_results)
 
@@ -631,15 +695,12 @@ def test_unescaped_search_in_between_max_match(self):
                 expected_master_results[j][0 : max_match]
                 for j in range(len(expected_master_results))]
 
-            self.assertEqual(len(expected_results), len(self.test_strings))
-            for x in range(0, len(expected_results)):
-                return_value = unescaped_search_in_between(
-                    sequence,
-                    sequence,
-                    self.test_strings[x],
-                    max_match)
-                self.assertIteratorElementsEqual(iter(expected_results[x]),
-                                                 return_value)
+            self.assertUnescapedSearchInBetweenEquals(
+                self.test_strings,
+                expected_results,
+                self.test_unescaped_search_in_between_max_match_pattern,
+                self.test_unescaped_search_in_between_max_match_pattern,
+                max_match)
 
     # Test the unescaped_search_in_between() function with different regex
     # patterns.
@@ -660,21 +721,13 @@ def test_unescaped_search_in_between_regex_pattern(self):
     # Test the unescaped_search_in_between() function for its
     # remove_empty_matches feature.
     def test_unescaped_search_in_between_auto_trim(self):
-        sequence = self.test_unescaped_search_in_between_auto_trim_pattern
-        expected_results = (
-            self.test_unescaped_search_in_between_auto_trim_expected_results)
-
-        self.assertEqual(len(expected_results),
-                         len(self.auto_trim_test_strings))
-        for i in range(0, len(expected_results)):
-            return_value = unescaped_search_in_between(
-                sequence,
-                sequence,
-                self.auto_trim_test_strings[i],
-                0,
-                True)
-            self.assertIteratorElementsEqual(iter(expected_results[i]),
-                                             return_value)
+        self.assertUnescapedSearchInBetweenEquals(
+            self.auto_trim_test_strings,
+            self.test_unescaped_search_in_between_auto_trim_expected_results,
+            self.test_unescaped_search_in_between_auto_trim_pattern,
+            self.test_unescaped_search_in_between_auto_trim_pattern,
+            0,
+            True)
 
 
 if __name__ == '__main__':