MCPcopy Index your code
hub / github.com/RustPython/RustPython / parameterize

Function parameterize

Lib/test/test_email/__init__.py:76–167  ·  view source on GitHub ↗

A test method parameterization class decorator. Parameters are specified as the value of a class attribute that ends with the string '_params'. Call the portion before '_params' the prefix. Then a method to be parameterized must have the same prefix, the string '_as_', and an arbi

(cls)

Source from the content-addressed store, hash-verified

74
75
76def parameterize(cls):
77 """A test method parameterization class decorator.
78
79 Parameters are specified as the value of a class attribute that ends with
80 the string '_params'. Call the portion before '_params' the prefix. Then
81 a method to be parameterized must have the same prefix, the string
82 '_as_', and an arbitrary suffix.
83
84 The value of the _params attribute may be either a dictionary or a list.
85 The values in the dictionary and the elements of the list may either be
86 single values, or a list. If single values, they are turned into single
87 element tuples. However derived, the resulting sequence is passed via
88 *args to the parameterized test function.
89
90 In a _params dictionary, the keys become part of the name of the generated
91 tests. In a _params list, the values in the list are converted into a
92 string by joining the string values of the elements of the tuple by '_' and
93 converting any blanks into '_'s, and this become part of the name.
94 The full name of a generated test is a 'test_' prefix, the portion of the
95 test function name after the '_as_' separator, plus an '_', plus the name
96 derived as explained above.
97
98 For example, if we have:
99
100 count_params = range(2)
101
102 def count_as_foo_arg(self, foo):
103 self.assertEqual(foo+1, myfunc(foo))
104
105 we will get parameterized test methods named:
106 test_foo_arg_0
107 test_foo_arg_1
108 test_foo_arg_2
109
110 Or we could have:
111
112 example_params = {'foo': ('bar', 1), 'bing': ('bang', 2)}
113
114 def example_as_myfunc_input(self, name, count):
115 self.assertEqual(name+str(count), myfunc(name, count))
116
117 and get:
118 test_myfunc_input_foo
119 test_myfunc_input_bing
120
121 Note: if and only if the generated test name is a valid identifier can it
122 be used to select the test individually from the unittest command line.
123
124 The values in the params dict can be a single value, a tuple, or a
125 dict. If a single value of a tuple, it is passed to the test function
126 as positional arguments. If a dict, it is a passed via **kw.
127
128 """
129 paramdicts = {}
130 testers = collections.defaultdict(list)
131 for name, attr in cls.__dict__.items():
132 if name.endswith('_params'):
133 if not hasattr(attr, 'keys'):

Callers

nothing calls this directly

Calls 13

hasattrFunction · 0.85
strFunction · 0.85
lenFunction · 0.85
getattrFunction · 0.85
setattrFunction · 0.85
itemsMethod · 0.45
endswithMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45
splitMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected