o
    >h                     @   s\   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 de	ZdS )	z1Test handling of ``pyproject.toml`` configuration    N)castOptionalUnion)Path)TestCase)_load_pyproject_toml_IncrementalConfigc                   @   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   path_fe r   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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_brokenToml5   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   n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_nameInvalidOptInJ   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_toolIncrementalInvalidV   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_toolIncrementalUnexpecteKeysc   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opt_inpackager   Nr   r   mkdirr   assertEqualr   r   )r   rootpkgr   configr   r   r   test_setuptoolsOptInn   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   r8   r*   r(   r   )r   r:   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/   r0   Tr1   z[project]
name = "Foo"
r   r
   Fr3   r4   Nr7   )r   r:   r;   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	   )rC   r   typingr   r   r   pathlibr   twisted.trial.unittestr   incrementalr   r   r	   r   r   r   r   <module>   s   