
    -Phl+                     n    d dl Z d dlmZ d dlmZ ddlmZmZ ddlm	Z	 ddl
mZmZ  G d	 d
e          ZdS )    N)	CliRunner)TestCase   )ConfigErrorload_config)cli   )with_isolated_runnerwritec                       e Zd ZddddededefdZd Zd Zd	 Zd
 Zd Z	d Z
d Zd Zd Zedefd            Zedefd            Zd Zd Zd Zd ZdS )TomlSettingsTests )pyproject_tomltowncrier_tomlr   r   returnc                   |                                  }t          j        |           |r0t          t          j                            |d          |d           |r0t          t          j                            |d          |d           |S )zP
        Create a temporary directory with a pyproject.toml file in it.
        zpyproject.tomlT)dedentztowncrier.toml)mktemposmakedirsr   pathjoin)selfr   r   project_dirs       \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/towncrier/test/test_settings.pymktemp_projectz TomlSettingsTests.mktemp_project   s     kkmm
K    	[*:;;     	[*:;;        c                 ^   |                      d          }t          |          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           dS )	z'
        Test a "base config".
        zu
                [tool.towncrier]
                package = "foobar"
                orphan_prefix = "~"
            r   foobar.zNEWS.rst)=-~r$   N)r   r   assertEqualpackagepackage_dirfilename
underlinesorphan_prefixr   r   configs      r   	test_basezTomlSettingsTests.test_base(   s     )) * 
 
 [))222+S111*555*O<<<-s33333r   c                     |                      d          }t          |          }|                     |j        d           |                     |j        d           dS )z
        If the filename references an .md file and the builtin template doesn't have an
        extension, add .md rather than .rst.
        zv
                [tool.towncrier]
                package = "foobar"
                filename = "NEWS.md"
            r   NEWS.md)towncrier.templatesz
default.mdNr   r   r%   r(   templater+   s      r   test_markdownzTomlSettingsTests.test_markdown;   si    
 )) * 
 
 [)))444*OPPPPPr   c                     |                      d          }t          |          }|                     |j        d           |                     |j        d           dS )z|
        If the filename references an .md file and the builtin template has an
        extension, don't change it.
        z
                [tool.towncrier]
                package = "foobar"
                filename = "NEWS.md"
                template = "towncrier:default.rst"
            r   r/   r0   zdefault.rstNr1   r+   s      r    test_explicit_template_extensionz2TomlSettingsTests.test_explicit_template_extensionN   si    
 )) * 
 
 [)))444*PQQQQQr   c                     |                      d          }t          |          }|                     |j        d           dS )z
        The template can be any package and resource, and although we look for a
        resource's 'templates' package, it could also be in the specified resource
        directly.
        z
                [tool.towncrier]
                package = "foobar"
                template = "towncrier.templates:default.rst"
            r   r5   N)r   r   r%   r2   r+   s      r   test_template_extendedz(TomlSettingsTests.test_template_extendeda   sQ     )) * 
 
 [))*PQQQQQr   c                     |                      d          }|                     t                    5 }t          |           ddd           n# 1 swxY w Y   |                     |j        j        d           dS )zQ
        If the config file doesn't have the correct toml key, we error.
        zI
                [something.else]
                blah='baz'
            r   Nallr   assertRaisesr   r   r%   	exceptionfailing_optionr   r   es      r   test_missingzTomlSettingsTests.test_missings   s     )) * 
 
 {++ 	%q$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	3U;;;;;   AAAc                     |                      d          }|                     t                    5 }t          |           ddd           n# 1 swxY w Y   |                     |j        j        d           dS )z-
        single_file must be a bool.
        zP
                [tool.towncrier]
                single_file = "a"
            r   Nsingle_filer;   r?   s      r   test_incorrect_single_filez,TomlSettingsTests.test_incorrect_single_file        )) * 
 
 {++ 	%q$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	3]CCCCCrB   c                     |                      d          }|                     t                    5 }t          |           ddd           n# 1 swxY w Y   |                     |j        j        d           dS )z-
        all_bullets must be a bool.
        zP
                [tool.towncrier]
                all_bullets = "a"
            r   Nall_bulletsr;   r?   s      r   test_incorrect_all_bulletsz,TomlSettingsTests.test_incorrect_all_bullets   rF   rB   c                     |                      d          }|                     t                    5 }t          |           ddd           n# 1 swxY w Y   |                     |j        j        d           dS )z=
        singlefile is not accepted, single_file is.
        zO
                [tool.towncrier]
                singlefile = "a"
            r   N
singlefiler;   r?   s      r   test_mistype_singlefilez)TomlSettingsTests.test_mistype_singlefile   s     )) * 
 
 {++ 	%q$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	3\BBBBBrB   c                     |                      dd          }t          |          }|                     |j        d           dS )zZ
        Towncrier prefers the towncrier.toml for autodetect over pyproject.toml.
        zL
                [tool.towncrier]
                package = "a"
            zL
                [tool.towncrier]
                package = "b"
            )r   r   aN)r   r   r%   r&   r+   s      r   test_towncrier_toml_preferredz/TomlSettingsTests.test_towncrier_toml_preferred   sU     )) * 	
 	
 [))-----r   runnerc                 >   |                                  }t          j        |           |                    t          d|f          }|                     |j        dt          j                            |           d           |                     |j	        d           dS )z
        Calling the root CLI without an existing configuration file in the base directory,
        will exit with code 1 and an informative message is sent to standard output.
        z--dirz/No configuration file found.
Looked back from: 
r	   N)
r   r   r   invoker   r%   outputr   abspath	exit_code)r   rP   tempresults       r   test_load_no_configz%TomlSettingsTests.test_load_no_config   s     {{}}
DsWdO44MXrwt?T?TXXX	
 	
 	
 	)1-----r   c                     d}|                     t          d|f          }|                     |j        d           |                     |j        dt
          j                            |           d           dS )z
        Calling the CLI with an incorrect explicit configuration file will exit with
        code 1 and an informative message is sent to standard output.
        znot-there.tomlz--configr	   zConfiguration file 'z' not found.
N)rS   r   r%   rV   rT   r   r   rU   )r   rP   r,   rX   s       r   !test_load_explicit_missing_configz3TomlSettingsTests.test_load_explicit_missing_config   s}     "sZ$899)1---MJ27??6#:#:JJJ	
 	
 	
 	
 	
r   c                    |                      d          }|                     t                    5 }t          |           ddd           n# 1 swxY w Y   |                     t          |j                  d                    t          j	        
                    t          j	                            |d                                         dS )zY
        Towncrier will raise an exception saying when it can't find a template.
        zS
                [tool.towncrier]
                template = "foo.rst"
            r   Nz&The template file '{}' does not exist.zfoo.rst)r   r<   r   r   r%   strr=   formatr   r   normpathr   r?   s      r   test_missing_templatez'TomlSettingsTests.test_missing_template   s     )) * 
 
 {++ 	%q$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	4;;  k9!E!EFF 	
 	
 	
 	
 	
rB   c                    |                      d          }|                     t                    5 }t          |           ddd           n# 1 swxY w Y   |                     t          |j                  d           dS )z~
        Towncrier will raise an exception saying when it can't find a template
        from the Towncrier templates.
        zY
                [tool.towncrier]
                template = "towncrier:foo"
            r]   Nz5'towncrier' does not have a template named 'foo.rst'.)r   r<   r   r   r%   r^   r=   r?   s      r   "test_missing_template_in_towncrierz4TomlSettingsTests.test_missing_template_in_towncrier   s    
 )) * 
 
 {++ 	%q$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	U	
 	
 	
 	
 	
rB   c                     |                      d          }t          |          }dddddfdd	dddfd
ddddfg}t          |          }|j        }|                     ||           dS )a  
        Custom fragment categories can be defined inside
        the toml config file using an array of tables
        (a table name in double brackets).

        This functionality is considered deprecated, but we continue
        to support it to keep backward compatibility.
        a  
                [tool.towncrier]
                package = "foobar"
                [[tool.towncrier.type]]
                directory="foo"
                name="Foo"
                showcontent=false

                [[tool.towncrier.type]]
                directory="spam"
                name="Spam"
                showcontent=true

                [[tool.towncrier.type]]
                directory="auto"
                name="Automatic"
                showcontent=true
                check=false
            r   fooFooFTnameshowcontentcheckspamSpamauto	AutomaticN)r   r   dicttypesassertDictEqualr   r   r,   expectedactuals        r   ,test_custom_types_as_tables_array_deprecatedz>TomlSettingsTests.test_custom_types_as_tables_array_deprecated  s     )) * 
 
* [)) !#(!  "#'!  '#'" #
4 >>Xv.....r   c                     |                      d          }t          |          }ddddddddddddd	dddd
}|j        }|                     ||           dS )zm
        Custom fragment categories can be defined inside
        the toml config file using tables.
        a  
                [tool.towncrier]
                package = "foobar"
                [tool.towncrier.fragment.feat]
                ignored_field="Bazz"
                [tool.towncrier.fragment.fix]
                [tool.towncrier.fragment.chore]
                name = "Other Tasks"
                showcontent = false
                [tool.towncrier.fragment.auto]
                name = "Automatic"
                check = false
            r   zOther TasksFTrg   FeatFixrn   )chorefeatfixrm   N)r   r   rp   rq   rr   s        r   test_custom_types_as_tablesz-TomlSettingsTests.test_custom_types_as_tablesJ  s    
 )) * 
 
 [)) &$  #  #  $# !
 
, Xv.....r   N)__name__
__module____qualname__r^   r   r-   r3   r6   r8   rA   rE   rI   rL   rO   r
   r   rY   r[   ra   rc   ru   r|    r   r   r   r      su       ')  !$;>	   24 4 4&Q Q Q&R R R&R R R$< < < D D D D D D C C C . . .$ .) . . . .  
	 
 
 
 

 
 
*
 
 
&;/ ;/ ;/z,/ ,/ ,/ ,/ ,/r   r   )r   click.testingr   twisted.trial.unittestr   	_settingsr   r   _shellr   helpersr
   r   r   r   r   r   <module>r      s    
			 # # # # # # + + + + + + 0 0 0 0 0 0 0 0       0 0 0 0 0 0 0 0h/ h/ h/ h/ h/ h/ h/ h/ h/ h/r   