1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """a set of helper functions for filters..."""
23
24 import operator
25
26
28 """checks whether countstr occurs the same number of times in str1 and str2"""
29 return str1.count(countstr) == str2.count(countstr)
30
31
33 """returns whether the result of func is the same for str1 and str2"""
34 return func(str1, *args) == func(str2, *args)
35
36
38 """checks whether each element in countlist occurs the same number of times in str1 and str2"""
39 return reduce(operator.and_, [countmatch(str1, str2, countstr) for countstr in countlist], True)
40
41
43 """checks whether the results of each func in funclist match for str1 and str2"""
44 return reduce(operator.and_, [funcmatch(str1, str2, funcstr) for funcstr in funclist], True)
45
46
48 """returns the number of characters in str1 that pass func"""
49 return len(filter(func, str1))
50
51
53 """returns a version of the testmethod that operates on filtered strings using strfilter"""
54
55 def filteredmethod(str1, str2):
56 return testmethod(strfilter(str1), strfilter(str2))
57 filteredmethod.__doc__ = testmethod.__doc__
58 filteredmethod.name = getattr(testmethod, 'name', testmethod.__name__)
59 return filteredmethod
60
61
63 """passes str1 through a list of filters"""
64 for strfilter in strfilters:
65 str1 = strfilter(str1, *args)
66 return str1
67
68
70 """returns a version of the testmethod that operates on filtered strings using strfilter"""
71
72 def filteredmethod(str1, str2):
73 return testmethod(multifilter(str1, strfilters), multifilter(str2, strfilters))
74 filteredmethod.__doc__ = testmethod.__doc__
75 filteredmethod.name = getattr(testmethod, 'name', testmethod.__name__)
76 return filteredmethod
77