ó 2ÄÈ[c@sdZddlZddlZddlZddlZddlmZddlmZddl m Z yddl m Z Wne k r“eZ nXddlmZejdd kZejdd kZer d d%d „ƒYZd „ZeZefZeZd„Zn4ddlmZeZeZeZefZd„Ze ddƒZdefd„ƒYZ de fd„ƒYZ!d„Z"dd„Z#d„Z$d„Z%da&e'a(e)dddddgƒZ*idd 6Z+d!„Z,d"„Z-d#e.fd$„ƒYZ/dS(&ss tl;dr: all code code is licensed under simplified BSD, unless stated otherwise. Unless stated otherwise in the source files, all code is copyright 2010 David Wolever . 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 ``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 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. iÿÿÿÿN(twraps(t MethodType(t namedtuple(t OrderedDict(tTestCaseiiit InstanceTypecBseZRS((t__name__t __module__(((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR6scGstt|ŒƒS(N(tlisttzip(ta((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt8scCs|dkr|St||ƒS(N(tNoneR(tfunctinstancettype((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt make_method<s (RcCst|||ƒS(N(R(R RR((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRFstparams args kwargscBsDeZdZd„Zeddd„ƒZed„ƒZd„ZRS(sÞ 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 cOstj|||ƒS(N(t_paramt__new__(tclstargstkwargs((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRascCs%|p d}|pi}|||ŽS(s 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((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytexplicitds  cCs„t|tƒr|St|tƒr.|f}ny||ŒSWnAtk r}dt|ƒkrf‚ntd||fƒ‚nXdS(s( 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={}) safter * must bes=Parameters must be tuples, but %r is not (hint: use '(%r, )')N(t isinstanceRt string_typest TypeErrortstr(RRte((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytfrom_decoratorrs  cCsd|S(Nsparam(*%r, **%r)((tself((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt__repr__ŠsN( RRt__doc__Rt classmethodR RRR(((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRKs   tQuietOrderedDictcBs eZdZejZejZRS(su When OrderedDict is available, use it to make sure that the kwargs in doc strings are consistently ordered. (RRR tdictt__str__R(((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR"Žs c Csƒtj|ƒ}|jd dgkr+dnd}|j|}t||jƒ}|jt|ƒ|}|jt|ƒ}|jgt||jp•gƒD]'\}}||jj ||ƒf^q™ƒt g|D]\} } | ^qу} t t g|jD]%}|| krü||j|f^qüƒƒ} |rY|j d|jft|ƒfƒn| r|j d|jf| fƒn|S(s 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, ))] iRis*%ss**%s(tinspectt getargspecRtlziptlentextendR tdefaultsRtgettsetR"tsortedtappendtvarargsttupletkeywords( R tptargspect arg_offsett named_argstresultR/tnametdefaulttnt_tseen_arg_namesR1((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt"parameterized_argument_value_pairs•s&" D% +& i@cCs•t|ƒ}t|tƒrTyt|dƒ}WqTtk rPt|dƒ}qTXnt|ƒ|kr‘||d d|t|ƒ|d}n|S(sÁ A shortened repr of ``x`` which is guaranteed to be ``unicode``:: >>> short_repr("foo") u"foo" >>> short_repr("123456789", n=4) u"12...89" sutf-8tlatin1is...(treprRt bytes_typet text_typetUnicodeDecodeErrorR((txR9tx_repr((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt short_reprÐs  +c Csç|jdkrdSt||ƒ}g|D]"\}}d|t|ƒf^q)}|jjƒjdƒ\}}} d} |jdƒršd} |d }ndt|ƒr¯dp²ddj|ƒf} dj|j ƒ| | || gƒS( Ns%s=%ss tt.iÿÿÿÿs %s[with %s]t s, ( R R R<RDtlstript partitiontendswithR(tjointrstrip( R tnumR2tall_args_with_valuesR9tvtdescstfirsttnltresttsuffixR((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytdefault_doc_funcãs/! +cCsj|j}d|f}t|jƒdkrbt|jdtƒrb|dtj|jdƒ7}n||S(Ns_%siR:(RR(RRRt parameterizedt to_safe_name(R RMR2t base_namet name_suffix((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytdefault_name_func÷s   +!tnosetunittestt unittest2tnose2tpytestt_pytestcCs8|tkr.td|djtƒfƒ‚n|adS(Ns,Invalid test runner: %r (must be one of: %s)s, (t _test_runnersRRKt_test_runner_override(R7((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytset_test_runners  cCsÁtdk rtSttkr½tjƒ}x’t|ƒD]{}|d}|jjdƒj dƒd}|t kr}t |}n|t kr“|aPn|dj dƒr5daPq5q5WdantS(s  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 disocvery where the test runner should be the stack frame immediately outside. iRRFispython2.6/unittest.pyR\N( RbR t_test_runner_guesstFalseR%tstacktreversedt f_globalsR+RIt_test_runner_aliasesRaRJ(Rftrecordtframetmodule((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt detect_runners"        RVcBseZdZd d„Zd„Zd„Zd„Zd„Ze d„ƒZ e d„ƒZ e d d d„ƒZ e d „ƒZ e d „ƒZRS( sE Parameterize a test case:: class TestInt(object): @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) cCs%|j|ƒ|_|pt|_dS(N(tinput_as_callablet get_inputRUtdoc_func(RtinputRp((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt__init__>scs]ˆjƒtˆƒd‡‡‡fd†ƒ‰ˆjƒˆ_ˆˆ_dˆjfˆ_ˆS(Nc3s|ot|ƒ}|dk rFt|tƒrFtd|fƒ‚qFnˆj}x±tˆjƒD] \}}tj |ƒ}ˆj |ˆ||ƒ\}}z;|djˆ_|dk rÍt |ˆj |ƒn|VWd|dk rõt |ˆj ƒn|ˆ_Xq_WdS(Nsè@parameterized can't be used with old-style classes, but %r has an old-style class. Consider using a new-style class, or '@parameterized.expand' (see http://stackoverflow.com/q/54867/71522 for more information on old-style classes).i(RR t issubclassRRR t enumeratetparameterized_inputRRtparam_as_nose_tupletsetattrRtdelattr(t test_selfttest_clst original_docRMRR2t unbound_funct nose_tuple(Rt test_functwrapper(sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyREs$     s_parameterized_original_%s(tassert_not_in_testcase_subclassRR RoRutparameterized_funcR(RR~((RR~RsC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt__call__Bs   cs¥tˆƒ‡fd†ƒ}|jˆ||ƒ|_|}|dk rtr`tƒdkr`dn|}t||t|ƒƒ}n||f|j|j piffS(Ncsˆ|d |dŽS(Niÿÿÿÿ((R(R (sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR jsR[( RRpR R tPY2RmRRRR(RRyR RMR2t nose_funcR|t func_self((R sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRvis cCs5|jƒ}td„|Dƒƒr1tdƒ‚ndS(Ncss|]}t|tƒVqdS(N(RsR(t.0R((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pys ~ssqWarning: '@parameterized' tests won't work inside subclasses of 'TestCase' - use '@parameterized.expand' instead.(t$_terrible_magic_get_defining_classestanyt Exception(Rtparent_classes((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR€|s cCs¹tjƒ}t|ƒdkr"gS|d}|doG|ddjƒ}|o\|jdƒscgS|jdƒ\}}}|jdƒ\}}}td|d|dj|djƒS(s? Returns the set 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 iisclass t(t)t[t]( R%RfR(tstript startswithRItevalRhtf_locals(RRfRkt code_contextR:tparents((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR‡ƒs  cs8tˆƒr‡‡fd†Sˆjˆƒ‰‡fd†S(NcsˆjˆƒƒS(N(tcheck_input_values((RRq(sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR —scsˆS(N(((t input_values(sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR ™s(tcallableR•(RRq((RRqR–sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRn”s cCs>t|tƒst|ƒ}ng|D]}tj|ƒ^q%S(N(RRRR(RR–R2((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR•›sc s§d|kr8tjdtddƒˆs8|d‰q8nd|krptjdtddƒˆsp|d‰qpnˆpyt‰ˆp…t‰d‡‡‡‡fd†}|S( sm 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': ... >>> ttestcase_func_names1testcase_func_name= is deprecated; use name_func=t stacklevelittestcase_func_docs/testcase_func_doc= is deprecated; use doc_func=c s£tjƒ}|d}|dj}ˆjˆƒƒ}x^t|ƒD]P\}}ˆ|||ƒ}ˆj|||ƒ||<ˆ|||ƒ||_qBWt|_dS(Nii( R%RfR’RnRttparam_as_standalone_funcR Ret__test__( tfRRfRkt frame_localst parametersRMR2R7(RRpRqt name_func(sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytparameterized_expand_wrapperÆs   N(twarningstwarntDeprecationWarningRURZR (RRqR RptlegacyR¡((RRpRqR sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytexpand¦s         csRtˆƒ‡‡fd†ƒ}||_ˆ|_y |`Wntk rMnX|S(Ncsˆ|ˆjˆjŽS(N(RR(R (R R2(sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pytstandalone_funcÖs(RRtplace_ast __wrapped__tAttributeError(RR2R R7R§((R R2sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyR›Ôs    cCsttjdd|ƒƒS(Ns[^a-zA-Z0-9_]+R:(Rtretsub(Rts((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRWèsN(RRR R RrR‚RvR€R‡R!RnR•R¦R›RW(((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyRV)s  '    -((0R R«tsysR%R¢t functoolsRttypesRt collectionsRRtMaybeOrderedDictt ImportErrorR#R\Rt version_infotPY3RƒRR'RR@RtbytesR?RR tunicodet basestringRRR"R<RDRURZRbReRdR,RaRiRcRmtobjectRV(((sC/tmp/pip-build-fiC0ax/numpy/numpy/testing/_private/parameterized.pyt sT           C ;