
    Vh                     b    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y)	z1Test handling of ``pyproject.toml`` configuration    N)castOptionalUnion)Path)TestCase)_load_pyproject_toml_IncrementalConfigc                   r    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y)VerifyPyprojectDotTomlTestsz/Test the `_load_pyproject_toml` helper functionNpathtomlr   returnc                   || j                         }nt        |      }t        |d      5 }|j                  |       ddd       	 t	        |      S # 1 sw Y   xY w# t
        $ r&}t        |d      r|j                  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         P/home/dcms/DCMS/lib/python3.12/site-packages/incremental/tests/test_pyproject.py	_loadTomlz%VerifyPyprojectDotTomlTests._loadToml   s     <KKMEIE% 	GGDM		'..		 	
  	q*%

(/ 	s#   A
A A	B&!BBc                     t         j                  j                  t        t        | j                               d      }| j                  t        t        |       y)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-   s:    
 ww||Ddkkm46FG+-A4H    c                 J    d}| j                  t        | j                  |       y)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                 T    dD ]#  }| j                  t        | j                  |       % y)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 ]2  }| j                  t        d      5  | j                  |       ddd       4 y# 1 sw Y   ?xY w)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   sL    
 	%D
 ''	3VW %t$% %	%
% %s	   9A	c                 T    dD ]#  }| j                  t        | j                  |       % y)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                 T    dD ]#  }| j                  t        | j                  |       % y)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        | j                               }|dz  dz  }|j                  d       dD ]?  }| j                  ||dz        }| j	                  |t        ddt        |      	             A y
)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     DKKM"UlU"		$	
 	D ^^Dt6F/F^GF"!S	r&   c                     t        | j                               }|j                          | j                  t        d      5  | j                  d|dz         ddd       y# 1 sw Y   yxY w)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`     DKKM"

##J0VW 	NN+,,  	 	 	s    A  A)c           
          t        | j                               }|dz  dz  }|j                  d       | j                  d|dz        }| j	                  |t        dd	t        |      
             y)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   sw    
 DKKM"UlU"		$	'((   

 	X	
r&   )__name__
__module____qualname____doc__r   r   r   r   r	   r   r%   r)   r.   r2   r4   r6   rF   rH   rJ    r&   r   r   r      sj    9 <@"'c4"8	$	%8I;@
%@	@2
r&   r   )rN   r!   typingr   r   r   pathlibr   twisted.trial.unittestr   incrementalr   r	   r   rO   r&   r   <module>rT      s*    8 	 ( (  + @[
( [
r&   