Second-chance checker with support for random tests. If the default comparison doesn't pass, this checker looks in the expected output string for flags that tell us to ignore the output.
| 168 | |
| 169 | |
| 170 | class IPDoctestOutputChecker(doctest.OutputChecker): |
| 171 | """Second-chance checker with support for random tests. |
| 172 | |
| 173 | If the default comparison doesn't pass, this checker looks in the expected |
| 174 | output string for flags that tell us to ignore the output. |
| 175 | """ |
| 176 | |
| 177 | random_re = re.compile(r'#\s*random\s+') |
| 178 | |
| 179 | def check_output(self, want, got, optionflags): |
| 180 | """Check output, accepting special markers embedded in the output. |
| 181 | |
| 182 | If the output didn't pass the default validation but the special string |
| 183 | '#random' is included, we accept it.""" |
| 184 | |
| 185 | # Let the original tester verify first, in case people have valid tests |
| 186 | # that happen to have a comment saying '#random' embedded in. |
| 187 | ret = doctest.OutputChecker.check_output(self, want, got, |
| 188 | optionflags) |
| 189 | if not ret and self.random_re.search(want): |
| 190 | #print >> sys.stderr, 'RANDOM OK:',want # dbg |
| 191 | return True |
| 192 | |
| 193 | return ret |
| 194 | |
| 195 | |
| 196 | class DocTestCase(doctests.DocTestCase): |