(f)
| 21 | |
| 22 | |
| 23 | def read_tests(f): |
| 24 | basename, _ = path.splitext(path.basename(f)) |
| 25 | tests = [] |
| 26 | for lineno, line in enumerate(open(f), 1): |
| 27 | fields = filter(None, map(str.strip, line.split('\t'))) |
| 28 | if not (4 <= len(fields) <= 5) \ |
| 29 | or 'E' not in fields[0] or fields[0][0] == '#': |
| 30 | continue |
| 31 | |
| 32 | opts, pat, text, sgroups = fields[0:4] |
| 33 | groups = [] # groups as integer ranges |
| 34 | if sgroups == 'NOMATCH': |
| 35 | groups = [None] |
| 36 | elif ',' in sgroups: |
| 37 | noparen = map(lambda s: s.strip('()'), sgroups.split(')(')) |
| 38 | for g in noparen: |
| 39 | s, e = map(str.strip, g.split(',')) |
| 40 | if s == '?' and e == '?': |
| 41 | groups.append(None) |
| 42 | else: |
| 43 | groups.append((int(s), int(e))) |
| 44 | else: |
| 45 | # This skips tests that should result in an error. |
| 46 | # There aren't many, so I think we can just capture those |
| 47 | # manually. Possibly fix this in future. |
| 48 | continue |
| 49 | |
| 50 | if pat == 'SAME': |
| 51 | pat = tests[-1][1] |
| 52 | if '$' in opts: |
| 53 | pat = pat.decode('string_escape') |
| 54 | text = text.decode('string_escape') |
| 55 | if 'i' in opts: |
| 56 | pat = '(?i)%s' % pat |
| 57 | |
| 58 | name = '%s_%d' % (basename, lineno) |
| 59 | tests.append((name, pat, text, groups)) |
| 60 | return tests |
| 61 | |
| 62 | |
| 63 | def test_tostr(t): |
no test coverage detected