
    hh                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r  SSKJr  SSKJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJrJr  SSKJr  \" S5      r " S S\5      r  " S S\5      r! " S S\RD                  5      r#Sr$SS jr%          SS jr& " S S\5      r' " S S\RD                  5      r( " S S\RD                  5      r) " S S\RD                  5      r*g) z"
Tests for Twisted plugin system.
    )annotationsN)invalidate_caches)
ModuleType)Callable	TypedDictTypeVar)	Interface)plugin)FilePath)	EventDictaddObserverremoveObservertextFromEventDict)unittest_Tc                      \ rS rSrSrSrg)ITestPlugin   zG
A plugin for use by the plugin system's unit tests.

Do not use this.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       _/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_plugin.pyr   r      s    r   r   c                      \ rS rSrSrSrg)ITestPlugin2&   z
See L{ITestPlugin}.
r   Nr   r   r   r   r    r    &   s    r   r    c                     \ rS rSrSrSS jrSS jr S     SS jjrSS jr    SS jr	\	SS j5       r
SS	 jr\	SS
 j5       r\	SS j5       r\	SS j5       r\	SS j5       r\	SS j5       r\	SS j5       rSS jrSrg)PluginTests,   zS
Tests which verify the behavior of the current, active Twisted plugins
directory.
c                   [         R                  SS U l        [         R                  R	                  5       U l        [        U R                  5       5      U l        U R                  R                  5         U R                  R                  S5      U l        U R                  R                  5         U R                  R                  S5      R                  S5        [        [        5      R                  S5      R                  U R                  R                  S5      5        SU l        [         R                  R#                  SU R                  R                  5        SSKnXl        g)	zF
Save C{sys.path} and C{sys.modules}, and create a package for tests.
N	mypackage__init__.pyr   zplugin_basic.pyztestplugin.py
testpluginr   )syspathoriginalPathmodulescopysavedModulesr   mktemprootcreateDirectorychildpackage
setContent__file__siblingcopyTooriginalPlugininsertr&   module)selfr&   s     r   setUpPluginTests.setUp2   s      HHQKKK,,.T[[]+			!!#yy{3$$&=)44S9""#45<<LL/	
 +499>>*r   c                    U R                   [        R                  SS& [        R                  R	                  5         [        R                  R                  U R                  5        gzB
Restore C{sys.path} and C{sys.modules} to their original values.
Nr+   r)   r*   r,   clearupdater.   r;   s    r   tearDownPluginTests.tearDownJ   ?     ''4,,-r   c                   UR                   c   eUR                  R                  S5      nSR                  US S 5      nUS   n[	        [
        R                  U   U5        [
        R                  UR                  	 SS/U=(       a    S/=(       d    / -    H'  n [        R                  " UR                   U-   5        M)     g ! [         a     M9  f = f)N.co )
r5   r   splitjoindelattrr)   r,   osremoveFileNotFoundError)r;   r:   deleteSource
modulePathpackageName
moduleNameexts          r   _unimportPythonModule!PluginTests._unimportPythonModuleR   s     ***__**3/
hhz#2/^
K(*5KK(:!62$!<"=C		&//C/0 > % s   #C
CCc                V    U R                   R                  S5      R                  5         g)z+
Remove the plugins B{droping.cache} file.
dropin.cacheN)r3   r2   rQ   rC   s    r   _clearCachePluginTests._clearCacheb   s     	>*113r   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )z
This is a paranoid test wrapper, that calls C{meth} 2 times, clear the
cache, and calls it 2 other times. It's supposed to ensure that the
plugin system behaves correctly no matter what the state of the cache
is.
c                f   > T" U 5        T" U 5        U R                  5         T" U 5        T" U 5        g )N)r\   )r;   meths    r   wrapped+PluginTests._withCacheness.<locals>.wrappedr   s+    JJJJr   )r;   r#   returnNone)	functoolswraps)r`   ra   s   ` r   _withCachenessPluginTests._withCachenessh   s'     
		 
	 r   c                Z   [         R                  " U R                  5      nXR                     nU R	                  UR
                  SU R                   35        U R                  SUR                  5        UR                   Vs/ s H  n[        UR                  ;   d  M  UPM     snS   nU R                  UR                  U5        U R	                  UR                  S5        U R	                  UR                  R                  5       S5        U R	                  UR                  [        [         R                  /5        UR!                  5       nU R                  U["        R$                  SU R                   3   R&                  5        SSKJn  U R                  XVR&                  5        gs  snf )z
Check that the cache returned by L{plugin.getCache} hold the plugin
B{testplugin}, and that this plugin has the properties we expect:
provide L{TestPlugin}, has the good name and description, and can be
loaded successfully.
z
mypackage.zI'm a test drop-in.r   
TestPluginz*A plugin used solely for testing purposes.N)r
   getCacher:   r8   assertEqualrV   assertIndescriptionpluginsr   providedassertIsdropinnamestripIPluginloadr)   r,   rj   mypackage.testpluginr(   )r;   cacherr   pp1
realPlugintps          r   
test_cachePluginTests.test_cache|   sD    ,**+**j9L9L8M,NO+V-?-?@  EA;!**+DaEaHbii(,/ 	NN  "$P	
 	{FNN&CDWWY
KK*T%8%8$9:;FF	
 	*j--0) Fs   F(F(c                    [         R                  " U R                  5      U R                     n[	        S UR
                   5       5      S   nU R                  [        U5      S5        g)zU
L{CachedPlugin} has a helpful C{repr} which contains relevant
information about it.
c              3  H   #    U  H  oR                   S :X  d  M  Uv   M     g7f)rj   Nrs   ).0ry   s     r   	<genexpr>-PluginTests.test_cacheRepr.<locals>.<genexpr>   s     V';!vv?UAA';s   "	"r   zT<CachedPlugin 'TestPlugin'/'mypackage.testplugin' (provides 'ITestPlugin, IPlugin')>N)r
   rk   r:   r8   listro   rl   repr)r;   cachedDropincachedPlugins      r   test_cacheReprPluginTests.test_cacheRepr   s\    
 t{{3D4G4GHV|';';VV
 	1	
r   c                   [        [        R                  " [        U R                  5      5      nU R                  [        U5      S5        SS/nU H.  nUR                  UR                  5        UR                  5         M0     g)z
L{plugin.getPlugins} should return the list of plugins matching the
specified interface (here, L{ITestPlugin2}), and these plugins
should be instances of classes with a C{test} method, to be sure
L{plugin.getPlugins} load classes correctly.
   AnotherTestPluginThirdTestPluginN)
r   r
   
getPluginsr    r:   rl   lenrQ   r   test)r;   ro   namesry   s       r   test_pluginsPluginTests.test_plugins   sa     v((t{{CDWq)$&78ALL$FFH r   c                   [        [        5      R                  S5      R                  U R                  R                  S5      5         U R                  S[        R                  5        U R                  [        [        R                  S   S5      S5        [        [        R                  " [        U R                  5      5      nU R!                  [#        U5      S5        SS	/nU H.  nUR%                  UR&                  5        UR)                  5         M0     U R+                  [        R                  S   S
5        g! U R+                  [        R                  S   S
5        f = f)zM
Check that L{plugin.getPlugins} is able to detect plugins added at
runtime.
plugin_extra1.pypluginextra.pymypackage.pluginextrar&   pluginextraz&mypackage still has pluginextra moduler   rj   FourthTestPluginTN)r   r5   r6   r7   r3   r2   failIfInr)   r,   assertFalsehasattrr   r
   r   r   r:   rl   r   rQ   r   test1rX   r;   plgsr   ry   s       r   test_detectNewFilesPluginTests.test_detectNewFiles   s    	""#56==LL/0	
	SMM13;;?K0-@8
 ))+t{{CDD SY*!#56EQZZ(	  &&s{{3J'KTRD&&s{{3J'KTRs   CD: :%Ec                   [        [        5      R                  S5      R                  U R                  R                  S5      5         [        [        R                  " [        U R                  5      5      nU R                  [        U5      S5        [        [        5      R                  S5      R                  U R                  R                  S5      5        U R                  [        R                  S   5        [        [        R                  " [        U R                  5      5      nU R                  [        U5      S5        / SQnU H.  nUR!                  UR"                  5        UR%                  5         M0     U R                  [        R                  S   S5        g	! U R                  [        R                  S   S5        f = f)
zm
Check that if the content of a plugin change, L{plugin.getPlugins} is
able to detect the new plugins added.
r   r   r   zplugin_extra2.pyr      )rj   r   FifthTestPluginTN)r   r5   r6   r7   r3   r2   r   r
   r   r   r:   rl   r   rX   r)   r,   rQ   r   r   r   s       r   test_detectFilesChanged#PluginTests.test_detectFilesChanged   sG    	""#56==LL/0	
	S))+t{{CDDSY*X&&'9:AA""#34
 &&s{{3J'KL ))+t{{CDDSY*IEQZZ(	  &&s{{3J'KTRD&&s{{3J'KTRs   D2F %Gc                   [        [        5      R                  S5      R                  U R                  R                  S5      5         [        [        R                  " [        U R                  5      5        U R                  [        R                  S   S5        [        [        R                  " [        U R                  5      5      nU R                  S[        U5      5        g! U R                  [        R                  S   S5        f = f)z[
Check that when a dropin file is removed, L{plugin.getPlugins} doesn't
return it anymore.
r   r   r   T   N)r   r5   r6   r7   r3   r2   r   r
   r   r   r:   rX   r)   r,   rl   r   )r;   r   s     r   test_detectFilesRemoved#PluginTests.test_detectFilesRemoved   s     	""#56==LL/0	
	S"";<= &&s{{3J'KTRF%%k4;;?@CI& &&s{{3J'KTRs   .C# #%Dc                   U R                  5       nU R                  [        R                  R	                  U5      5        U R
                  R                  R                  U5         [        [        R                  " [        U R
                  5      5      nU R                  [        U5      S5        U R
                  R                  R                  U5        g! U R
                  R                  R                  U5        f = f)za
Test that getCache skips over any entries in a plugin package's
C{__path__} which do not exist.
r   N)r/   r   rP   r*   existsr:   __path__appendr   r
   r   r   rl   r   rQ   )r;   r*   r   s      r   test_nonexistentPathEntry%PluginTests.test_nonexistentPathEntry  s     {{}-.##D)	.))+t{{CDDSY*KK  ''-DKK  ''-s   %A	C 'C;c                F   [        U R                  5       5      nU R                  UR                  5       5        UR	                  5         UR                  S5      R                  nU R                  R                  R                  U5         [        [        R                  " [        U R                  5      5      nU R                  [        U5      S5        U R                  R                  R!                  U5        g! U R                  R                  R!                  U5        f = f)z
Test that getCache skips over any entries in a plugin package's
C{__path__} which refer to children of paths which are not directories.
test_packager   N)r   r/   r   r   touchr2   r*   r:   r   r   r   r
   r   r   rl   r   rQ   )r;   r*   r2   r   s       r   test_nonDirectoryChildEntry'PluginTests.test_nonDirectoryChildEntry"  s     &'



>*//##E*	/))+t{{CDDSY*KK  ''.DKK  ''.s   
A	C9 9'D c                $   [         R                  " U R                  5        U R                  R	                  S5      n[        [        5      R                  S5      R                  U R                  R	                  S5      5        [        5         [        R                  " U R                  R                  S5        [        R                  " UR                  S5        U R                  [        R                  U R                  R                  S5        U R                  [        R                  UR                  S5        / n[        UR                  5        U R                  [         UR                  5        [         R                  " U R                  5      nU R#                  SU5        U R#                  U R$                  U5        SUR                  [&        R(                  4-  nU H  n[+        U5      nUc   eXF;   d  M    g	   U R-                  S
U< 35        g	)z
The C{dropin.cache} file may not be writable: the cache should still be
attainable, but an error should be logged to show that the cache
couldn't be updated.
r[   r   r   i@     i  r   3Unable to write to plugin cache %s: error number %dN9Did not observe unwriteable cache warning in log events: )r
   rk   r:   r3   r2   r   r5   r6   r7   invalidateImportCachesrP   chmodr*   
addCleanupr   r   r   rm   r8   errnoEPERMr   fail)r;   	cachepatheventsrx   expectedevent	maybeTexts          r   test_deployedModePluginTests.test_deployedMode3  s    	$LL&&~6	 	""#56==LL/0	
 	 
""E*
'$,,"3"3U;)..%8 #%FMM"6,mU+d))51 INNKKL
 
 E)%0I((($	  II &)r   )r:   r+   r8   r3   r0   r.   Nrc   rd   )F)r:   r   rS   boolrc   rd   )r`   zCallable[[PluginTests], object]rc   zCallable[[PluginTests], None])r   r   r   r   r   r<   rD   rX   r\   rg   r}   r   r   r   r   r   r   r   r   r   r   r   r   r#   r#   ,   s    
 0. 8= 04	 4-	&( "1 "1H
    S S: S S@ ' '" . . / / /r   r#   sj   
from twisted.plugin import pluginPackagePaths
__path__.extend(pluginPackagePaths(__name__))
__all__ = []
c                B    SR                  U 5      R                  S5      $ )Nzfrom zope.interface import provider
from twisted.plugin import IPlugin
from twisted.test.test_plugin import ITestPlugin

@provider(IPlugin, ITestPlugin)
class {}:
    pass
ascii)formatencoder   s    r   pluginFileContentsr   m  s      
	r   c                   U R                  5         U R                  S5      nUR                  5         U(       a   UR                  S5      R                  S5        UR                  S5      nUR                  5         U(       a$  UR                  S5      R                  [        5        UR                  US-   5      R                  U5        U$ )z
Create a plugindummy package.
plugindummyr'   r   ro   .py)r1   r2   r4   pluginInitFile)	entrypathpluginContentrealpluginModulepkgplugss         r   _createPluginDummyr   }  s     
//-
(C		- ++C0IIi E	M"--n=	KKu$%00?Lr   c                       \ rS rSr% S\S'   Srg)_HasBoolLegacyKeyi  r   legacyr   N)r   r   r   r   __annotations__r   r   r   r   r   r     s    Lr   r   c                  |    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSrg)DeveloperSetupTestsi  z
These tests verify things about the plugin system without actually
interacting with the deployed 'twisted.plugins' package, instead creating a
temporary package.
c                D   [         R                  SS U l        [         R                  R	                  5       U l        [        U R                  5       5      U l        U R                  R                  5         U R                  R                  S5      U l        U R                  R                  S5      U l        U R                  R                  S5      U l        [        U R                  [        S5      SS5      U l        [        U R                  [        S5      SS5      U l        [        U R                  [        S	5      S
S5      U l        [         R                  R'                  U R                  U R                  4 Vs/ s H  oR                  PM     sn5        U R)                  5         U R                  R                  S5      R                  S5      U l        U R*                  R                  S5      U l        [.        R.                  " 5       n[0        R2                  " U R*                  R                  S5      R                  US-
  4S-  5        [0        R2                  " U R,                  R                  US-
  4S-  5        U R5                  5         U R7                  5         gs  snf )a  
Create a complex environment with multiple entries on sys.path, akin to
a developer's environment who has a development (trunk) checkout of
Twisted, a system installed version of Twisted (for their operating
system's tools) and a project which provides Twisted plugins.
Nsystem_pathdevelopment_pathapplication_pathsystemTplugindummy_builtindevappFplugindummy_appr   ro   r[   zplugindummy_builtin.pyi  r   i  )r)   r*   	savedPathr,   r-   r.   r   r/   fakeRootr1   r2   
systemPathdevPathappPathr   r   systemPackage
devPackage
appPackageextendgetAllPluginssysplugsyscachetimerP   utime
lockSystemresetEnvironment)r;   xnows      r   r<   DeveloperSetupTests.setUp  s    !KK,,. /%%'----m<}}**+=>}}**+=>/OO/94AV
 -LL,U3T;P
 -LL,U3U<M

 	$//4<<)HI)HA)HIJ 	,,];AA)L**>: iik
##$<=BBS4ZMTUDUV
##cDj]Q%67 	 Js   9Jc                    [         R                  " U R                  R                  S5        [         R                  " U R                  R                  S5        g)zG
Lock the system directories, as if they were unwritable by this user.
im  NrP   r   r   r*   r   rC   s    r   r   DeveloperSetupTests.lockSystem  4     	""E*
##U+r   c                    [         R                  " U R                  R                  S5        [         R                  " U R                  R                  S5        g)zG
Unlock the system directories, as if they were writable by this user.
i  Nr   rC   s    r   unlockSystem DeveloperSetupTests.unlockSystem  r   r   c                    SSK n[        [        R                  " [        UR
                  5      5      nU Vs/ s H  o3R                  PM     sn$ s  snf )zT
Get all the plugins loadable from our dummy package, and return their
short names.
r   N)plugindummy.pluginsr   r
   r   r   ro   r   )r;   r   r   plugs       r   r   !DeveloperSetupTests.getAllPlugins  s>     	#"";0C0CDE*+,!$!,,,s   Ac                    U R                  5         [        R                  R                  U R                  U R
                  U R                  4 Vs/ s H  oR                  PM     sn5        gs  snf )zK
Change the environment to what it should be just as the test is
starting.
N)unsetEnvironmentr)   r*   r   r   r   r   )r;   r   s     r   r   $DeveloperSetupTests.resetEnvironment  sI    
 	$,,)VW)VA)VWXWs   A,c                    [        5         [        R                  R                  5         [        R                  R	                  U R
                  5        U R                  [        R                  SS& g)zP
Change the Python environment back to what it was before the test was
started.
N)r   r)   r,   rA   rB   r.   r   r*   rC   s    r   r  $DeveloperSetupTests.unsetEnvironment  sC    
 	 4,,-nnr   c                D    U R                  5         U R                  5         g)z
Reset the Python environment to what it was before this test ran, and
restore permissions on files which were marked read-only so that the
directory may be cleanly cleaned up.
N)r  r  rC   s    r   rD   DeveloperSetupTests.tearDown  s     	
 	r   c                    [        S5       H7  nU R                  5       nUR                  5         U R                  USS/5        M9     g)z
Plugins added in the development path should be loadable, even when
the (now non-importable) system path contains its own idea of the
list of plugins for a package.  Inversely, plugins added in the
system path should not be available.
r   r   r   N)ranger   sortrl   )r;   r   r   s      r   "test_developmentPluginAvailability6DeveloperSetupTests.test_developmentPluginAvailability  s=     qA&&(EJJLUUEN3 r   c                H   U R                   R                  S5      nUR                  [        S5      5        [        R                  " 5       S-
  n[
        R                  " UR                  X"45        UR                  S5      n[        SS9n[        R                  " U R                   R                  4SS0UD6  [
        R                  " UR                  X"45        UR                  5         U R                  5         U R                  SU R                  5       5        U R!                  S	U R                  5       5        U R                  5         UR                  [        S	5      5        U R!                  SU R                  5       5        U R                  S	U R                  5       5        g
)z
Verify that if a stale .pyc file on the PYTHONPATH is replaced by a
fresh .py file, the plugins in the new .py are picked up rather than
the stale .pyc, even if the .pyc is still around.
zstale.pyonei  z	stale.pycT)r   quietr   twoN)r   r2   r4   r   r   rP   r   r*   r6   r   
compileallcompile_dirrQ   r   rm   r   r   )r;   mypathr   pycextras        r   test_freshPyReplacesStalePyc0DeveloperSetupTests.test_freshPyReplacesStalePyc  s1    &&z2,U34IIK$
qf%nn[) ".t33F1FF
A6"eT//12eT//12,U34eT//12eT//12r   c                z   U R                  5         U R                  R                  S5      R                  [	        S5      5        U R                  5         [        R                  R                  U R                  R                  5        / n[        UR                  5        U R                  [        UR                  5        U R                  SU R                  5       5        SU R                   R                  ["        R$                  4-  nU H  n['        U5      nUc   eX$;   d  M    g   U R)                  SU< 35        g)a  
Verify that a failure to write the dropin.cache file on a read-only
path will not affect the list of plugins returned.

Note: this test should pass on both Linux and Windows, but may not
provide useful coverage on Windows due to the different meaning of
"read-only directory".
znewstuff.pyr  r   Nr   )r  r   r2   r4   r   r   r)   r*   rQ   r   r   r   r   r   rm   r   r   r   r   r   r   )r;   r   r   r   r   s        r   test_newPluginsOnReadOnlyPath1DeveloperSetupTests.test_newPluginsOnReadOnlyPath,  s     	=)445G5NO 	))* #%FMM"6eT//12 IMMKKL
 
 E)%0I((($	  II &)r   )r   r   r   r   r   r.   r   r   r   r   r   Nr   )rc   z	list[str])r   r   r   r   r   r<   r   r  r   r   r  rD   r  r  r  r   r   r   r   r   r     s<    ( T,,
-Y%43@&r   r   c                  Z    \ rS rSrSrS
S jrS
S jr        SS jrS
S jrS
S jr	Sr
g	)AdjacentPackageTestsiU  z
Tests for the behavior of the plugin system when there are multiple
installed copies of the package containing the plugins being loaded.
c                z    [         R                  SS U l        [         R                  R	                  5       U l        g)zC
Save the elements of C{sys.path} and the items of C{sys.modules}.
N)r)   r*   r+   r,   r-   r.   rC   s    r   r<   AdjacentPackageTests.setUp[  s)      HHQKKK,,.r   c                    U R                   [        R                  SS& [        R                  R	                  5         [        R                  R                  U R                  5        gr?   r@   rC   s    r   rD   AdjacentPackageTests.tearDownb  rF   r   c                   UR                  U5      nUR                  S5      nUR                  5         UR                  S5      R                  S5        UR                  S5      nUR                  5         UR                  S5      R                  [        5        UR                  US-   5      nUR                  [	        U5      5        U$ )a  
Create a directory containing a Python package named I{dummy} with a
I{plugins} subpackage.

@type root: L{FilePath}
@param root: The directory in which to create the hierarchy.

@type name: C{str}
@param name: The name of the directory to create which will contain
    the package.

@type pluginName: C{str}
@param pluginName: The name of a module to create in the
    I{dummy.plugins} package.

@rtype: L{FilePath}
@return: The directory which was created to contain the I{dummy}
    package.
dummyr'   r   ro   r   )r2   makedirsr4   r   r   )r;   r0   rs   
pluginName	directoryr3   ro   r   s           r   createDummyPackage'AdjacentPackageTests.createDummyPackagej  s    , JJt$	//'*m$//4--	*m$//?}}Z%%78 24 89r   c                   [        U R                  5       5      nUR                  5         U R                  USS5      nU R                  USS5      n[        R
                  R                  UR
                  5        [        R
                  R                  UR
                  5        SSKn[        [        R                  " [        UR                  5      5      nU R                  S/U Vs/ s H  ofR                  PM     sn5        gs  snf )z
Only plugins from the first package in sys.path should be returned by
getPlugins in the case where there are two Python packages by the same
name installed, each with a plugin module by a single name.
first
somepluginsecondr   Nr   r/   r)  r,  r)   r*   r   dummy.pluginsr   r
   r   r   ro   rl   r   r;   r0   firstDirectorysecondDirectoryr(  ro   ry   s          r   .test_hiddenPackageSamePluginModuleNameObscuredCAdjacentPackageTests.test_hiddenPackageSamePluginModuleNameObscured       &00wM11$,O++,,,-v((emmDE'$AAZZ$AB$A   %D
c                   [        U R                  5       5      nUR                  5         U R                  USS5      nU R                  USS5      n[        R
                  R                  UR
                  5        [        R
                  R                  UR
                  5        SSKn[        [        R                  " [        UR                  5      5      nU R                  S/U Vs/ s H  ofR                  PM     sn5        gs  snf )z
Plugins from the first package in sys.path should be returned by
getPlugins in the case where there are two Python packages by the same
name installed, each with a plugin module by a different name.
r/  
thispluginr1  
thatpluginr   Nr2  r4  s          r   3test_hiddenPackageDifferentPluginModuleNameObscuredHAdjacentPackageTests.test_hiddenPackageDifferentPluginModuleNameObscured  r9  r:  )r+   r.   Nr   )r0   FilePath[str]rs   strr*  rA  rc   r@  )r   r   r   r   r   r<   rD   r,  r7  r>  r   r   r   r   r"  r"  U  sC    
/.!),:=	BC(Cr   r"  c                  @    \ rS rSrSrS	S jrS	S jrS	S jrS	S jrSr	g)
PackagePathTestsi  z[
Tests for L{plugin.pluginPackagePaths} which constructs search paths for
plugin packages.
c                4    [         R                  SS U l        g)z#
Save the elements of C{sys.path}.
N)r)   r*   r+   rC   s    r   r<   PackagePathTests.setUp  s      HHQKr   c                >    U R                   [        R                  SS& g)z,
Restore C{sys.path} to its original value.
N)r+   r)   r*   rC   s    r   rD   PackagePathTests.tearDown  s     ''r   c                b   [        S5      n[        S5      nUR                  UR                  /[        l        U R                  [        R
                  " S5      UR                  S5      R                  S5      R                  UR                  S5      R                  S5      R                  /5        g)z
L{plugin.pluginPackagePaths} should return a list containing each
directory in C{sys.path} with a suffix based on the supplied package
name.
foobardummy.pluginsr(  ro   N)r   r*   r)   rl   r
   pluginPackagePathsr2   )r;   rI  rJ  s      r   test_pluginDirectories'PackagePathTests.test_pluginDirectories  s     uouoHHchh'%%o6		'"((388		'"((388	
r   c                .   [        U R                  5       5      nUR                  S5      R                  S5      R                  S5      nUR                  5         UR                  S5      R	                  S5        UR                  S5      R
                  UR                  S5      R
                  /[        l        U R                  [        R                  " S5      UR                  S5      R                  S5      R                  S5      R
                  /5        g)	aa  
L{plugin.pluginPackagePaths} should exclude directories which are
Python packages.  The only allowed plugin package (the only one
associated with a I{dummy} package which Python will allow to be
imported) will already be known to the caller of
L{plugin.pluginPackagePaths} and will most commonly already be in
the C{__path__} they are about to mutate.
rI  r(  ro   r'   r   rJ  rK  N)
r   r/   r2   r)  r4   r*   r)   rl   r
   rL  )r;   r0   rI  s      r   test_pluginPackagesExcluded,PackagePathTests.test_pluginPackagesExcluded  s     &jj%%g.44Y?		- ++C0JJu%**DJJu,=,B,BC%%o6ZZ$$W-33I>CCD	
r   )r+   Nr   )
r   r   r   r   r   r<   rD   rM  rP  r   r   r   r   rC  rC    s    
((
"
r   rC  )rs   rA  rc   bytes)
r   r@  r   rR  r   r   r   rA  rc   r@  )+r   
__future__r   r  r   re   rP   r)   r   	importlibr   r   typesr   typingr   r   r   zope.interfacer	   twistedr
   twisted.python.filepathr   twisted.python.logr   r   r   r   twisted.trialr   r   r   r    TestCaser#   r   r   r   r   r   r"  rC  r   r   r   <module>r]     s   
 #    	 
  A  / / $  , X X "T]) 9 v(## vt	 -2:>NQ&	 ~(++ ~B\C8,, \C~4
x(( 4
r   