U kf:/@sUddlmZddlmZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZd d lmZd dlmZd dlmZddlmZeZdadadadZdadadadadZdZde d<ej!rd dl"m#Z#de d<nGdddZ$e$Z%e dedefdZ&ddddd d d!d"d#d$d%Z'd&d'd(d)Z(Gd*d+d+Z)dBd,d-Z*dCd/d0Z+d1d1d1d2d3d4Z,d!d5d6d7Z-d1d5d8d9Z.Gd:d;d;Z/e/Z0Gdd?Z2d@dAZ3dS)D) annotations) NamespaceN)Any)Callable)Iterable)NoReturn)Optional)Tuple)TypeVar)Union)mock) requirementsfail)utilFmainroptions)FixtureFunctionsr_fixture_functionsc@sXeZdZddZddZeddZddZd d Zd d Z d dZ ddZ ddZ dS)_NullFixtureFunctionscCs dd}|S)NcSs|SNfnrrI/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/testing/config.pygo5sz1_NullFixtureFunctions._null_decorator..gor)selfrrrr_null_decorator4sz%_NullFixtureFunctions._null_decoratorcOstSr) Exceptionrargkwrrrskip_test_exception:sz)_NullFixtureFunctions.skip_test_exceptioncCstSr)r ZMockrrrr add_to_marker=sz#_NullFixtureFunctions.add_to_markercCs|Srrr%rrrmark_base_test_classAsz*_NullFixtureFunctions.mark_base_test_classcOs|Srr')rZarg_setsr#rrr combinationsDsz"_NullFixtureFunctions.combinationscGs|Srr')r parametersrrr param_identGsz!_NullFixtureFunctions.param_identcOs|Srr'r!rrrfixtureJsz_NullFixtureFunctions.fixturecCsdSrrr%rrrget_current_test_nameMsz+_NullFixtureFunctions.get_current_test_namecCs|Srr)rrrrr async_testPsz _NullFixtureFunctions.async_testN) __name__ __module__ __qualname__rr$propertyr&r(r)r+r,r-r.rrrrr3s r_FN.)bound)argnamesid_zUnion[Any, Tuple[Any, ...]]z Optional[str]strzCallable[[_FN], _FN])combr5r6r#returncOstj|||d|S)a Deliver multiple versions of a test based on positional combinations. This is a facade over pytest.mark.parametrize. :param \*comb: argument combinations. These are tuples that will be passed positionally to the decorated function. :param argnames: optional list of argument names. These are the names of the arguments in the test function that correspond to the entries in each argument tuple. pytest.mark.parametrize requires this, however the combinations function will derive it automatically if not present by using ``inspect.getfullargspec(fn).args[1:]``. Note this assumes the first argument is "self" which is discarded. :param id\_: optional id template. This is a string template that describes how the "id" for each parameter set should be defined, if any. The number of characters in the template should match the number of entries in each argument tuple. Each character describes how the corresponding entry in the argument tuple should be handled, as far as whether or not it is included in the arguments passed to the function, as well as if it is included in the tokens used to create the id of the parameter set. If omitted, the argument combinations are passed to parametrize as is. If passed, each argument combination is turned into a pytest.param() object, mapping the elements of the argument tuple to produce an id based on a character value in the same position within the string template using the following scheme:: i - the given argument is a string that is part of the id only, don't pass it as an argument n - the given argument should be passed and it should be added to the id by calling the .__name__ attribute r - the given argument should be passed and it should be added to the id by calling repr() s - the given argument should be passed and it should be added to the id by calling str() a - (argument) the given argument should be passed and it should not be used to generated the id e.g.:: @testing.combinations( (operator.eq, "eq"), (operator.ne, "ne"), (operator.gt, "gt"), (operator.lt, "lt"), id_="na" ) def test_operator(self, opfunc, name): pass The above combination will call ``.__name__`` on the first member of each tuple and use that as the "id" to pytest.param(). r6r5)rr))r5r6r8r#rrrr)[sDr)zIterable[Tuple[Any, ...]]) arg_iterablecKs t||S)z+As combination, but takes a single iterable)r))r;r#rrrcombinations_listsr<c@seZdZdZddZejr*dddddZed d Z d d Z d dZ ddZ ddZ ddddZeddZeddZdS) Variation_name_argnamecCs*||_||_|D]}t||||kqdSr)r?r@setattr)rcaseargname case_namescasenamerrr__init__szVariation.__init__r7bool)keyr9cCsdSrr)rrHrrr __getattr__zVariation.__getattr__cCs|jSrr?r%rrrnameszVariation.namecCs |j|jkSrr>r%rrr__bool__szVariation.__bool__cCs | Sr)rMr%rrr __nonzero__szVariation.__nonzero__cCs|jd|jS)N=)r@r?r%rrr__str__szVariation.__str__cCst|Srr7r%rrr__repr__szVariation.__repr__rr9cCstd|dS)NzUnknown rr%rrrrszVariation.failcCs|jSr)rL)cls variationrrridfnszVariation.idfncs>fdd|DttfdtifddDS)Ncs,g|]$}|dkrn|dkr$dn|qS)TFnot_r).0c)rCrr sz,Variation.generate_cases.. __slots__csg|]}|qSrr)rXrErCrDtyprrrZs)typer=tuple)rTrCcasesrr\rgenerate_casess zVariation.generate_casesN)r/r0r1r[rFtyping TYPE_CHECKINGrIr2rLrMrNrPrRr classmethodrVrarrrrr=s  r=cCsvt|r.|j}|d}t||dd}|S|}dd|D}t|dd|D}tddt||Dd|d S) aa helper around testing.combinations that provides a single namespace that can be used as a switch. e.g.:: @testing.variation("querytyp", ["select", "subquery", "legacy_query"]) @testing.variation("lazy", ["select", "raise", "raise_on_sql"]) def test_thing( self, querytyp, lazy, decl_base ): class Thing(decl_base): __tablename__ = 'thing' # use name directly rel = relationship("Rel", lazy=lazy.name) # use as a switch if querytyp.select: stmt = select(Thing) elif querytyp.subquery: stmt = select(Thing).subquery() elif querytyp.legacy_query: stmt = Session.query(Thing) else: querytyp.fail() The variable provided is a slots object of boolean variables, as well as the name of the case itself under the attribute ".name" Ncss |jVdSr)param)rrequestrrrrszvariation..gocSs.g|]&}t|tr"t|dkr"|n|dfqS)rN) isinstancer_len)rXentryrrrrZs  zvariation..cSsg|] \}}|qSrr)rXrYlrrrrZscSs2g|]*\}\}}|dk r$|j||fn|j|fqSrrK)rXrUrBZ limitationrrrrZs iar:)inspect isfunctionr/variation_fixturer=rar)zip)Z argname_or_fnr`rCrZcases_plus_limitationsZ variationsrrrrUs0$     rUfunctioncCstt||tj|dS)N)paramsZidsscope)r,r=rarV)rCr`rrrrrrn*s  rnr)r"r#r9cOs tj||Sr)rr,)r"r#rrrr,2sr,rScCstSr)rr-rrrrr-6sr-cCstSr)rr(rrrrr(:sr(c@seZdZdddddZdS) _AddToMarkerr7r)attrr9cCs ttj|Sr)getattrrr&)rrtrrrrI?sz_AddToMarker.__getattr__N)r/r0r1rIrrrrrs>srsc@seZdZddZeZeZddZ e ddZ e ddZ e d d Z e d d Ze d dZe ddZe ddZe ddZddZdS)ConfigcCsT||||_||_||_||_d|_d|_|jjoLt |j j dd |_dS)N test_schema test_schema_2Zasync_fallbackF) _set_namedbdb_optsr file_configrwrxdialectis_asyncrZasboolurlqueryget)rrzr{rr|rrrrFGs  zConfig.__init__cCs`|jjr dnd}|jjrHddd|jjD}d|j|j||f|_nd|j|j|f|_dS)NZ_async.css|]}t|VqdSrrQ)rXtokrrr Zsz#Config._set_name..z %s+%s%s_[%s]z%s+%s%s)r}r~Zserver_version_infojoinrLZdriver)rrzsuffixZsvirrrryWs zConfig._set_namecCs(t||||}tp|ja|j||S)zadd a config as one of the global configs. If there are no configs set up yet, this config also gets set as the "_current". )rv any_asyncr~_configsadd)rTrzr{rr|cfgrrrregister_s   zConfig.registercCs.|a|jja|ja|ja|ja|j|_adSr)_currentrzrdb_urlr{rwrxrTconfig namespacerrrset_as_currentrs zConfig.set_as_currentcCs,ts td|t|tjtjtj|dS)Nz*Can't push without a default Config set up)rAssertionErrorpushrvr{rr|)rTrzrrrr push_engine|s zConfig.push_enginecCs|jt|||dSr)_stackappendrrrrrrrs z Config.pushcCs(|jr$|jd}|jd=|||dS)N)rr)rTrrrrrpops z Config.popcCs&|jr"||jd||jdS)Nr)rrclear)rTrrrrresetsz Config.resetcCs|jSr)r)rTrrr all_configsszConfig.all_configsccs|D] }|jVqdSr)rrz)rTrrrrall_dbss zConfig.all_dbscCs t|dSr) skip_test)rmsgrrrrszConfig.skip_testN)r/r0r1rF collectionsdequersetrryrdrrrrrrrrrrrrrrvFs*         rvcCst|dSr)rr$)rrrrrsrcCs t|Sr)rr.rrrrr.sr.)N)rp)4 __future__rargparserrrlrbrrrrrr r r rr rZ _requirementsrrZSuiteRequirementsrzrr{r|rwrxrridentr__annotations__rcZplugin.plugin_baserrrr3r)r<r=rUrnr,r-r(rsr&rvrr.rrrr sb                 "I6 K `