Skip to content

Commit

Permalink
StringProcessing: Add assert function for tests
Browse files Browse the repository at this point in the history
New assert function for unescaped_search_in_between().
  • Loading branch information
Makman2 committed Mar 24, 2015
1 parent 56f779e commit 467760e
Showing 1 changed file with 50 additions and 37 deletions.
87 changes: 50 additions & 37 deletions coalib/tests/parsing/StringProcessingTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,38 @@ def assertSearchInBetweenEquals(self,
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.
Expand Down Expand Up @@ -646,23 +678,15 @@ def test_search_in_between_auto_trim(self):

# 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)

Expand All @@ -671,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.
Expand All @@ -700,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__':
Expand Down

1 comment on commit 467760e

@sils
Copy link
Member

@sils sils commented on 467760e Mar 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.