o
    Îó·iÍ  ã                   @   s\   d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ G dd„ de	ƒZdS )	z1Test handling of ``pyproject.toml`` configurationé    N)ÚPath)ÚOptionalÚUnionÚcast)ÚTestCase)Ú_IncrementalConfigÚ_load_pyproject_tomlc                   @   s‚   e Zd ZdZddœdedeeedf dee fdd„Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚVerifyPyprojectDotTomlTestsz/Test the `_load_pyproject_toml` helper functionN©ÚpathÚtomlr   Úreturnc             
   C   sŽ   |du r	|   ¡ }nt|ƒ}t|dƒ�}| |¡ W d  ƒ n1 s"w   Y  zt|ƒW S  tyF } zt|dƒrA| d|› �¡ ‚ d}~w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   Zpath_ÚfÚe© r   úfC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\incremental/tests/test_pyproject.pyÚ	_loadToml   s   
ÿ

€ýz%VerifyPyprojectDotTomlTests._loadTomlc                 C   s*   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   r   r   r   Útest_fileNotFound,   s   z-VerifyPyprojectDotTomlTests.test_fileNotFoundc                 C   s   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   r   r   r   Útest_brokenToml4   s   z+VerifyPyprojectDotTomlTests.test_brokenTomlc                 C   ó   dD ]
}|   t| j|¡ q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"   r   r   r   Útest_nameMissing<   s   ùz,VerifyPyprojectDotTomlTests.test_nameMissingc              	   C   sD   dD ]}|   td¡� |  |¡ W d  ƒ q1 sw   Y  qd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"   r   r   r   Útest_nameInvalidOptInI   s
   ÿûz1VerifyPyprojectDotTomlTests.test_nameInvalidOptInc                 C   r$   )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"   r   r   r   Útest_toolIncrementalInvalidU   s   úz7VerifyPyprojectDotTomlTests.test_toolIncrementalInvalidc                 C   r$   )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"   r   r   r   Ú!test_toolIncrementalUnexpecteKeysb   s   üz=VerifyPyprojectDotTomlTests.test_toolIncrementalUnexpecteKeysc              	   C   s^   t |  ¡ ƒ}|d d }|jdd� dD ]}| j||d d�}|  |tddt|ƒd	�¡ qd
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©Zopt_inÚpackager   N©r   r   Úmkdirr   ÚassertEqualr   r   )r   ÚrootÚpkgr   Úconfigr   r   r   Útest_setuptoolsOptInm   s   ýþúz0VerifyPyprojectDotTomlTests.test_setuptoolsOptInc                 C   sX   t |  ¡ ƒ}| ¡  |  td¡� | jd|d d� W d  ƒ dS 1 s%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   r6   r)   r'   r   )r   r8   r   r   r   Útest_packagePathRequired†   s   þ"ÿz4VerifyPyprojectDotTomlTests.test_packagePathRequiredc                 C   sT   t |  ¡ ƒ}|d d }|jdd� | jd|d d�}|  |tdd	t|ƒd
�¡ dS )z„
        The ``[tool.incremental]`` table is not strictly required, but its
        ``opt_in=False`` indicates its absence.
        r.   r/   Tr0   z[project]
name = "Foo"
r   r
   Fr2   r3   Nr5   )r   r8   r9   r:   r   r   r   Útest_noToolIncrementalSection“   s   þýþz9VerifyPyprojectDotTomlTests.test_noToolIncrementalSection)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r!   r#   r(   r+   r,   r-   r;   r<   r=   r   r   r   r   r	      s&    ÿÿÿ
þr	   )rA   r   Úpathlibr   Útypingr   r   r   Ztwisted.trial.unittestr   Úincrementalr   r   r	   r   r   r   r   Ú<module>   s   