3 öLÖj�“ãœ@sl dZedkredƒ‚ddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl!Z"ddl#Z#ddl$m%Z%yddl&Z&ddl'Z'Wnek �rBdZ&dZ'YnXy ddl(Z)Wnek �rjdZ)YnXy ddl*Z*Wnek �r’dZ*YnXy ddl+Z+Wnek �rºdZ+YnXy ddl,Z,Wnek �râdZ,YnXy ddl-Z-Wnek �r dZ-YnXy ddl.Z.Wnek �r2dZ.YnXy ddl/Z/Wnek �rZdZ/YnXddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbg\Z0Gdcd „d e1ƒZ2Gddd „d e2ƒZ3Gded„de2ƒZ4Gdfd„de j5ƒZ6ej7�dhdhdi„ƒZ8�difdkœdld„Z9dmdn„Z:dodp„Z;dqd=„Z„Z=ffdjfdsd„Z>dtd9„Z?dZ@dZAdaBdaCdZDdjZEdaFdud„ZGdvd„ZHdwd„ZIdxdy„ZJejjKdzƒ�r.�djd{d|„ZLd}d~„ZMdd€„ZNd�d‚„ZOdƒd„„ZPnejQZMejRZNd…d‚„ZOd†d„„ZPd‡d„ZQdˆd‰„ZRdŠd„ZSd‹dŒ„ZTd�d„ZUdŽd�„ZVd�d#„ZW�dkd‘d$„ZXd’d“„ZYd”d%„ZZd•d&„Z[d–d'„Z\�dld—d(„Z]d˜Z^d™Z_ej`ejafdšdJ„Zbe^fd›dK„ZcdœdM„Zdd�dž„ZeeeƒZfdŸd „Zg�doZh�drZie jjekjld¤ƒjKd¥ƒd¦ƒZme jje*d§ƒZne jje+d¨ƒZoe jje,d©ƒZpe jje-dªƒZqejjKd«ƒZrejsd¬ƒZtetdk �oxetdkZuejd­k�r–eu�r�d®nd¯ZvndZvejwd«k�r¬d°Zxnd±Zxd²jyexejzƒƒZxdZ{xL�dsD]BZ|yej}ej~e|ƒƒe|k�rìe‚Wnek �rYnXe|Z{P�qÌWexd¾Z€ejd¿k�r:ddl�Z�e�j‚dÀe€ƒZ€ejƒƒZ„dZ…ejwdÁk�r¦ej†ƒjdÂk�rèexdÃZ…ye…j‡e„ƒWneˆk �rŽYnXe‰dÄe…e„fƒdZ…nBejd¿k�rèydÅjŠe„ƒWn&e‹k �ræexdÆjŠe„dǃZ…YnXdZŒxF�dtD]dY„ƒZ÷�d?�d@„Zøe jùe•e�dAƒ�dBƒZú�dC�dD„Zû�dE�dF„ZüG�dGdP„dPejýjþƒZÿG�dHd[„d[e¥ƒ�Zd�a�dId!„�Z�dJd2„�Zd�a�dK�dL„�Z�dMd;„�Z�dN�dO„�Z�dPd"„�Zf�dQœ�dRd?„�Z dfff�dSd@„�Z G�dTd]„d]ƒ�Z �dU�dV„�Z �dW�dX„�Z ff�dY�dZ„�Zgf�d[da„�Zd�a�d\dG„�Zej7�d]�d^„ƒ�Z�d_db„�ZG�d`�da„�daƒ�ZG�db�dc„�dcƒ�Zej7�dd�de„ƒ�Z�df�dg„�ZdS(‚z7Supporting definitions for the Python regression tests.z test.supportz.support must be imported from the test packageéNé)Úget_test_runnerÚ PIPE_MAX_SIZEÚverboseÚ max_memuseÚ use_resourcesÚfailfastÚErrorÚ TestFailedÚ TestDidNotRunÚResourceDeniedÚ import_moduleÚimport_fresh_moduleÚ CleanImportÚunloadÚforgetÚrecord_original_stdoutÚget_original_stdoutÚcaptured_stdoutÚcaptured_stdinÚcaptured_stderrÚTESTFNÚSAVEDCWDÚunlinkÚrmtreeÚtemp_cwdÚfindfileÚcreate_empty_fileÚ can_symlinkÚfs_is_case_insensitiveÚis_resource_enabledÚrequiresÚrequires_freebsd_versionÚrequires_linux_versionÚrequires_mac_verÚrequires_hashdigestÚcheck_syntax_errorÚTransientResourceÚtime_outÚsocket_peer_resetÚioerror_peer_resetÚtransient_internetÚBasicTestRunnerÚ run_unittestÚ run_doctestÚskip_unless_symlinkÚ requires_gzipÚ requires_bz2Ú requires_lzmaÚ bigmemtestÚbigaddrspacetestÚ cpython_onlyÚ get_attributeÚrequires_IEEE_754Úskip_unless_xattrÚ requires_zlibÚanticipate_failureÚload_package_testsÚdetect_api_mismatchÚ check__all__Úrequires_android_levelÚrequires_multiprocessing_queueÚ is_jythonÚ is_androidÚcheck_impl_detailÚ unix_shellÚsetswitchintervalÚHOSTÚ IPV6_ENABLEDÚfind_unused_portÚ bind_portÚopen_urlresourceÚbind_unix_socketÚ temp_umaskÚ reap_childrenÚ TestHandlerÚthreading_setupÚthreading_cleanupÚ reap_threadsÚ start_threadsÚcheck_warningsÚcheck_no_resource_warningÚEnvironmentVarGuardÚrun_with_localeÚ swap_itemÚ swap_attrÚMatcherÚ set_memlimitÚSuppressCrashReportÚsortdictÚ run_with_tzÚPGOÚmissing_compiler_executableÚfd_countc@seZdZdZdS)r z*Base class for regression test exceptions.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rdrdú-/usr/lib64/python3.6/test/support/__init__.pyr |sc@seZdZdZdS)r z Test failed.N)r`rarbrcrdrdrdrer sc@seZdZdZdS)r zTest did not run any subtests.N)r`rarbrcrdrdrdrer ‚sc@seZdZdZdS)r zàTest skipped because it requested a disallowed resource. This is raised when a test calls requires() for a resource that has not be enabled. It is used to distinguish between expected and unexpected skips. N)r`rarbrcrdrdrdrer …sTc cs8|r.tjƒ�tjddtƒdVWdQRXndVdS)zžContext manager to suppress package and module deprecation warnings when importing them. If ignore is False, this context manager has no effect. Úignorez.+ (module|package)N)ÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarning)rfrdrdreÚ_ignore_deprecated_imports�s  rkF)Ú required_oncCsft|ƒ�Ty tj|ƒStk rV}z&tjjt|ƒƒr8‚tj t |ƒƒ‚WYdd}~XnXWdQRXdS)acImport and return the module to be tested, raising SkipTest if it is not available. If deprecated is True, any module or package deprecation messages will be suppressed. If a module is required on a platform but optional for others, set required_on to an iterable of platform prefixes which will be compared against sys.platform. N) rkÚ importlibr Ú ImportErrorÚsysÚplatformÚ startswithÚtupleÚunittestÚSkipTestÚstr)ÚnameÚ deprecatedrlÚmsgrdrdrer �s  cCs^|tjkrt|ƒtj|=x>ttjƒD]0}||ks@|j|dƒr&tj|||<tj|=q&WdS)zyHelper function to save and remove a module from sys.modules Raise ImportError if the module can't be imported. Ú.N)roÚmodulesÚ __import__Úlistrq)rvÚ orig_modulesÚmodnamerdrdreÚ_save_and_remove_module¯s rc Cs>d}ytj|||<Wntk r.d}YnXdtj|<|S)z‚Helper function to save and block a module in sys.modules Return True if the module was in sys.modules, False otherwise. TFN)rorzÚKeyError)rvr}ZsavedrdrdreÚ_save_and_block_module½s  r�cCs|r tjSdd„S)z¯Decorator to mark a test that is known to be broken in some cases Any use of this decorator should have a comment identifying the associated tracker issue. cSs|S)Nrd)ÚfrdrdreÚÓsz$anticipate_failure..)rsZexpectedFailure)Z conditionrdrdrer:ËscCsF|dkr d}tjjtjjtjjtƒƒƒ}|j|||d�}|j|ƒ|S)zòGeneric load_tests implementation for simple test packages. Most packages can implement load_tests using this function as follows: def load_tests(*args): return load_package_tests(os.path.dirname(__file__), *args) Nztest*)Z start_dirZ top_level_dirÚpattern)ÚosÚpathÚdirnameÚ__file__ZdiscoverZaddTests)Zpkg_dirÚloaderZstandard_testsr„Ztop_dirZ package_testsrdrdrer;Õs c CsÊt|ƒ�¸i}g}t||ƒzfyHx|D]}t||ƒq&Wx |D]}t||ƒs>|j|ƒq>Wtj|ƒ}Wntk r~d}YnXWdx|jƒD]\} } | tj | <qŽWx|D] } tj | =qªWX|SQRXdS)aøImport and return a module, deliberately bypassing sys.modules. This function imports and returns a fresh copy of the named Python module by removing the named module from sys.modules before doing the import. Note that unlike reload, the original module is not affected by this operation. *fresh* is an iterable of additional module names that are also removed from the sys.modules cache before doing the import. *blocked* is an iterable of module names that are replaced with None in the module cache during the import to ensure that attempts to import them raise ImportError. The named module and any modules named in the *fresh* and *blocked* parameters are saved before starting the import and then reinserted into sys.modules when the fresh import is complete. Module and package deprecation messages are suppressed during this import if *deprecated* is True. This function will raise ImportError if the named module cannot be imported. N) rkrr�Úappendrmr rnÚitemsrorz) rvZfreshZblockedrwr}Znames_to_removeZ fresh_nameZ blocked_nameZ fresh_moduleZ orig_nameÚmoduleZname_to_removerdrdrerés$      c Cs>yt||ƒ}Wn&tk r4tjd||fƒ‚YnX|SdS)z?Get an attribute, raising SkipTest if AttributeError is raised.zobject %r has no attribute %rN)ÚgetattrÚAttributeErrorrsrt)ÚobjrvZ attributerdrdrer6s cCs|adS)N)Ú_original_stdout)Ústdoutrdrdrer0scCs tptjS)N)r�ror‘rdrdrdrer4sc Cs&y tj|=Wntk r YnXdS)N)rorzr€)rvrdrdrer7s cGsny||ŽStk rh}zDtdkrHtd|jj|fƒtd|j|fƒtj|tjƒ||ŽSd}~XnXdS)Néz%s: %sz re-run %s%r) ÚOSErrorrÚprintÚ __class__r`r…ÚchmodÚstatÚS_IRWXU)r†ÚfuncÚargsÚerrrdrdreÚ _force_run=srœÚwincCs„||ƒ|r|}ntjj|ƒ\}}|p(d}d}x<|dkrjtj|ƒ}|rJ|n||ksVdStj|ƒ|d9}q0Wtjd|tdd�dS)Nrygü©ñÒMbP?gð?r’z)tests may fail, delete still pending for é)Ú stacklevel) r…r†ÚsplitÚlistdirÚtimeÚsleeprgÚwarnÚRuntimeWarning)r™ÚpathnameÚwaitallr‡rvÚtimeoutÚLrdrdreÚ_waitforHs     rªcCsttj|ƒdS)N)rªr…r)ÚfilenamerdrdreÚ_unlinkisr¬cCsttj|ƒdS)N)rªr…Úrmdir)r‡rdrdreÚ_rmdirlsr®cs,‡fdd„‰tˆ|dd�tdd„|ƒdS)Ncs®x¨t|tj|ƒD]–}tjj||ƒ}ytj|ƒj}Wn<tk rn}z td||ft j d�d}WYdd}~XnXt j |ƒr˜t ˆ|dd�t|tj|ƒqt|tj|ƒqWdS)Nz-support.rmtree(): os.lstat(%r) failed with %s)ÚfilerT)r§)rœr…r¡r†ÚjoinÚlstatÚst_moder“r”roÚ __stderr__r—ÚS_ISDIRrªr­r)r†rvÚfullnameÚmodeÚexc)Ú _rmtree_innerrdrer¸ps   z_rmtree.._rmtree_innerT)r§cSst|tj|ƒS)N)rœr…r­)Úprdrdrerƒsz_rmtree..)rª)r†rd)r¸reÚ_rmtreeos rºc Cs^y ddl}Wntk r Yn:X|jt|ƒdƒ}|jjj||t|ƒƒ}|rZ|d|…S|S)Nrr’)ÚctypesrnZcreate_unicode_bufferÚlenÚwindllÚkernel32ZGetLongPathNameW)r†r»ÚbufferZlengthrdrdreÚ _longpath�s    rÀc sFytj|ƒdStk r"YnX‡fdd„‰ˆ|ƒtj|ƒdS)Nc s„x~t|tj|ƒD]l}tjj||ƒ}ytj|ƒj}Wntk rJd}YnXtj |ƒrnˆ|ƒt|tj |ƒqt|tj |ƒqWdS)Nr) rœr…r¡r†r°r±r²r“r—r´r­r)r†rvrµr¶)r¸rdrer¸™s  z_rmtree.._rmtree_inner)Úshutilrr“r…r­)r†rd)r¸rerº’s  cCs|S)Nrd)r†rdrdrerÀ¨sc Cs*y t|ƒWnttfk r$YnXdS)N)r¬ÚFileNotFoundErrorÚNotADirectoryError)r«rdrdrer«s c Cs&y t|ƒWntk r YnXdS)N)r®rÂ)r‡rdrdrer­±s r­c Cs&y t|ƒWntk r YnXdS)N)rºrÂ)r†rdrdrer·s cCsBtjj|ƒ}tjjtjj|ƒƒ}tjj||dƒ}tj||ƒ|S)aMove a PEP 3147/488 pyc file to its legacy pyc location. :param source: The file system path to the source file. The source file does not need to exist, however the PEP 3147/488 pyc file must exist. :return: The file system path to the legacy pyc file. Úc) rmÚutilÚcache_from_sourcer…r†r‡Úabspathr°Úrename)ÚsourceZpyc_fileZup_oneZ legacy_pycrdrdreÚmake_legacy_pyc½s   rÊcCs\t|ƒxNtjD]D}tjj||dƒ}t|dƒx dD]}ttjj||d�ƒq8WqWdS) zŽ'Forget' a module was ever imported. This removes the module from sys.modules and deletes any PEP 3147/488 or legacy .pyc files. z.pyrÄÚrr’)Ú optimizationN)rËrr’) rror†r…r°rrmrÅrÆ)r~r‡rÉÚoptrdrdrerÊs    csüttdƒrtjSd}tjjdƒr¾ddl‰ddl‰d}d}G‡fdd„dˆjƒ}ˆj j }|j ƒ}|sjˆj ƒ‚|ƒ}ˆj jƒ}|j||ˆj|ƒˆj|ƒˆj|ƒƒ}|sªˆj ƒ‚t|j|@ƒs¼d}n˜tjdk�rVdd lm} m‰m} m} dd lm} | j| d ƒƒ} | jƒdk�rd }nFG‡fd d„d| ƒ}|ƒ}| |ƒ}| j|ƒdk�sR| j|ƒdk�rVd}|�sèy.ddlm}|ƒ}|jƒ|j ƒ|j!ƒWn\t"k �ræ}z>t#|ƒ}t$|ƒdk�rÄ|dd…d}dj%t&|ƒj'|ƒ}WYdd}~XnX|t_(| t_tjS)NÚresultr�rrcs.eZdZd”jjfd”jjfd”jjfgZdS)z*_is_gui_available..USEROBJECTFLAGSZfInheritZ fReservedÚdwFlagsN)r`rarbÚwintypesZBOOLÚDWORDÚ_fields_rd)r»rdreÚUSEROBJECTFLAGSås  rÓz,gui not available (WSF_VISIBLE flag not set)Údarwin)ÚcdllÚc_intÚpointerÚ Structure)Ú find_libraryZApplicationServicesz0gui tests cannot run without OS X window managercseZdZd”fd”fgZdS)z._is_gui_available..ProcessSerialNumberZ highLongOfPSNZ lowLongOfPSNN)r`rarbrÒrd)rÖrdreÚProcessSerialNumbersrÚz#cannot run without OS X gui process)ÚTké2z [...]zTk unavailable due to {}: {}))ÚhasattrÚ_is_gui_availablerÎrorprqr»Zctypes.wintypesrØr½Zuser32ZGetProcessWindowStationZWinErrorrÐrÑZGetUserObjectInformationWZbyrefZsizeofÚboolrÏrÕrÖr×Z ctypes.utilrÙZ LoadLibraryZCGMainDisplayIDZGetCurrentProcessZSetFrontProcessZtkinterrÛZwithdrawÚupdateZdestroyÚ Exceptionrur¼ÚformatÚtyper`Úreason)räZ UOI_FLAGSZ WSF_VISIBLErÓZdllÚhZuofZneededÚresrÕr×rØrÙZ app_servicesrÚZpsnZpsn_prÛÚrootÚeZ err_stringrd)rÖr»rerÞÚsh         rÞcCstdkp|tkS)zÁTest whether a resource is enabled. Known resources are set by regrtest.py. If not running under regrtest.py, all resources are assumed enabled unless use_resources has been set. N)r)Úresourcerdrdrer $scCs>t|ƒs |dkrd|}t|ƒ‚|dkr:tƒ r:ttjƒ‚dS)z@Raise ResourceDenied if the specified resource is not available.Nz"Use of the %r resource not enabledÚgui)r r rÞrä)rérxrdrdrer!,s cs‡‡fdd„}|S)zàDecorator raising SkipTest if the OS is `sysname` and the version is less than `min_version`. For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if the FreeBSD version is less than 7.2. cs$tjˆƒ‡‡‡fdd„ƒ}ˆ|_|S)Nc s„tjƒˆkrztjƒjddƒd}yttt|jdƒƒƒ}Wntk rLYn.X|ˆkrzdjtt ˆƒƒ}t j dˆ||fƒ‚ˆ||ŽS)Nú-rrryz(%s version %s or higher required, not %s) rpÚsystemÚreleaser rrÚmapÚintÚ ValueErrorr°rursrt)ršÚkwÚ version_txtÚversionÚmin_version_txt)r™Ú min_versionÚsysnamerdreÚwrapper=s z:_requires_unix_version..decorator..wrapper)Ú functoolsÚwrapsrõ)r™r÷)rõrö)r™reÚ decorator<sz)_requires_unix_version..decoratorrd)rörõrúrd)rõröreÚ_requires_unix_version5srûcGs td|ƒS)zÛDecorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is less than `min_version`. For example, @requires_freebsd_version(7, 2) raises SkipTest if the FreeBSD version is less than 7.2. ZFreeBSD)rû)rõrdrdrer"PscGs td|ƒS)zÚDecorator raising SkipTest if the OS is Linux and the Linux version is less than `min_version`. For example, @requires_linux_version(2, 6, 32) raises SkipTest if the Linux version is less than 2.6.32. ZLinux)rû)rõrdrdrer#Yscs‡fdd„}|S)zÐDecorator raising SkipTest if the OS is Mac OS X and the OS X version if less than min_version. For example, @requires_mac_ver(10, 5) raises SkipTest if the OS X version is lesser than 10.5. cs"tjˆƒ‡‡fdd„ƒ}ˆ|_|S)Nc sxtjdkrntjƒd}yttt|jdƒƒƒ}Wntk rBYn,X|ˆkrndjtt ˆƒƒ}t j d||fƒ‚ˆ||ŽS)NrÔrryz&Mac OS X %s or higher required, not %s) rorpZmac_verrrrîrïr rðr°rursrt)ršrñròrórô)r™rõrdrer÷js   z4requires_mac_ver..decorator..wrapper)rørùrõ)r™r÷)rõ)r™rerúisz#requires_mac_ver..decoratorrd)rõrúrd)rõrer$bs cs‡‡fdd„}|S)a·Decorator raising SkipTest if a hashing algorithm is not available The hashing algorithm could be missing or blocked by a strict crypto policy. If 'openssl' is True, then the decorator checks that OpenSSL provides the algorithm. Otherwise the check falls back to built-in implementations. ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS ValueError: unsupported hash type md4 cstjˆƒ‡‡‡fdd„ƒ}|S)Nc sXy&ˆrtdk rtjˆƒn tjˆƒWn&tk rLtjdˆ›d�ƒ‚YnXˆ||ŽS)Nz hash digest 'z' is not available.)Ú_hashlibÚnewÚhashlibrðrsrt)ršÚkwargs)Ú digestnamer™Úopensslrdrer÷‹s  z7requires_hashdigest..decorator..wrapper)rørù)r™r÷)rr)r™rerúŠs z&requires_hashdigest..decoratorrd)rrrúrd)rrrer%}s z 127.0.0.1z::1cCs"tj||ƒ}t|ƒ}|jƒ~|S)aî Returns an unused port that should be suitable for binding. This is achieved by creating a temporary socket with the same family and type as the 'sock' parameter (default is AF_INET, SOCK_STREAM), and binding it to the specified host address (defaults to 0.0.0.0) with the port set to 0, eliciting an unused ephemeral port from the OS. The temporary socket is then closed and deleted, and the ephemeral port is returned. Either this method or bind_port() should be used for any tests where a server socket needs to be bound to a particular port for the duration of the test. Which one to use depends on whether the calling code is creating a python socket, or if an unused port needs to be provided in a constructor or passed to an external program (i.e. the -accept argument to openssl's s_server mode). Always prefer bind_port() over find_unused_port() where possible. Hard coded ports should *NEVER* be used. As soon as a server socket is bound to a hard coded port, the ability to run multiple instances of the test simultaneously on the same host is compromised, which makes the test a ticking time bomb in a buildbot environment. On Unix buildbots, this may simply manifest as a failed test, which can be recovered from without intervention in most cases, but on Windows, the entire python process can completely and utterly wedge, requiring someone to log in to the buildbot and manually kill the affected process. (This is easy to reproduce on Windows, unfortunately, and can be traced to the SO_REUSEADDR socket option having different semantics on Windows versus Unix/Linux. On Unix, you can't have two AF_INET SOCK_STREAM sockets bind, listen and then accept connections on identical host/ports. An EADDRINUSE OSError will be raised at some point (depending on the platform and the order bind and listen were called on each socket). However, on Windows, if SO_REUSEADDR is set on the sockets, no EADDRINUSE will ever be raised when attempting to bind two identical host/ports. When accept() is called on each socket, the second caller's process will steal the port from the first caller, leaving them both in an awkwardly wedged state where they'll no longer respond to any signals or graceful kills, and must be forcibly killed via OpenProcess()/TerminateProcess(). The solution on Windows is to use the SO_EXCLUSIVEADDRUSE socket option instead of SO_REUSEADDR, which effectively affords the same semantics as SO_REUSEADDR on Unix. Given the propensity of Unix developers in the Open Source world compared to Windows ones, this is a common mistake. A quick look over OpenSSL's 0.9.8g source shows that they use SO_REUSEADDR when openssl.exe is called with the 's_server' option, for example. See http://bugs.python.org/issue2550 for more info. The following site also has a very thorough description about the implications of both REUSEADDR and EXCLUSIVEADDRUSE on Windows: http://msdn2.microsoft.com/en-us/library/ms740621(VS.85).aspx) XXX: although this approach is a vast improvement on previous attempts to elicit unused ports, it rests heavily on the assumption that the ephemeral port returned to us by the OS won't immediately be dished back out to some other process when we close and delete our temporary socket but before our calling code has a chance to bind the returned port. We can deal with this issue if/when we come across it. )ÚsocketrHÚclose)ÚfamilyZsocktypeZtempsockÚportrdrdrerG s 8 c Cs¸|jtjkrš|jtjkršttdƒr>|jtjtjƒdkr>t dƒ‚ttdƒr~y |jtjtj ƒdkrft dƒ‚Wnt k r|YnXttdƒrš|j tjtj dƒ|j|dfƒ|jƒd}|S)a%Bind the socket to a free port and return the port number. Relies on ephemeral ports in order to ensure we are using an unbound port. This is important as many tests may be running simultaneously, especially in a buildbot environment. This method raises an exception if the sock.family is AF_INET and sock.type is SOCK_STREAM, *and* the socket has SO_REUSEADDR or SO_REUSEPORT set on it. Tests should *never* set these socket options for TCP/IP sockets. The only case for setting these options is testing multicasting via multiple UDP sockets. Additionally, if the SO_EXCLUSIVEADDRUSE socket option is available (i.e. on Windows), it will be set on the socket. This will prevent anyone else from bind()'ing to our host/port for the duration of the test. Ú SO_REUSEADDRrzHtests should never set the SO_REUSEADDR socket option on TCP/IP sockets!Ú SO_REUSEPORTzHtests should never set the SO_REUSEPORT socket option on TCP/IP sockets!ÚSO_EXCLUSIVEADDRUSEr)rrÚAF_INETrãÚ SOCK_STREAMrÝZ getsockoptZ SOL_SOCKETrr rr“Z setsockoptrÚbindZ getsockname)ÚsockÚhostrrdrdrerHÞs     c CsJ|jtjkst‚y|j|ƒWn&tk rD|jƒtjdƒ‚YnXdS)zBBind a unix socket, raising SkipTest if PermissionError is raised.zcannot bind AF_UNIX socketsN) rrZAF_UNIXÚAssertionErrorr ÚPermissionErrorrrsrt)r ZaddrrdrdrerJs cCsZtjrVd}z.dec)rørù)r‚rrd)r‚reÚsystem_must_validate_certs rržiéZdoubleZIEEEztest requires IEEE 754 doublesz requires zlibz requires gzipz requires bz2z requires lzmaÚjavaÚANDROID_API_LEVELÚwin32z/system/bin/shz/bin/shz$testz@testz {}_{}_tmpõæõİõÅ�õφõКõ×�õØŒõتõà¸�õ õ€u -àòɘÅ�ÄŸrÔZNFDÚntr’u-å…±Å�â™¡Í£í²€ztWARNING: The filename %r CAN be encoded by the filesystem encoding (%s). Unicode filename tests may not be effectiveóÿs-ÿÚsurrogateescapeóçwðó®Õí²€óí´€ó�˜rëccsžd}|dkr&tjƒ}d}tjj|ƒ}nBytj|ƒd}Wn.tk rf|sN‚tjd|t dd�YnX|rttj ƒ}z |VWd|r˜|tj ƒkr˜t |ƒXdS)a¢Return a context manager that creates a temporary directory. Arguments: path: the directory to create temporarily. If omitted or None, defaults to creating a temporary directory using tempfile.mkdtemp. quiet: if False (the default), the context manager raises an exception on error. Otherwise, if the path is specified and cannot be created, only a warning is issued. FNTz+tests may fail, unable to create temp dir: é)rŸ) ÚtempfileÚmkdtempr…r†ÚrealpathÚmkdirr“rgr¤r¥Úgetpidr)r†ÚquietZ dir_createdÚpidrdrdreÚtemp_dirãs&   r3ccsftjƒ}ytj|ƒWn.tk rD|s,‚tjd|tdd�YnXztjƒVWdtj|ƒXdS)agReturn a context manager that changes the current working directory. Arguments: path: the directory to use as the temporary current working directory. quiet: if False (the default), the context manager raises an exception on error. Otherwise, it issues only a warning and keeps the current working directory the same. z)tests may fail, unable to change CWD to: r+)rŸN)r…ÚgetcwdÚchdirr“rgr¤r¥)r†r1Z saved_dirrdrdreÚ change_cwd s  r6Útempcwdccs:t||d��$}t||d�� }|VWdQRXWdQRXdS)aö Context manager that temporarily creates and changes the CWD. The function temporarily changes the current working directory after creating a temporary directory in the current directory with name *name*. If *name* is None, the temporary directory is created using tempfile.mkdtemp. If *quiet* is False (default) and it is not possible to create or change the CWD, an error is raised. If *quiet* is True, only a warning is raised and the original CWD is used. )r†r1)r1N)r3r6)rvr1Z temp_pathZcwd_dirrdrdrer$sÚumaskc cs&tj|ƒ}z dVWdtj|ƒXdS)z8Context manager that temporarily sets the process umask.N)r…r8)r8ZoldmaskrdrdrerK8s  ÚdatacCsbtjj|ƒr|S|dk r&tjj||ƒ}tgtj}x*|D]"}tjj||ƒ}tjj|ƒr8|Sq8W|S)a[Try to find a file on sys.path or in the test directory. If it is not found the argument passed to the function is returned (this does not necessarily signal failure; could still be the legitimate path). Setting *subdir* indicates a relative path to use to find the file rather than looking directly in the path directories. N)r…r†Úisabsr°Ú TEST_HOME_DIRroÚexists)r«Zsubdirr†ZdnÚfnrdrdrerIs    cCs(tj|tjtjBtjBƒ}tj|ƒdS)z>Create an empty file. If the file already exists, truncate it.N)r…ÚopenÚO_WRONLYÚO_CREATÚO_TRUNCr)r«Úfdrdrdrer[scCs,t|jƒƒ}dd„|Dƒ}dj|ƒ}d|S)z%Like repr(dict), but in sorted order.cSsg|] }d|‘qS)z%r: %rrd)Ú.0Zpairrdrdreú cszsortdict..z, z{%s})Úsortedr‹r°)Údictr‹Z reprpairsZ withcommasrdrdrer[`s  c Cs*ttdƒ}z|jƒS|jƒttƒXdS)z` Create an invalid file descriptor by opening and closing a file and return its fd. ÚwbN)r>rÚfilenorr)r¯rdrdreÚ make_bad_fdgs  rI)ÚlinenoÚoffsetc Csp|jtƒ�}t|ddƒWdQRX|j}|j|jƒ|dk rJ|j|j|ƒ|j|jƒ|dk rl|j|j|ƒdS)Nz Úexec)Ú assertRaisesÚ SyntaxErrorÚcompileZ exceptionZassertIsNotNonerJÚ assertEqualrK)ÚtestcaseZ statementrJrKÚcmr›rdrdrer&ss   c sVddl}ddl}ˆjddƒ‰|jj|ƒdjdƒd}tjjt |ƒ}‡‡‡fdd„}tjj |ƒr|||ƒ}|dk rt|St |ƒt dƒt rštd |tƒd �|jjƒ}tr´|jjdƒ|j|d d�}trâ|jjdƒd krâtj|d�}zBt|dƒ�.} |jƒ} x| �r| j| ƒ|jƒ} �qúWWdQRXWd|jƒX||ƒ}|dk �rF|Std|ƒ‚dS)NrÚcheckr’ú/rcs>t|fˆžˆŽ}ˆdkr|Sˆ|ƒr2|jdƒ|S|jƒdS)Nr)r>Úseekr)r=r‚)ršrSrñrdreÚcheck_valid_file‡s z*open_urlresource..check_valid_fileZurlfetchz fetching %s ...)r¯úAccept-EncodingÚgzipé)r¨zContent-Encoding)ZfileobjrGzinvalid resource %réÿÿÿÿ)rWrX)Zurllib.requestZ urllib.parseÚpopÚparseZurlparser r…r†r°Ú TEST_DATA_DIRr<rr!rr”rZrequestZ build_openerrXZ addheadersrŠr>ZheadersÚgetZGzipFileÚreadÚwriterr ) ZurlršrñÚurllibr«r=rVr‚ÚopenerÚoutÚsrd)ršrSrñrerI~s<         c@s4eZdZdZdd„Zdd„Zedd„ƒZdd „Zd S) ÚWarningsRecorderzyConvenience wrapper for the warnings list returned on entry to the warnings.catch_warnings() context manager. cCs||_d|_dS)Nr)Ú _warningsÚ_last)ÚselfZ warnings_listrdrdreÚ__init__´szWarningsRecorder.__init__cCsDt|jƒ|jkr t|jd|ƒS|tjjkr0dStd||fƒ‚dS)Nrz%r has no attribute %rrZ)r¼rfrgr�rgÚWarningMessageÚ_WARNING_DETAILSrŽ)rhÚattrrdrdreÚ __getattr__¸s  zWarningsRecorder.__getattr__cCs|j|jd…S)N)rfrg)rhrdrdrerg¿szWarningsRecorder.warningscCst|jƒ|_dS)N)r¼rfrg)rhrdrdreÚresetÃszWarningsRecorder.resetN) r`rarbrcrirmÚpropertyrgrnrdrdrdrere°s  rec cs tjdƒ}|jjdƒ}|r"|jƒtjdd�� }tjdjdƒt |ƒVWdQRXt |ƒ}g}xz|D]r\}}d} xH|dd…D]8}|j } t j |t| ƒt jƒr€t| j|ƒr€d} |j|ƒq€W| rf| rf|j||jfƒqfW|rðtd |d ƒ‚|�rtd |d ƒ‚dS) z¶Catch the warnings, then check if all the expected warnings have been raised and re-raise unexpected warnings. If 'quiet' is True, only re-raise the unexpected warnings. r’Z__warningregistry__T)ÚrecordrgÚalwaysNFzunhandled warning %srz)filter (%r, %s) did not catch any warning)roÚ _getframeÚ f_globalsr^ÚclearrgrhrzÚ simplefilterrer|ÚmessageÚreÚmatchruÚIÚ issubclassr•ÚremoverŠr`r) Úfiltersr1ÚframeÚregistryÚwZreraiseZmissingrxÚcatÚseenZwarningrdrdreÚ_filterwarningsÇs0    r‚cOs.|jdƒ}|s$dtff}|dkr$d}t||ƒS)a˜Context manager to silence warnings. Accept 2-tuples as positional arguments: ("message regexp", WarningCategory) Optional argument: - if 'quiet' is True, it does not fail if a filter catches nothing (default True without argument, default False if some filters are defined) Without argument, it defaults to: check_warnings(("", Warning), quiet=True) r1rËNT)r^ÚWarningr‚)r|rÿr1rdrdrerRîs   rËc csHtjdd��&}tjd||d�dV|r.tƒWdQRX|j|gƒdS)aÑContext manager to check that no warnings are emitted. This context manager enables a given warning within its scope and checks that no warnings are emitted even with that warning enabled. If force_gc is True, a garbage collection is attempted before checking for warnings. This may help to catch warnings emitted when objects are deleted, such as ResourceWarning. Other keyword arguments are passed to warnings.filterwarnings(). T)rprq)rvÚcategoryN)rgrhriÚ gc_collectrP)rQrvr„Zforce_gcÚwarnsrdrdreÚcheck_no_warningssr‡c csBtjdd�� }tjdtd�dVtƒWdQRX|j|gƒdS)a"Context manager to check that no ResourceWarning is emitted. Usage: with check_no_resource_warning(self): f = open(...) ... del f You must remove the object which may emit ResourceWarning before the end of the context manager. T)rprq)r„N)rgrhriÚResourceWarningr…rP)rQr†rdrdrerSs c@s(eZdZdZdd„Zdd„Zdd„ZdS) ra,Context manager to force import to return a new module reference. This is useful for testing module-level behaviours, such as the emission of a DeprecationWarning on import. Use like this: with CleanImport("foo"): importlib.import_module("foo") # new reference cGsNtjjƒ|_x<|D]4}|tjkrtj|}|j|kr>tj|j=tj|=qWdS)N)rorzÚcopyÚoriginal_modulesr`)rhZ module_namesZ module_namerŒrdrdreri?s      zCleanImport.__init__cCs|S)Nrd)rhrdrdreÚ __enter__LszCleanImport.__enter__cGstjj|jƒdS)N)rorzràrŠ)rhÚ ignore_excrdrdreÚ__exit__OszCleanImport.__exit__N)r`rarbrcrir‹r�rdrdrdrer3s  c@sheZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„ZdS)rTz_Class to help protect the environment variable properly. Can be used as a context manager.cCstj|_i|_dS)N)r…ÚenvironÚ_environÚ_changed)rhrdrdreriXszEnvironmentVarGuard.__init__cCs |j|S)N)r�)rhÚenvvarrdrdreÚ __getitem__\szEnvironmentVarGuard.__getitem__cCs*||jkr|jj|ƒ|j|<||j|<dS)N)r�r�r^)rhr‘ÚvaluerdrdreÚ __setitem___s zEnvironmentVarGuard.__setitem__cCs2||jkr|jj|ƒ|j|<||jkr.|j|=dS)N)r�r�r^)rhr‘rdrdreÚ __delitem__es  zEnvironmentVarGuard.__delitem__cCs |jjƒS)N)r�Úkeys)rhrdrdrer–lszEnvironmentVarGuard.keyscCs t|jƒS)N)Úiterr�)rhrdrdreÚ__iter__oszEnvironmentVarGuard.__iter__cCs t|jƒS)N)r¼r�)rhrdrdreÚ__len__rszEnvironmentVarGuard.__len__cCs |||<dS)Nrd)rhr‘r“rdrdreÚsetuszEnvironmentVarGuard.setcCs ||=dS)Nrd)rhr‘rdrdreÚunsetxszEnvironmentVarGuard.unsetcCs|S)Nrd)rhrdrdrer‹{szEnvironmentVarGuard.__enter__cGsJx<|jjƒD].\}}|dkr0||jkr:|j|=q ||j|<q W|jt_dS)N)r�r‹r�r…rŽ)rhrŒÚkÚvrdrdrer�~s   zEnvironmentVarGuard.__exit__N)r`rarbrcrir’r”r•r–r˜r™ršr›r‹r�rdrdrdrerTSsc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú DirsOnSysPathaŽContext manager to temporarily add directories to sys.path. This makes a copy of sys.path, appends any directories given as positional arguments, then reverts sys.path to the copied settings when the context ends. Note that *all* sys.path modifications in the body of the context manager, including replacement of the object, will be reverted at the end of the block. cGs(tjdd…|_tj|_tjj|ƒdS)N)ror†Úoriginal_valueÚoriginal_objectÚextend)rhÚpathsrdrdreri”szDirsOnSysPath.__init__cCs|S)Nrd)rhrdrdrer‹™szDirsOnSysPath.__enter__cGs|jt_|jtjdd…<dS)N)r ror†rŸ)rhrŒrdrdrer�œszDirsOnSysPath.__exit__N)r`rarbrcrir‹r�rdrdrdreržˆs ržc@s*eZdZdZdd„Zdd„Zd dd„ZdS) r'zŽRaise ResourceDenied if an exception is raised while the context manager is in effect that matches the specified exception and attributes.cKs||_||_dS)N)r·Úattrs)rhr·rÿrdrdreri¦szTransientResource.__init__cCs|S)Nrd)rhrdrdrer‹ªszTransientResource.__enter__NcCsT|dk rPt|j|ƒrPx:|jjƒD]$\}}t||ƒs4Pt||ƒ|kr Pq Wtdƒ‚dS)z§If type_ is a subclass of self.exc and value has attributes matching self.attrs, raise ResourceDenied. Otherwise let the exception propagate (if any).Nz%an optional resource is not available)rzr·r£r‹rÝr�r )rhZtype_r“Ú tracebackrlZ attr_valuerdrdrer�­s zTransientResource.__exit__)NNN)r`rarbrcrir‹r�rdrdrdrer'¡s)Úerrnog>@)r¨Úerrnosc #spd!d"d#d$d%d&g}d(d*d,d.d/g}td|ƒ‰|‰g‰ˆsRdd„|Dƒ‰dd„|Dƒ‰‡‡‡fdd„}tjƒ}zôy|dk r€tj|ƒdVWnÒtjk �rÎ}z&tr¸tjj ˆj ddƒˆ|‚WYdd}~XnŽt k �rZ}zpx^|j }t |ƒd k�rt |dt ƒ�r|d}n*t |ƒdk�r8t |d t ƒ�r8|d }nP�qâW||ƒ‚WYdd}~XnXWdtj|ƒXdS)0z‹Return a context manager that raises ResourceDenied when various issues with the Internet connection manifest themselves as exceptions.Ú ECONNREFUSEDéoÚ ECONNRESETéhÚ EHOSTUNREACHéqÚ ENETUNREACHéeÚ ETIMEDOUTénÚ EADDRNOTAVAILécÚ EAI_AGAINr+ÚEAI_FAILržÚ EAI_NONAMEr’Ú EAI_NODATAéÚ WSANO_DATAéü*zResource %r is not availablecSsg|]\}}tt||ƒ‘qSrd)r�r¥)rCrvÚnumrdrdrerDÝsz&transient_internet..cSsg|]\}}tt||ƒ‘qSrd)r�r)rCrvrºrdrdrerDßscs¬t|ddƒ}t|tjƒsˆt|tjƒr,|ˆksˆt|tjjƒrTd|jkoNdknsˆt|tjj ƒr€d|j ksˆd|j ksˆd|j ksˆ|ˆkr¨t s¢t j jˆjddƒˆ|‚dS) Nr¥iôiWÚConnectionRefusedErrorÚ TimeoutErrorÚEOFErrorrÚ )r�Ú isinstancerr¨ZgaierrorraÚerrorZ HTTPErrorÚcodeZURLErrorrärroÚstderrr`rš)r›Ún)Úcaptured_errnosÚdeniedÚ gai_errnosrdreÚ filter_errorâs     z(transient_internet..filter_errorNrr¾r)r§r¨)r©rª)r«r¬)r­r®)r¯r°)r±r²éýÿÿÿ)r³rÈéüÿÿÿ)r´rÉéþÿÿÿ)rµrÊéûÿÿÿ)r¶rË)r¸r¹)r rZgetdefaulttimeoutZsetdefaulttimeoutÚnntplibZNNTPTemporaryErrorrrorÂr`ršr“r¼r¿) Z resource_namer¨r¦Zdefault_errnosZdefault_gai_errnosrÇZ old_timeoutr›Úard)rÄrÅrÆrer+ÂsP     c csFddl}tt|ƒ}tt||jƒƒztt|ƒVWdtt||ƒXdS)z‰Return a context manager used by captured_stdout/stdin/stderr that temporarily replaces the sys stream *stream_name* with a StringIO.rN)Úior�roÚsetattrÚStringIO)Z stream_namerÎZ orig_stdoutrdrdreÚcaptured_outputs  rÑcCstdƒS)z Capture the output of sys.stdout: with captured_stdout() as stdout: print("hello") self.assertEqual(stdout.getvalue(), "hello\n") r‘)rÑrdrdrdrerscCstdƒS)z±Capture the output of sys.stderr: with captured_stderr() as stderr: print("hello", file=sys.stderr) self.assertEqual(stderr.getvalue(), "hello\n") rÂ)rÑrdrdrdrer%scCstdƒS)a Capture the input to sys.stdin: with captured_stdin() as stdin: stdin.write('hello\n') stdin.seek(0) # call test code that consumes from sys.stdin captured = input() self.assertEqual(captured, "hello") Ústdin)rÑrdrdrdrer.s cCs*tjƒtrtjdƒtjƒtjƒdS)aÚForce as many objects as possible to be collected. In non-CPython implementations of Python, this is needed because timely deallocation is not guaranteed by the garbage collector. (Even in CPython this can be the case in case of reference cycles.) This means that __del__ methods may be called later than expected and weakrefs may remain alive for longer than expected. This function tries its best to force all garbage objects to disappear. gš™™™™™¹?N)ÚgcZcollectr@r¢r£rdrdrdrer…;s  r…c cs.tjƒ}tjƒz dVWd|r(tjƒXdS)N)rÓÚ isenabledÚdisableÚenable)Zhave_gcrdrdreÚ disable_gcKs  r×cCs:tjdƒp d}d}x|jƒD]}|jdƒr|}qW|dkS)z,Find if Python was built with optimizations.Ú PY_CFLAGSrËz-Oú-O0ú-Og)rËrÙrÚ)Ú sysconfigÚget_config_varr rq)ZcflagsZ final_optrÍrdrdreÚpython_is_optimizedVs  rÝZnPZ0nÚgettotalrefcountZ2PZ0PrÃcCstjt|tƒS)N)ÚstructÚcalcsizeÚ_headerÚ_align)ÚfmtrdrdreÚ calcobjsizegsräcCstjt|tƒS)N)rßràÚ_vheaderrâ)rãrdrdreÚ calcvobjsizejsræéé cCspddl}tj|ƒ}t|ƒtkr(|jt@sBt|ƒtkrLt|ƒjt@rL||j7}dt|ƒ||f}|j|||ƒdS)Nrz&wrong size for %s: got %d, expected %d) Ú _testcapiroÚ getsizeofrãÚ __flags__Ú_TPFLAGS_HEAPTYPEÚ_TPFLAGS_HAVE_GCZSIZEOF_PYGC_HEADrP)ÚtestÚoÚsizerérÎrxrdrdreÚ check_sizeofqs  rñcs‡‡fdd„}|S)Ncs$‡‡‡fdd„}ˆj|_ˆj|_|S)Ncsžy ddl}t|ˆƒ}|j|ƒ}Wn(tk r6‚YnBd}}Yn0Xx,ˆD]$}y|j||ƒPWqPYqPXqPWz ˆ||ŽS|r˜|r˜|j||ƒXdS)Nr)Úlocaler�Ú setlocalerŽ)ršÚkwdsròr„Z orig_localeÚloc)Úcatstrr™ÚlocalesrdreÚinner‚s$     z1run_with_locale..decorator..inner)r`rc)r™rø)rör÷)r™rerú�sz"run_with_locale..decoratorrd)rör÷rúrd)rör÷rerU€scs‡fdd„}|S)Ncs"‡‡fdd„}ˆj|_ˆj|_|S)NcsŠy tj}Wntk r(tjdƒ‚YnXdtjkr@tjd}nd}ˆtjd<|ƒz ˆ||ŽS|dkrrtjd=n |tjd<tjƒXdS)Nztzset requiredZTZ)r¢ÚtzsetrŽrsrtr…rŽ)ršrôrùZorig_tz)r™Útzrdrerø¦s       z-run_with_tz..decorator..inner)r`rc)r™rø)rú)r™rerú¥szrun_with_tz..decoratorrd)rúrúrd)rúrer\¤s cCs”dttdtdœ}tjd|tjtjBƒ}|dkr>td|fƒ‚tt|j dƒƒ||j dƒj ƒƒ}|a |t krrt }|t dkrŒtd|fƒ‚|adS)Ni)rœÚmÚgÚtz(\d+(\.\d+)?) (K|M|G|T)b?$zInvalid memory limit %rrr+z$Memory limit %r too low to be useful)Ú_1MÚ_1GrwrxÚ IGNORECASEÚVERBOSErðrïÚfloatÚgroupÚlowerÚreal_max_memuseÚMAX_Py_ssize_tÚ_2Gr)ÚlimitZsizesrûZmemlimitrdrdrerYÎs $ c@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú_MemoryWatchdogz`An object which periodically watches the process' memory consumption and prints it out. cCsdjtjƒd�|_d|_dS)Nz/proc/{pid}/statm)r2F)râr…r0ÚprocfileÚstarted)rhrdrdrerièsz_MemoryWatchdog.__init__cCs‚yt|jdƒ}Wn<tk rL}z tjdj|ƒtƒtjj ƒdSd}~XnXt dƒ}t j tj |g|t jd�|_|jƒd|_dS)NÚrz!/proc not available for stats: {}zmemory_watchdog.py)rÒrÂT)r>r r“rgr¤râr¥rorÂÚflushrÚ subprocessÚPopenÚ executableZDEVNULLÚ mem_watchdogrr )rhr‚rèZwatchdog_scriptrdrdreÚstartìs   z_MemoryWatchdog.startcCs|jr|jjƒ|jjƒdS)N)r rZ terminateÚwait)rhrdrdreÚstopûs z_MemoryWatchdog.stopN)r`rarbrcrirrrdrdrdrer ãsr cs‡‡‡fdd„}|S)atDecorator for bigmem tests. 'size' is a requested size for the test (in arbitrary, test-interpreted units.) 'memuse' is the number of bytes per unit for the test, or a good estimate of it. For example, a test that needs two byte buffers, of 4 GiB each, could be decorated with @bigmemtest(size=_4G, memuse=2). The 'size' argument is normally passed to the decorated test method as an extra argument. If 'dry_run' is true, the value passed to the test method may be less than the requested value. If 'dry_run' is false, it means the test doesn't support dummy runs when -M is not specified. cs ‡‡‡fdd„‰ˆˆ_ˆˆ_ˆS)Nc sžˆj}ˆj}tsd}n|}ts$ˆ rFt||krFtjd||dƒ‚tr|tr|tƒtdj||dd�ƒtƒ}|j ƒnd}z ˆ||ƒS|r˜|j ƒXdS) Niz'not enough memory: %.1fG minimum neededir+z* ... expected peak memory use: {peak:.1f}G)Zpeaki@i@) rðÚmemuserrsrtrr”râr rr)rhrðrÚmaxsizeZwatchdog)Údry_runr‚r÷rdrer÷s*    z.bigmemtest..decorator..wrapper)rðr)r‚)rrrð)r‚r÷rerúszbigmemtest..decoratorrd)rðrrrúrd)rrrðrer3s !cs‡fdd„}|S)z0Decorator for tests that fill the address space.csDttkr8td kr$td kr$tjdƒ‚q@tjdtd ƒ‚nˆ|ƒSdS) Nr’é?réz-not enough memory: try a 32-bit build insteadz'not enough memory: %.1fG minimum neededir+llÿÿÿÿli@)rrrsrt)rh)r‚rdrer÷3sz!bigaddrspacetest..wrapperrd)r‚r÷rd)r‚rer41s c@seZdZdd„ZdS)r,cCstjƒ}||ƒ|S)N)rsZ TestResult)rhrîrÎrdrdreÚrunDszBasicTestRunner.runN)r`rarbrrdrdrdrer,CscCs|S)Nrd)r�rdrdreÚ_idIsrcCs<|dkrtƒ rtjtjƒSt|ƒr(tStjdj|ƒƒSdS)Nrêzresource {0!r} is not enabled)rÞrsÚskiprär rrâ)rérdrdreÚrequires_resourceLs  rcCs&trt|krtjd|tfƒStSdS)Nz%s at Android API level %d)rAÚ_ANDROID_API_LEVELrsrr)Úlevelrärdrdrer>Ts  cCstdd�|ƒS)z9 Decorator for tests only applicable on CPython. T)Úcpython)Ú impl_detail)rîrdrdrer5[scKsVtf|ŽrtS|dkrLt|ƒ\}}|r,d}nd}t|jƒƒ}|jdj|ƒƒ}tj|ƒS)Nz*implementation detail not available on {0}z%implementation detail specific to {0}z or ) rBrÚ _parse_guardsrEr–râr°rsr)rxÚguardsZ guardnamesÚdefaultrdrdrer!as   r!c CsTtdkr:ddl}y|jƒdaWntk r8daYnXd}trF|Stj|ƒ|ƒS)z8Skip decorator for tests that use multiprocessing.Queue.NrTFz6requires a functioning shared semaphore implementation)Ú_have_mp_queueÚmultiprocessingZQueuernrsr)rîr&rxrdrdrer?os cCsH|sddidfSt|jƒƒd}t|jƒƒ|gt|ƒks>t‚|| fS)Nr TFr)r|Úvaluesr¼r)r#Zis_truerdrdrer"~s  r"cKs t|ƒ\}}|jtjƒjƒ|ƒS)a5This function returns True or False depending on the host platform. Examples: if check_impl_detail(): # only on CPython (default) if check_impl_detail(jython=True): # only on Jython if check_impl_detail(cpython=False): # everywhere except on CPython )r"r^rpZpython_implementationr)r#r$rdrdrerBˆs cs,ttdƒsˆStjˆƒ‡fdd„ƒ}|SdS)zEDecorator to temporarily turn off tracing for the duration of a test.Úgettracec s.tjƒ}ztjdƒˆ||ŽStj|ƒXdS)N)ror(Úsettrace)ršrÿZoriginal_trace)r™rdrer÷˜s   zno_tracing..wrapperN)rÝrorørù)r™r÷rd)r™reÚ no_tracing“s r*cCs tt|ƒƒS)aDecorator for tests which involve reference counting. To start, the decorator does not run the test if is not run by CPython. After that, any trace function is unset during the test to prevent unexpected refcounts caused by the trace function. )r*r5)rîrdrdreÚ refcount_test£sr+cCsRg}xB|jD]8}t|tjƒr2t||ƒ|j|ƒq ||ƒr |j|ƒq W||_dS)z>Recursively filter test cases in a suite based on a predicate.N)Z_testsr¿rsÚ TestSuiteÚ _filter_suiterŠ)ÚsuiteZpredZnewtestsrîrdrdrer-®s    r-cCs®ttjttdk d�}|j|ƒ}tdk r4tj|jƒƒ|js>t ‚|j ƒsªt |j ƒdkrl|j rl|j dd}n6t |j ƒdkr’|j r’|j dd}nd}ts¢|d7}t|ƒ‚dS)z2Run tests from a unittest.TestSuite-derived class.N)Ú verbosityZcapture_outputrrzmultiple errors occurredz!; run in verbose mode for details)rror‘rÚjunit_xml_listrrŠZget_xml_elementZtestsRunr Z wasSuccessfulr¼ÚerrorsZfailuresr )r.ZrunnerrÎr›rdrdreÚ _run_suiteºs"  r2cCstdkr dSt|jƒƒSdS)NT)Ú_match_test_funcÚid)rîrdrdreÚ match_test×sr5cCsd|kotjd|ƒ S)Nryz[?*\[\]])rwÚsearch)r„rdrdreÚ_is_full_match_testßsr7csr|tkr dS|sd}f}nHttt|ƒƒr4t|ƒj}n.djttj|ƒƒ}t j |ƒj ‰‡fdd„}|}t |ƒa|a dS)Nú|cs$ˆ|ƒr dSttˆ|jdƒƒƒSdS)NTry)Úanyrîr )Ztest_id)Ú regex_matchrdreÚmatch_test_regexþsz)set_match_tests..match_test_regex)Ú_match_test_patternsÚallrîr7ršÚ __contains__r°ÚfnmatchÚ translaterwrOrxrrr3)Zpatternsr™Zregexr;rd)r:reÚset_match_testsés   rAcGs”tjtjf}tjƒ}xh|D]`}t|tƒrT|tjkrJ|jtjtj|ƒƒqzt dƒ‚qt||ƒrj|j|ƒq|jtj |ƒƒqWt |t ƒt |ƒdS)z1Run tests from unittest.TestCase-derived classes.z)str arguments must be keys in sys.modulesN)rsr,ZTestCaser¿rurorzZaddTestZ findTestCasesrðZ makeSuiter-r5r2)ÚclassesZ valid_typesr.Úclsrdrdrer-s        cCsdS)z,Just used to check if docstrings are enabledNrdrdrdrdreÚ_check_docstrings(srDÚWITH_DOC_STRINGSztest requires docstringscCs`ddl}|dkrt}nd}|j|||d�\}}|rBtd||fƒ‚trXtd|j|fƒ||fS)aRun doctest on the given module. Return (#failures, #tests). If optional argument verbosity is not specified (or is None), pass support's belief about verbosity on to doctest. Else doctest's usual behavior is used (it searches sys.argv for -v). rN)rÚ optionflagsz%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)ÚdoctestrZtestmodr r”r`)rŒr/rFrGr‚rýrdrdrer.9scCs tjjƒfS)N)rorzr‰rdrdrdreÚ modules_setupTsrHcCs:dd„tjjƒDƒ}tjjƒtjj|ƒtjj|ƒdS)NcSs"g|]\}}|jdƒr||f‘qS)z encodings.)rq)rCrœr�rdrdrerD[sz#modules_cleanup..)rorzr‹rtrà)Z oldmodulesZ encodingsrdrdreÚmodules_cleanupWs  rIcCs"trtjƒtjjƒfSdffSdS)Nr)Ú_threadÚ_countÚ threadingÚ _danglingr‰rdrdrdrerNzscGsJtsdSd}x8t|ƒD],}tjƒtjf}||kr2PtjdƒtƒqWdS)Nédg{®Gáz„?)rJÚrangerKrLrMr¢r£r…)Zoriginal_valuesZ _MAX_COUNTÚcountr'rdrdrerO€s cs"tsˆStjˆƒ‡fdd„ƒ}|S)z¿Use this function when threads are being used. This will ensure that the threads are cleaned up even when the test fails. If threading is unavailable this function does nothing. c stƒ}zˆ|ŽSt|ŽXdS)N)rNrO)ršÚkey)r™rdrerú”szreap_threads..decorator)rJrørù)r™rúrd)r™rerPŒsçN@ccs–tjƒ}z dVWdtjƒ}||}xjtjƒ}||kr8Ptjƒ|kr|tjƒ|}d||›d|d›d|›d|›d� }t|ƒ‚tjdƒtƒq&WXdS) aH bpo-31234: Context manager to wait until all threads created in the with statement exit. Use _thread.count() to check if threads exited. Indirectly, wait until threads exit the internal t_bootstrap() C function of the _thread module. threading_setup() and threading_cleanup() are designed to emit a warning if a test leaves running threads in the background. This context manager is designed to cleanup threads started by the _thread.start_new_thread() which doesn't allow to wait for thread exit, whereas thread.Thread has a join() method. Nz!wait_threads() failed to cleanup z threads after z.1fz seconds (count: z , old count: ú)g{®Gáz„?)rJrKr¢Z monotonicrr£r…)r¨Z old_countZ start_timeZdeadlinerPZdtrxrdrdreÚwait_threads_exitžs   $ rTc CsZttdƒrVd}xFy2tj|tjƒ\}}|dkr.Ptd|tjd�WqPYqXqWdS)zåUse this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) stick around to hog resources and create problems when looking for refleaks. Úwaitpidrrz2Warning -- reap_children() reaped child process %s)r¯NrZ)rÝr…rUÚWNOHANGr”rorÂ)Z any_processr2ZstatusrdrdrerLÁs ccs*t|ƒ}g}zZy$x|D]}|jƒ|j|ƒqWWn*trVtdt|ƒt|ƒfƒ‚YnXdVWdzˆ|rt|ƒtjƒ}}xltddƒD]^}|d7}x$|D]}|jt |tjƒdƒƒqžWdd„|Dƒ}|sÒPtrŒtdt|ƒ|fƒqŒWWdd d„|Dƒ}|�r"t j t j ƒtd t|ƒƒ‚XXdS) Nz/Can't start %d threads, only %d threads startedrré<g{®Gáz„?cSsg|]}|jƒr|‘qSrd)ÚisAlive)rCrýrdrdrerDîsz!start_threads..z7Unable to join %d threads during a period of %d minutescSsg|]}|jƒr|‘qSrd)rX)rCrýrdrdrerDõszUnable to join %d threads)r|rrŠrr”r¼r¢rOr°ÚmaxÚ faulthandlerZdump_tracebackror‘r)ZthreadsZunlockr rýZendtimeZ starttimer¨rdrdrerQÖs>     c csnt||ƒrrrwrHrprírwrxrïrr“rr­)ruZtmp_dirZtmp_fpZtmp_nameÚfpZkernel_versionrûrdrdreÚ can_xattr¨ s,    r|cCs tƒ}d}|r|Stj|ƒ|ƒS)zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)r|rsr)rîrvrxrdrdrer8Æ scCs$t pt}d}|r|Stj|ƒ|ƒS)z;Skip decorator for tests not run in (non-extended) PGO taskz#Not run for (non-extended) PGO task)r]Ú PGO_EXTENDEDrsr)rîrvrxrdrdreÚskip_if_pgo_taskÌ s r~cCs^tj|d��H}|j}|jƒ}||kr,|jƒ}ytjj||ƒStk rNdSXWdQRXdS)zKDetects if the file system for the specified directory is case-insensitive.)rxFN) r,ZNamedTemporaryFilervÚupperrr…r†ÚsamefilerÂ)Z directoryÚbaseÚ base_pathZ case_pathrdrdrerÒ s)rfcCs>tt|ƒƒtt|ƒƒ}|r(|t|ƒ8}tdd„|Dƒƒ}|S)a Returns the set of items in ref_api not in other_api, except for a defined list of items to be ignored in this check. By default this skips private attributes beginning with '_' but includes all magic methods, i.e. those starting and ending in '__'. css(|] }|jdƒ s|jdƒr|VqdS)Ú_Ú__N)rqÚendswith)rCrûrdrdreú é sz&detect_api_mismatch..)ršrx)Zref_apiZ other_apirfZ missing_itemsrdrdrer<ß s  cCs |dkr|jf}nt|tƒr"|f}t|ƒ}xbt|ƒD]V}|jdƒs4||krLq4t||ƒ}t|ddƒ|ks€t|dƒ r4t|tj ƒ r4|j |ƒq4W|j |j |ƒdS)aAssert that the __all__ variable of 'module' contains all public names. The module's public names (its API) are detected automatically based on whether they match the public name convention and were defined in 'module'. The 'name_of_module' argument can specify (as a string or tuple thereof) what module(s) an API could be defined in in order to be detected as a public API. One case for this is when 'module' imports part of its public API from other modules, possibly a C backend (like 'csv' and its '_csv'). The 'extra' argument can be a set of names that wouldn't otherwise be automatically detected as "public", like objects without a proper '__module__' attribute. If provided, it will be added to the automatically detected ones. The 'blacklist' argument can be a set of names that must not be treated as part of the public API even though their names indicate otherwise. Usage: import bar import foo import unittest from test import support class MiscTestCase(unittest.TestCase): def test__all__(self): support.check__all__(self, foo) class OtherTestCase(unittest.TestCase): def test__all__(self): extra = {'BAR_CONST', 'FOO_CONST'} blacklist = {'baz'} # Undocumented name. # bar imports part of its API from _bar. support.check__all__(self, bar, ('bar', '_bar'), extra=extra, blacklist=blacklist) Nrƒra) r`r¿ruršrxrqr�rÝÚtypesÚ ModuleTypeÚaddZassertCountEqualÚ__all__)Z test_caserŒZname_of_moduleZextraZ blacklistZexpectedrvr�rdrdrer=î s)    c@s(eZdZdZdZdZdd„Zdd„ZdS)rZz«Try to prevent a crash report from popping up. On Windows, don't display the Windows Error Reporting dialog. On UNIX, disable the creation of coredump file. Nc Csrtjjdƒrºddl}|jj|_d}|jj|ƒ|_|jj|j|Bƒyddl }|j Wnt t fk rlYnLXi|_ xø|j|j|jgD].}|j ||jƒ}|j||jƒ}||f|j |<q†Wn´tdk �r y*tjtjƒ|_tjtjd|jdfƒWnttfk �rYnXtjdk�rnddd d g}tj|tjtjd �}|�|jƒd} WdQRX| jƒd k�rntd ddd�|S)z»On Windows, disable Windows Error Reporting dialogs using SetErrorMode. On UNIX, try to save the previous core file size limit, then set soft limit to 0. r�rNr’rrÔz/usr/bin/defaultsr_zcom.apple.CrashReporterZ DialogType)r‘rÂs developerz:this test triggers the Crash Reporter, that is intentionalrËT)Úendr ) rorprqr»r½r¾Ú_k32Ú SetErrorModeÚ old_valueÚmsvcrtÚCrtSetReportModerŽrnÚ old_modesÚCRT_WARNÚ CRT_ERRORÚ CRT_ASSERTZCRTDBG_MODE_FILEÚCrtSetReportFileZCRTDBG_FILE_STDERRréZ getrlimitÚ RLIMIT_COREÚ setrlimitrðr“rrÚPIPEZ communicaterar”) rhr»ZSEM_NOGPFAULTERRORBOXr�Ú report_typeÚold_modeÚold_fileÚcmdÚprocr‘rdrdrer‹2 sN        zSuppressCrashReport.__enter__c Gs¦|jdkrdStjjdƒrl|jj|jƒ|jr¢ddl}xj|jjƒD]$\}\}}|j ||ƒ|j ||ƒqBWn6t dk r¢yt j t j |jƒWnttfk r YnXdS)zARestore Windows ErrorMode or core file behavior to initial value.Nr�r)rŽrorprqrŒr�r‘r�r‹r�r•rér—r–rðr“)rhrŒr�r™ršr›rdrdrer�s s   zSuppressCrashReport.__exit__)r`rarbrcrŽr‘r‹r�rdrdrdrerZ) s Ac srtˆˆƒd‰yˆjˆ‰Wn$ttfk r@tˆˆdƒ‰YnXd‰‡‡‡‡fdd„}|j|ƒtˆˆ|ƒdS)zóOverride 'object_to_patch'.'attr_name' with 'new_value'. Also, add a cleanup procedure to 'test_instance' to restore 'object_to_patch' value for 'attr_name'. The 'attr_name' should be a valid attribute for 'object_to_patch'. FNTcs ˆrtˆˆˆƒn tˆˆƒdS)N)rÏr[rd)Ú attr_is_localÚ attr_nameÚobject_to_patchrŽrdreÚcleanupž szpatch..cleanup)r�rjrŽr€Z addCleanuprÏ)Z test_instancer rŸZ new_valuer¡rd)ržrŸr rŽreÚpatchˆ s  r¢c CsFy ddl}Wntk r YnX|jƒr4tjdƒ‚ddl}|j|ƒS)zi Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc module is enabled. rNzUrun_in_subinterp() cannot be used if tracemalloc module is tracing memory allocations)Ú tracemallocrnZ is_tracingrsrtréÚrun_in_subinterp)rÁr£rérdrdrer¤ª s  r¤csHG‡‡fdd„d|ƒ}d‰|||Žƒ‰|jttˆƒtƒ|jˆƒdS)NcseZdZ‡‡fdd„ZdS)z%check_free_after_iterating..Ac s*d‰y tˆƒWntk r$YnXdS)NT)ÚnextÚ StopIteration)rh)ÚdoneÚitrdreÚ__del__À s  z-check_free_after_iterating..A.__del__N)r`rarbr©rd)r§r¨rdreÚA¿ srªF)rMr¦r¥r…Z assertTrue)rîr—rCršrªrd)r§r¨reÚcheck_free_after_iterating¾ s   r«cCs�ddlm}m}m}|jƒ}|j|ƒxd|jD]Z}|r@||kr@q.t||ƒ}|rd|dk sntd|ƒ‚n |dkrnq.|j |dƒdkr.|dSq.WdS)a<Check if the compiler components used to build the interpreter exist. Check for the existence of the compiler executables whose names are listed in 'cmd_names' or all the compiler executables when 'cmd_names' is empty and return the first missing executable or None when none is found missing. r)Ú ccompilerrÛÚspawnNz%the '%s' executable is not configured) Z distutilsr¬rÛr­Z new_compilerZcustomize_compilerZ executablesr�rZfind_executable)Z cmd_namesr¬rÛr­Zcompilerrvrœrdrdrer^Ñ s       cCs@d}tr6||kr6tdkr.tjddgƒjƒdkatr6|}tj|ƒS)Ngñh㈵øä>Zgetpropzro.kernel.qemuó1)rAÚ_is_android_emulatorrZ check_outputrarorD)ZintervalZminimum_intervalrdrdrerDë s c cs>tjjƒ}tjƒ}ztjƒdVWd|r8tj|dd�XdS)NT)r¯Z all_threads)ror³rHrZÚ is_enabledrÕrÖ)rBr°rdrdreÚdisable_faulthandlerù s  r±c /Cs€tjjd ƒr8ytjdƒ}t|ƒdStk r6YnXd}ttdƒrjytjdƒ}Wnt k rhYnXd}tjd krÒyd dl }|j Wnt t fk r¢Yn0Xi}x(|j|j|jfD]}|j |d ƒ||<qºWzpd }xft|ƒD]Z}ytj|ƒ}Wn4t k �r(}z|jtjk�r‚WYdd}~XqâXtj|ƒ|d7}qâWWd|dk �rzx*|j|j|jfD]}|j |||ƒ�q`WX|S) z/Count the number of open file descriptors. ÚlinuxÚfreebsdz /proc/self/fdréÚsysconfÚ SC_OPEN_MAXNrr)r²r³)rorprqr…r¡r¼rÂrÝrµr“r�r�rŽrnr’r“r”rOÚdupr¥ZEBADFr) ÚnamesZMAXFDr‘r�r™rPrBZfd2rèrdrdrer_ sP          c@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú SaveSignalszÅ Save an restore signal handlers. This class is only able to save/restore signal handlers registered by the Python signal module: see bpo-13285 for "external" signal handlers. c Csjddl}||_ttd|jƒƒ|_x>dD]6}yt||ƒ}Wntk rNw&YnX|jj|ƒq&Wi|_dS)NrrÚSIGKILLÚSIGSTOP)rºr») Úsignalr|rOÚNSIGÚsignalsr�rŽr{rf)rhr¼ZsignameÚsignumrdrdreriM s zSaveSignals.__init__cCs4x.|jD]$}|jj|ƒ}|dkr"q||j|<qWdS)N)r¾r¼Ú getsignalrf)rhr¿ÚhandlerrdrdreÚsaveZ s   zSaveSignals.savecCs*x$|jjƒD]\}}|jj||ƒq WdS)N)rfr‹r¼)rhr¿rÁrdrdreÚrestoref szSaveSignals.restoreN)r`rarbrcrirÂrÃrdrdrdrer¹D s  r¹c@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚFakePathz.Simple implementing of the path protocol. cCs ||_dS)N)r†)rhr†rdrdrerin szFakePath.__init__cCsd|j›d�S)Nz )r†)rhrdrdreÚ__repr__q szFakePath.__repr__cCs6t|jtƒs$t|jtƒr,t|jtƒr,|j‚n|jSdS)N)r¿r†Ú BaseExceptionrãrz)rhrdrdreÚ __fspath__t s    zFakePath.__fspath__N)r`rarbrcrirÆrÈrdrdrdrerÄk srÄc cs.tjƒ}ztj|ƒdVWdtj|ƒXdS)z>Temporarily change the integer string conversion length limit.N)roÚget_int_max_str_digitsÚset_int_max_str_digits)Z max_digitsZcurrentrdrdreÚadjust_int_max_str_digits| s   rËcCsdd„tddƒDƒdgS)z�Returns a list of C0 control characters as strings. C0 control characters defined as the byte range 0x00-0x1F, and 0x7F. cSsg|] }t|ƒ‘qSrd)Úchr)rCrÄrdrdrerD‹ sz)control_characters_c0..ré ú)rOrdrdrdreÚcontrol_characters_c0‡ srÏ)T)F)F)N)Nii@i@i@ii) rrrrrrrr r!r"r#)r'r%r(r)r*)NF)F)r7F)N)Fi@ii)T)N)Nr)rR)N(rcr`rnÚcollections.abcÚ collectionsÚ contextlibZdatetimer¥rZr?rørÓrþrmÚimportlib.utilrÎZlogging.handlersrerÌr…rprwrÁrr—rßrrorÛr,r¢r‡rsZ urllib.errorrargZ testresultrrJrLZmultiprocessing.processr&ÚzlibrXÚbz2ZlzmarérürŠrár r r rtr Úcontextmanagerrkr rr�r:r;rr6rrrrr0rr�rrrrœrqrªr¬r®rºrÀrr­rrÊrrÞr r!rûr"r#r$r%rErr r rGrHrJrrFrrZ SOCK_MAX_SIZEZ skipUnlessrÚ __getformat__r7r9r0r1r2r@rÜrrArCrvrrâr0Z FS_NONASCIIÚ characterÚfsdecodeÚfsencodeÚ UnicodeErrorZTESTFN_UNICODEZ unicodedataÚ normalizeÚgetfilesystemencodingZTESTFN_ENCODINGZTESTFN_UNENCODABLEZgetwindowsversionÚencodeÚUnicodeEncodeErrorr”ÚdecodeÚUnicodeDecodeErrorZTESTFN_UNDECODABLEZTESTFN_NONASCIIr4rr]r}r3r6rrÝrKr†r‡rÇrˆZTEST_SUPPORT_DIRr;r°r]rrr[rIr&rIÚobjectrer‚rRrƒr‡rSrÚabcÚMutableMappingrTržr'r“r¯r(r©r)r*r+rÑrrrr…r×rÝrárârårärærírìrñrUr\rþrÿrZ_4GrrrYr r3r4r,rrr>r5r!r%r?r"rBr*r+r-r2r3r<r5r7rAr-rDZMISSING_C_DOCSTRINGSZHAVE_DOCSTRINGSZrequires_docstringsr.rHrIZenvironment_alteredrNrOrPrTrLrQrWrVrbZskipIfZrequires_type_collectingrcrdrfrgrMrXrrrr/rzr|r8r~rr<r=rZr¢r¤r«r^r¯rDr±r_r¹rÄrËrÏrdrdrdreÚsÖ                      2   !  J    > %                 %      2 ' 5M            $ # 0           (        " #   "    :_"  ;'