zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
U
P±dÌ@ã@sÌdZddlZddlZddlZddlmZddlmZddlm    Z    ddl
m Z e    ddƒZ Gd    d„de ƒZ d
d „Zd d d„Zdd„Zdd„ZdadaedddddgƒZddiZdd„Zdd„ZGdd„dƒZdS)!an
tl;dr: all code is licensed under simplified BSD, unless stated otherwise.
 
Unless stated otherwise in the source files, all code is copyright 2010 David
Wolever <david@wolever.net>. All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 
   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
 
   2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
 
THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of David Wolever.
 
éN)Úwraps)Ú
MethodType)Ú
namedtuple)ÚTestCaseÚparamz args kwargsc@s:eZdZdZdd„Zed dd„ƒZedd„ƒZd    d
„ZdS) raÞ Represents a single parameter to a test case.
 
        For example::
 
            >>> p = param("foo", bar=16)
            >>> p
            param("foo", bar=16)
            >>> p.args
            ('foo', )
            >>> p.kwargs
            {'bar': 16}
 
        Intended to be used as an argument to ``@parameterized``::
 
            @parameterized([
                param("foo", bar=16),
            ])
            def test_stuff(foo, bar=16):
                pass
        cOst |||¡S©N)Ú_paramÚ__new__©ÚclsÚargsÚkwargs©rú[d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/testing/_private/parameterized.pyr    Bsz param.__new__NcCs|pd}|pi}|||ŽS)a Creates a ``param`` by explicitly specifying ``args`` and
            ``kwargs``::
 
                >>> param.explicit([1,2,3])
                param(*(1, 2, 3))
                >>> param.explicit(kwargs={"foo": 42})
                param(*(), **{"foo": "42"})
            rrr
rrrÚexplicitEs
zparam.explicitc
Cspt|tƒr|St|tfƒr |f}z
||ŽWStk
rj}z"dt|ƒkrJ‚td||fƒ‚W5d}~XYnXdS)a( Returns an instance of ``param()`` for ``@parameterized`` argument
            ``args``::
 
                >>> param.from_decorator((42, ))
                param(args=(42, ), kwargs={})
                >>> param.from_decorator("foo")
                param(args=("foo", ), kwargs={})
            zafter * must bez=Parameters must be tuples, but %r is not (hint: use '(%r, )')N)Ú
isinstancerÚstrÚ    TypeError)r r ÚerrrÚfrom_decoratorSs
 
 
 ÿÿzparam.from_decoratorcCsd|S)Nzparam(*%r, **%r)r)ÚselfrrrÚ__repr__kszparam.__repr__)NN)    Ú__name__Ú
__module__Ú __qualname__Ú__doc__r    Ú classmethodrrrrrrrr,s 
csøt |¡}|jdd…dgkr"dnd}|j|d…}tt|ˆjƒƒ}|jt|ƒ|d…}ˆjt|ƒd…}| ‡fdd„t||jp†gƒDƒ¡dd„|Dƒ‰tt    ‡‡fd    d„ˆj
Dƒƒƒ}|rÚ|  d
|j ft |ƒf¡|rô|  d |jf|f¡|S) a Return tuples of parameterized arguments and their values.
 
        This is useful if you are writing your own doc_func
        function and need to know the values for each parameter name::
 
            >>> def func(a, foo=None, bar=42, **kwargs): pass
            >>> p = param(1, foo=7, extra=99)
            >>> parameterized_argument_value_pairs(func, p)
            [("a", 1), ("foo", 7), ("bar", 42), ("**kwargs", {"extra": 99})]
 
        If the function's first argument is named ``self`` then it will be
        ignored::
 
            >>> def func(self, a): pass
            >>> p = param(1)
            >>> parameterized_argument_value_pairs(func, p)
            [("a", 1)]
 
        Additionally, empty ``*args`` or ``**kwargs`` will be ignored::
 
            >>> def func(foo, *args): pass
            >>> p = param(1)
            >>> parameterized_argument_value_pairs(func, p)
            [("foo", 1)]
            >>> p = param(1, 16)
            >>> parameterized_argument_value_pairs(func, p)
            [("foo", 1), ("*args", (16, ))]
    Nérrcs"g|]\}}|ˆj ||¡f‘qSr)r Úget)Ú.0ÚnameÚdefault)ÚprrÚ
<listcomp>•sÿz6parameterized_argument_value_pairs.<locals>.<listcomp>cSsh|] \}}|’qSrr)rÚnÚ_rrrÚ    <setcomp>›sz5parameterized_argument_value_pairs.<locals>.<setcomp>cs"g|]}|ˆkr|ˆj|f‘qSr)r )rr ©r"Zseen_arg_namesrrr#œsþz*%sz**%s)ÚinspectÚ
getargspecr ÚlistÚzipÚlenÚextendÚdefaultsÚdictÚsortedr ÚappendÚvarargsÚtupleÚkeywords)Úfuncr"ZargspecZ
arg_offsetZ
named_argsÚresultr2r4rr'rÚ"parameterized_argument_value_pairsos$
ýþ
r7é@cCs|t|ƒ}t|tƒr@zt|dƒ}Wntk
r>t|dƒ}YnXt|ƒ|krx|d|d…d|t|ƒ|dd…}|S)zÁ A shortened repr of ``x`` which is guaranteed to be ``unicode``::
 
            >>> short_repr("foo")
            u"foo"
            >>> short_repr("123456789", n=4)
            u"12...89"
    zutf-8Úlatin1Néz...)ÚreprrÚbytesrÚUnicodeDecodeErrorr,)Úxr$Zx_reprrrrÚ
short_reprªs    
 ,r?c
Cs|jdkrdSt||ƒ}dd„|Dƒ}|j ¡ d¡\}}}d}| d¡rZd}|dd…}dt|ƒrhdpjdd     |¡f}    d | ¡|    |||g¡S)
NcSs"g|]\}}|›dt|ƒ›‘qS)ú=)r?)rr$Úvrrrr#Äsz$default_doc_func.<locals>.<listcomp>Ú
ÚÚ.éÿÿÿÿz %s[with %s]ú ú, )rr7ÚlstripÚ    partitionÚendswithr,ÚjoinÚrstrip)
r5Únumr"Zall_args_with_valuesZdescsÚfirstÚnlÚrestÚsuffixr rrrÚdefault_doc_func½s
 
 
 rRcCsP|j}d|f}t|jƒdkrHt|jdtfƒrH|dt |jd¡7}||S)Nz_%srr%)rr,r rrÚ parameterizedÚ to_safe_name)r5rMr"Ú    base_nameZ name_suffixrrrÚdefault_name_funcÑs
 
 rVZnoseFÚunittestZ    unittest2Znose2ZpytestZ_pytestcCs&|tkrtd|d t¡fƒ‚|adS)Nz,Invalid test runner: %r (must be one of: %s)rG)Ú _test_runnersrrKÚ_test_runner_override)r rrrÚset_test_runnerás ÿÿrZcCsptdk    r tStdkrlt ¡}t|ƒD]B}|d}|j d¡ d¡d}|tkrVt|}|t    kr$|aqlq$datS)a
 Guess which test runner we're using by traversing the stack and looking
        for the first matching module. This *should* be reasonably safe, as
        it's done during test discovery where the test runner should be the
        stack frame immediately outside. NFrrrD)
rYÚ_test_runner_guessr(ÚstackÚreversedÚ    f_globalsrrIÚ_test_runner_aliasesrX)r\ÚrecordÚframeÚmodulerrrÚ detect_runnerês rcc@sxeZdZdZddd„Zdd„Zdd„Zd    d
„Zd d „Ze    d d„ƒZ
e    dd„ƒZ e    ddd„ƒZ e    dd„ƒZ e    dd„ƒZdS)rSa= Parameterize a test case::
 
            class TestInt:
                @parameterized([
                    ("A", 10),
                    ("F", 15),
                    param("10", 42, base=42)
                ])
                def test_int(self, input, expected, base=16):
                    actual = int(input, base=base)
                    assert_equal(actual, expected)
 
            @parameterized([
                (2, 3, 5)
                (3, 5, 8),
            ])
            def test_add(a, b, expected):
                assert_equal(a + b, expected)
        NcCs| |¡|_|pt|_dSr)Úinput_as_callableÚ    get_inputrRÚdoc_func)rÚinputrfrrrÚ__init__s zparameterized.__init__csDˆ ¡tˆƒd‡‡‡fdd„    ƒ‰ˆ ¡ˆ_ˆˆ_dˆjfˆ_ˆS)Nc
3s’|o
t|ƒ}ˆj}tˆjƒD]p\}}t |¡}ˆ |ˆ||¡\}}z,|djˆ_|dk    rft    |ˆj|ƒ|VW5|dk    r„t|ˆjƒ|ˆ_XqdS)Nr)
ÚtyperÚ    enumerateÚparameterized_inputrrÚparam_as_nose_tupleÚdelattrrÚsetattr)Ú    test_selfZtest_clsZ original_docrMr r"Ú unbound_funcZ
nose_tuple©rÚ    test_funcÚwrapperrrrss 
 
 z'parameterized.__call__.<locals>.wrapperz_parameterized_original_%s)N)Úassert_not_in_testcase_subclassrrerkZparameterized_funcr)rrrrrqrÚ__call__s
zparameterized.__call__csVtˆƒ‡fdd„ƒ}| ˆ||¡|_|}|dk    r:t||ƒ}||f|j|jpNiffS)Ncsˆ|dd…|dŽS)NrEr)r ©r5rrÚ<lambda>8óz3parameterized.param_as_nose_tuple.<locals>.<lambda>)rrfrrr r )rror5rMr"Z    nose_funcrprrvrrl7s 
z!parameterized.param_as_nose_tuplecCs&| ¡}tdd„|Dƒƒr"tdƒ‚dS)Ncss|]}t|tƒVqdSr)Ú
issubclassr)rr rrrÚ    <genexpr>Dsz@parameterized.assert_not_in_testcase_subclass.<locals>.<genexpr>zqWarning: '@parameterized' tests won't work inside subclasses of 'TestCase' - use '@parameterized.expand' instead.)Ú$_terrible_magic_get_defining_classesÚanyÚ    Exception)rZparent_classesrrrrtBsz-parameterized.assert_not_in_testcase_subclasscCsŠt ¡}t|ƒdkrgS|d}|do6|dd ¡}|rF| d¡sJgS| d¡\}}}| d¡\}}}td|d|dj|djƒS)a@ Returns the list of parent classes of the class currently being defined.
            Will likely only work if called from the ``parameterized`` decorator.
            This function is entirely @brandon_rhodes's fault, as he suggested
            the implementation: http://stackoverflow.com/a/8793684/71522
            érzclass ú(ú)ú[ú])    r(r\r,ÚstripÚ
startswithrIÚevalr^Úf_locals)rr\raÚ code_contextr%Úparentsrrrr{Is z2parameterized._terrible_magic_get_defining_classescs,tˆƒr‡‡fdd„Sˆ ˆ¡‰‡fdd„S)Ncs ˆ ˆƒ¡Sr)Úcheck_input_valuesr©r rgrrrw]rxz1parameterized.input_as_callable.<locals>.<lambda>csˆSrrr)Ú input_valuesrrrw_rx)Úcallabler‰rŠr)r rgr‹rrdZs
zparameterized.input_as_callablecCs t|tƒst|ƒ}dd„|DƒS)NcSsg|]}t |¡‘qSr)rr)rr"rrrr#jsz4parameterized.check_input_values.<locals>.<listcomp>)rr*)r r‹rrrr‰as
z parameterized.check_input_valuesc spd|kr$tjdtddˆs$|d‰d|krHtjdtddˆsH|d‰ˆpNt‰ˆpVt‰d
‡‡‡‡fdd    „    }|S) am A "brute force" method of parameterizing test cases. Creates new
            test cases and injects them into the namespace that the wrapped
            function is being defined in. Useful for parameterizing tests in
            subclasses of 'UnitTest', where Nose test generators don't work.
 
            >>> @parameterized.expand([("foo", 1, 2)])
            ... def test_add1(name, input, expected):
            ...     actual = add1(input)
            ...     assert_equal(actual, expected)
            ...
            >>> locals()
            ... 'test_add1_foo_0': <function ...> ...
            >>>
            Ztestcase_func_namez1testcase_func_name= is deprecated; use name_func=r:)Ú
stacklevelZtestcase_func_docz/testcase_func_doc= is deprecated; use doc_func=Nc    srt ¡}|d}|dj}ˆ ˆ¡ƒ}t|ƒD]8\}}ˆ|||ƒ}ˆ |||¡||<ˆ|||ƒ||_q.d|_dS)NrrF)r(r\r†rdrjÚparam_as_standalone_funcrZ__test__)    ÚfÚinstancer\raZ frame_localsÚ
parametersrMr"r ©r rfrgÚ    name_funcrrÚparameterized_expand_wrapperŒs
  z:parameterized.expand.<locals>.parameterized_expand_wrapper)N)ÚwarningsÚwarnÚDeprecationWarningrRrV)r rgr“rfÚlegacyr”rr’rÚexpandls$ÿÿ zparameterized.expandcsDtˆƒ‡‡fdd„ƒ}||_ˆ|_z|`Wntk
r>YnX|S)Ncsˆ|ˆjˆjŽSr)r r )Úa©r5r"rrÚstandalone_funcœsz?parameterized.param_as_standalone_func.<locals>.standalone_func)rrZplace_asÚ __wrapped__ÚAttributeError)r r"r5r rœrr›rrŽšsz&parameterized.param_as_standalone_funccCstt dd|¡ƒS)Nz[^a-zA-Z0-9_]+r%)rÚreÚsub)r ÚsrrrrT®szparameterized.to_safe_name)N)NN)rrrrrhrurlrtr{rrdr‰r™rŽrTrrrrrSs 
 
 
 
 -
rS)r8)rrŸr(r•Ú    functoolsrÚtypesrÚ collectionsrrWrrrr7r?rRrVrYr[ÚsetrXr_rZrcrSrrrrÚ<module>s,     
C;
    ÿ