
    h                     b    S r SSK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Jr   " S S\	5      rg)	z1Test handling of ``pyproject.toml`` configuration    N)castOptionalUnion)Path)TestCase)_load_pyproject_toml_IncrementalConfigc                   ~    \ rS rSrSrSS.S\S\\\S4   S\\	   4S jjr
S	 rS
 rS rS rS rS rS rS rS rSrg)VerifyPyprojectDotTomlTests   z/Test the `_load_pyproject_toml` helper functionNpathtomlr   returnc                6   Uc  U R                  5       nO[        U5      n[        US5       nUR                  U5        SSS5         [	        U5      $ ! , (       d  f       N= f! [
         a+  n[        US5      (       a  UR                  SU 35        e SnAff = f)z
Read a TOML snipped from a temporary file with `_load_pyproject_toml`

@param toml: TOML content of the temporary file

@param path: Path to which the TOML is written
Nwadd_notezWhile loading:

)mktempstropenwriter   	Exceptionhasattrr   )selfr   r   path_fes         g/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/incremental/tests/test_pyproject.py	_loadToml%VerifyPyprojectDotTomlTests._loadToml   s     <KKMEIE%GGDM 	'..	 
  	q*%%

(/ 	s#   A
A# 
A #
B-&BBc                     [         R                  R                  [        [        U R                  5       5      S5      nU R                  [        [        U5        g)zN
An absent ``pyproject.toml`` file produces no result unless
there is opt-in.
pyproject.tomlN)	osr   joinr   r   r   assertRaisesFileNotFoundErrorr   )r   r   s     r   test_fileNotFound-VerifyPyprojectDotTomlTests.test_fileNotFound-   s:    
 ww||Ddkkm46FG+-A4H    c                 J    SnU R                  [        U R                  U5        g)zp
Syntactially invalid TOML produces an exception. The specific
exception varies by the underlying TOML library.
z[project]
name = "abcN)r%   r   r   r   r   s     r   test_brokenToml+VerifyPyprojectDotTomlTests.test_brokenToml5   s    
 ()T^^T:r)   c                 X    S H$  nU R                  [        U R                  U5        M&     g)z@
`ValueError` is raised when we can't extract the project name.
)
z[tool.notincremental]
z
[project]
z[tool.incremental]
z[project]
[tool.incremental]
Nr%   
ValueErrorr   r+   s     r   test_nameMissing,VerifyPyprojectDotTomlTests.test_nameMissing=   s&    
D j$..$?
r)   c                     S H3  nU R                  [        S5         U R                  U5        SSS5        M5     g! , (       d  f       MG  = f)z=
`TypeError` is raised when the project name isn't a string.
)z[project]
name = false
z[tool.incremental]
name = -1
z([tool.incremental]
[project]
name = 1.0
z!The project name must be a stringN)assertRaisesRegex	TypeErrorr   r+   s     r   test_nameInvalidOptIn1VerifyPyprojectDotTomlTests.test_nameInvalidOptInJ   s@    
D
 ''	3VWt$ XW

 XWs	   ;
A
	c                 X    S H$  nU R                  [        U R                  U5        M&     g)zU
`ValueError` is raised when the ``[tool]`` or ``[tool.incremental]``
isn't a table.
)ztool = false
z[tool]
incremental = false
z[tool]
incremental = 123
z[tool]
incremental = null
Nr0   r+   s     r   test_toolIncrementalInvalid7VerifyPyprojectDotTomlTests.test_toolIncrementalInvalidV   s&    

D j$..$?
r)   c                 X    S H$  nU R                  [        U R                  U5        M&     g)z`
Raise `ValueError` when the ``[tool.incremental]`` section contains
keys other than ``"name"``
)z[tool.incremental]
foo = false
z-[tool.incremental]
name = "OK"
other = false
Nr0   r+   s     r   !test_toolIncrementalUnexpecteKeys=VerifyPyprojectDotTomlTests.test_toolIncrementalUnexpecteKeysc   s&    

D j$..$?	
r)   c                     [        U R                  5       5      nUS-  S-  nUR                  SS9  S H9  nU R                  X1S-  S9nU R	                  U[        SS[        U5      S	95        M;     g
)z
The package has opted-in to Incremental version management when
the ``[tool.incremental]`` section is a dict. The project name
is taken from ``[tool.incremental] name`` or ``[project] name``.
srcfooTparents)z*[project]
name = "Foo"
[tool.incremental]
z [tool.incremental]
name = "Foo"
r"   r   Fooopt_inpackager   Nr   r   mkdirr   assertEqualr	   r   )r   rootpkgr   configs        r   test_setuptoolsOptIn0VerifyPyprojectDotTomlTests.test_setuptoolsOptInn   sz     DKKM"UlU"		$	
D ^^D6F/F^GF"!S
r)   c                     [        U R                  5       5      nUR                  5         U R                  [        S5         U R                  SUS-  S9  SSS5        g! , (       d  f       g= f)z=
Raise `ValueError` when the package root can't be resolved.
z$Can't find the directory of project z[project]
name = "foo"
r"   r   N)r   r   rI   r5   r1   r   )r   rK   s     r   test_packagePathRequired4VerifyPyprojectDotTomlTests.test_packagePathRequired   sX     DKKM"

##J0VWNN+,,   XWWs    A
A+c           
          [        U R                  5       5      nUS-  S-  nUR                  SS9  U R                  SUS-  S9nU R	                  U[        SS	[        U5      S
95        g)zl
The ``[tool.incremental]`` table is not strictly required, but its
``opt_in=False`` indicates its absence.
r@   rA   TrB   z[project]
name = "Foo"
r"   r   FrD   rE   NrH   )r   rK   rL   rM   s       r   test_noToolIncrementalSection9VerifyPyprojectDotTomlTests.test_noToolIncrementalSection   sw    
 DKKM"UlU"		$	'((   

 	X	
r)    )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r	   r   r'   r,   r2   r7   r:   r=   rN   rQ   rT   __static_attributes__rV   r)   r   r   r      sj    9 <@"'c4"8	$	%8I;@
%@	@2
r)   r   )r[   r#   typingr   r   r   pathlibr   twisted.trial.unittestr   incrementalr   r	   r   rV   r)   r   <module>ra      s*    8 	 ( (  + @[
( [
r)   