
    Sf                     j    d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZ  G d de	          ZdS )	z1Test handling of ``pyproject.toml`` configuration    N)castOptionalUnion)Path)TestCase)_load_pyproject_toml_IncrementalConfigc                       e Zd ZdZdddedeeedf         dee         fdZ	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )VerifyPyprojectDotTomlTestsz/Test the `_load_pyproject_toml` helper functionNpathtomlr   returnc                ^   ||                                  }nt          |          }t          |d          5 }|                    |           ddd           n# 1 swxY w Y   	 t	          |          S # t
          $ r.}t          |d          r|                    d|             d}~ww xY w)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         R/var/www/html/env/lib/python3.11/site-packages/incremental/tests/test_pyproject.py	_loadTomlz%VerifyPyprojectDotTomlTests._loadToml   s     <KKMMEEIIE% 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 		'... 	 	 	q*%% 

///   	s)   AA A%A4 4
B,>)B''B,c                     t           j                            t          t          |                                           d          }|                     t          t          |           dS )zf
        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_fileNotFoundz-VerifyPyprojectDotTomlTests.test_fileNotFound-   sL    
 w||Ddkkmm446FGG+-A4HHHHH    c                 L    d}|                      t          | j        |           dS )z
        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_brokenTomlz+VerifyPyprojectDotTomlTests.test_brokenToml5   s)    
 ()T^T:::::r&   c                 R    dD ]#}|                      t          | j        |           $dS )zP
        `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_nameMissingz,VerifyPyprojectDotTomlTests.test_nameMissing=   s@    
 	@ 	@D j$.$????	@ 	@r&   c                     dD ]J}|                      t          d          5  |                     |           ddd           n# 1 swxY w Y   KdS )zM
        `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_nameInvalidOptInz1VerifyPyprojectDotTomlTests.test_nameInvalidOptInJ   s    
 	% 	%D
 ''	3VWW % %t$$$% % % % % % % % % % % % % % %	% 	%s   AA		A	c                 R    dD ]#}|                      t          | j        |           $dS )zm
        `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
Nr,   r(   s     r   test_toolIncrementalInvalidz7VerifyPyprojectDotTomlTests.test_toolIncrementalInvalidV   s@    

 	@ 	@D j$.$????	@ 	@r&   c                 R    dD ]#}|                      t          | j        |           $dS )zx
        Raise `ValueError` when the ``[tool.incremental]`` section contains
        keys other than ``"name"``
        )z[tool.incremental]
foo = false
z-[tool.incremental]
name = "OK"
other = false
Nr,   r(   s     r   !test_toolIncrementalUnexpecteKeysz=VerifyPyprojectDotTomlTests.test_toolIncrementalUnexpecteKeysc   s@    

 	@ 	@D j$.$????		@ 	@r&   c                 (   t          |                                           }|dz  dz  }|                    d           dD ]O}|                     ||dz            }|                     |t          ddt          |          	                     Pd
S )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_setuptoolsOptInz0VerifyPyprojectDotTomlTests.test_setuptoolsOptInn   s     DKKMM""UlU"		$	
 	 	D ^^Dt6F/F^GGF"!S     	 	r&   c                    t          |                                           }|                                 |                     t          d          5  |                     d|dz             ddd           dS # 1 swxY w Y   dS )zM
        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   rA   r0   r-   r   )r   rC   s     r   test_packagePathRequiredz4VerifyPyprojectDotTomlTests.test_packagePathRequired   s     DKKMM""

##J0VWW 	 	NN+,,    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A99A= A=c           
         t          |                                           }|dz  dz  }|                    d           |                     d|dz            }|                     |t          dd	t          |          
                     dS )z
        The ``[tool.incremental]`` table is not strictly required, but its
        ``opt_in=False`` indicates its absence.
        r8   r9   Tr:   z[project]
name = "Foo"
r    r   Fr<   r=   Nr@   )r   rC   rD   rE   s       r   test_noToolIncrementalSectionz9VerifyPyprojectDotTomlTests.test_noToolIncrementalSection   s    
 DKKMM""UlU"		$	'((   
 

 	XX  	
 	
 	
 	
 	
r&   )__name__
__module____qualname____doc__r   r   r   r   r	   r   r%   r)   r.   r2   r4   r6   rF   rH   rJ    r&   r   r   r      s        99 <@  "'c4"8	$	%   8I I I; ; ;@ @ @
% 
% 
%@ @ @	@ 	@ 	@  2  
 
 
 
 
r&   r   )rN   r!   typingr   r   r   pathlibr   twisted.trial.unittestr   incrementalr   r	   r   rO   r&   r   <module>rT      s    8 7 				 ( ( ( ( ( ( ( ( ( (       + + + + + + @ @ @ @ @ @ @ @[
 [
 [
 [
 [
( [
 [
 [
 [
 [
r&   