@@ -122,6 +122,7 @@ def __init__(self, xmlTree, filename):
122122 self .exclusions = []
123123 self .filename = filename
124124 self .tests = []
125+ self .determine_test_application_run = False
125126
126127 for (attrName , xpath , conversion ) in self ._attrConvert :
127128 elems = root .xpath (xpath )
@@ -161,6 +162,21 @@ def _addTests(self):
161162 continue
162163 self .tests .append (Test ("http://%s/" % target ))
163164
165+ def _determineTestApplication (self ):
166+ """Match each test against a rule or exclusion if possible, and hang them
167+ off that rule or exclusion. Return any coverage problems."""
168+ if not self .determine_test_application_run :
169+ self .test_application_problems = []
170+ for test in self .tests :
171+ applies = self .whatApplies (test .url )
172+ if applies :
173+ applies .tests .append (test )
174+ else :
175+ self .test_application_problems .append ("%s: No rule or exclusion applies to test URL %s" % (
176+ self .filename , test .url ))
177+ self .determine_test_application_run = True
178+ return self .test_application_problems
179+
164180 def getCoverageProblems (self ):
165181 """Verify that each rule and each exclusion has the right number of tests
166182 that applies to it. TODO: Also check that each target has the right
@@ -170,16 +186,7 @@ def getCoverageProblems(self):
170186 Returns an array of strings reporting any coverage problems if they exist,
171187 or empty list if coverage is sufficient.
172188 """
173- # First, match each test against a rule or exclusion if possible, and hang
174- # them off that rule or exclusion.
175- problems = []
176- for test in self .tests :
177- applies = self .whatApplies (test .url )
178- if applies :
179- applies .tests .append (test )
180- else :
181- problems .append ("%s: No rule or exclusion applies to test URL %s" % (
182- self .filename , test .url ))
189+ problems = self ._determineTestApplication ()
183190 # Next, make sure each rule or exclusion has sufficient tests.
184191 for rule in self .rules :
185192 needed_count = 1 + len (regex .findall ("[+*?|]" , rule .fromPattern ))
@@ -206,6 +213,22 @@ def getCoverageProblems(self):
206213 self .filename , actual_count , needed_count , exclusion ))
207214 return problems
208215
216+ def getNonmatchGroupProblems (self ):
217+ """Verify that when rules are actually applied, no non-match groups (e.g.
218+ '$1', '$2' etc.) will exist in the rewritten url"""
219+ self ._determineTestApplication ()
220+ problems = []
221+ for rule in self .rules :
222+ test_urls = map (lambda test : test .url , rule .tests )
223+ for test in rule .tests :
224+ try :
225+ replacement_url = rule .apply (test .url )
226+ except Exception , e :
227+ if ~ e .message .index ("invalid group reference" ):
228+ problems .append ("%s: Rules include non-matched groups in replacement for url: %s" % (
229+ self .filename , test .url ))
230+ return problems
231+
209232 def whatApplies (self , url ):
210233 for exclusion in self .exclusions :
211234 if exclusion .matches (url ):
0 commit comments