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
27 """checks whether countstr occurs the same number of times in str1 and str2"""
28 return str1.count(countstr) == str2.count(countstr)
29
31 """returns whether the result of func is the same for str1 and str2"""
32 return func(str1, *args) == func(str2, *args)
33
35 """checks whether each element in countlist occurs the same number of times in str1 and str2"""
36 return reduce(operator.and_, [countmatch(str1, str2, countstr) for countstr in countlist], True)
37
39 """checks whether the results of each func in funclist match for str1 and str2"""
40 return reduce(operator.and_, [funcmatch(str1, str2, funcstr) for funcstr in funclist], True)
41
43 """returns the number of characters in str1 that pass func"""
44 return len(filter(func, str1))
45
47 """returns a version of the testmethod that operates on filtered strings using strfilter"""
48 def filteredmethod(str1, str2):
49 return testmethod(strfilter(str1), strfilter(str2))
50 filteredmethod.__doc__ = testmethod.__doc__
51 filteredmethod.name = getattr(testmethod, 'name', testmethod.__name__)
52 return filteredmethod
53
55 """passes str1 through a list of filters"""
56 for strfilter in strfilters:
57 str1 = strfilter(str1, *args)
58 return str1
59
61 """returns a version of the testmethod that operates on filtered strings using strfilter"""
62 def filteredmethod(str1, str2):
63 return testmethod(multifilter(str1, strfilters), multifilter(str2, strfilters))
64 filteredmethod.__doc__ = testmethod.__doc__
65 filteredmethod.name = getattr(testmethod, 'name', testmethod.__name__)
66 return filteredmethod
67