U
    [eC)                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlmZ d dl	m
Z
 dd ZG dd dejZG d	d
 d
ejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZdS )    N)configparser)base)utilc                 C   st   i }t t| } tjdkr8t }|t	
|  nt }|t	
|  | D ]}t||||< qX|S )N)      )textwrapdedentsixusysversion_infor   ConfigParser	read_fileioStringIOSafeConfigParserreadfpsectionsdictitems)iniconfigparsersection r   U/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pbr/tests/test_util.pyconfig_from_ini   s    
r   c                   @   s   e Zd Zdd ZdS )
TestBasicsc                 C   s   d | _ d}dddddddd	d
dddgdgdddgdgddgdgdgi ddidgddgdgddgddd gfd!d"gfgd#gd$gd%}t|}t|}| || d S )&Na  
            [metadata]
            name = foo
            version = 1.0
            author = John Doe
            author_email = jd@example.com
            maintainer = Jim Burke
            maintainer_email = jb@example.com
            home_page = http://example.com
            summary = A foobar project.
            description = Hello, world. This is a long description.
            download_url = http://opendev.org/x/pbr
            classifier =
                Development Status :: 5 - Production/Stable
                Programming Language :: Python
            platform =
                any
            license = Apache 2.0
            requires_dist =
                Sphinx
                requests
            setup_requires_dist =
                docutils
            python_requires = >=3.6
            provides_dist =
                bax
            provides_extras =
                bar
            obsoletes_dist =
                baz

            [files]
            packages_root = src
            packages =
                foo
            package_data =
                "" = *.txt, *.rst
                foo = *.msg
            namespace_packages =
                hello
            data_files =
                bitmaps =
                    bm/b1.gif
                    bm/b2.gif
                config =
                    cfg/data.cfg
            scripts =
                scripts/hello-world.py
            modules =
                mod1
            fooz1.0zJohn Doezjd@example.comz	Jim Burkezjb@example.comzhttp://example.comzA foobar project.z)Hello, world. This is a long description.zhttp://opendev.org/x/pbrz+Development Status :: 5 - Production/StablezProgramming Language :: Pythonanyz
Apache 2.0ZSphinxrequestsZdocutilsz>=3.6ZbaxbarZbaz srcz*.txt,z*.rstz*.msg)r"   r   ZhelloZbitmapsz	bm/b1.gifz	bm/b2.gifr   zcfg/data.cfgzscripts/hello-world.pyZmod1)nameversionauthorauthor_email
maintainermaintainer_emailurldescriptionlong_descriptiondownload_urlclassifiers	platformslicenseZinstall_requiresZsetup_requiresZpython_requiresprovidesprovides_extras	obsoletesextras_requirepackage_dirpackagespackage_datanamespace_packages
data_filesscripts
py_modules)ZmaxDiffr   r   setup_cfg_to_setup_kwargsZassertDictEqual)selfconfig_textexpectedr   actualr   r   r   test_basics,   sR    4
*
zTestBasics.test_basicsN)__name__
__module____qualname__rA   r   r   r   r   r   *   s   r   c                   @   s`   e Zd Zddddgddgdgdgdd	fd
dddgddgdd	fddi d	fgZdd ZdS )!TestExtrasRequireParsingScenariosZsimple_extrasz
                [extras]
                first =
                    foo
                    bar==1.0
                second =
                    baz>=3.2
                    foo
                r   zbar==1.0zbaz>=3.2zrequests-mockZordereddict)firstsecondtesttest:(python_version=='2.6'))r>   expected_extra_requiresZwith_markersz
                [extras]
                test =
                    foo:python_version=='2.6'
                    bar
                    baz<1.6 :python_version=='2.6'
                    zaz :python_version>'1.0'
                zbaz<1.6r!   Zzaz)rI   rH   Z	no_extraszG
            [metadata]
            long_description = foo
            c                 C   s*   t | j}t|}| | j|d  d S )Nr4   )r   r>   r   r<   assertEqualrJ   r=   r   kwargsr   r   r   test_extras_parsing   s
    

z5TestExtrasRequireParsingScenarios.test_extras_parsingN)rB   rC   rD   	scenariosrN   r   r   r   r   rE      s(   
	'rE   c                   @   s   e Zd Zdd ZdS )TestInvalidMarkersc                 C   s    dddii}|  ttj| d S )NextrasrH   zfoo :bad_marker>'1.0')assertRaisesSyntaxErrorr   r<   )r=   r   r   r   r    test_invalid_marker_raises_error   s    z3TestInvalidMarkers.test_invalid_marker_raises_errorN)rB   rC   rD   rT   r   r   r   r   rP      s   rP   c                   @   s@   e Zd Zdddddddfdd	d
ddddfgZdd ZdS )TestMapFieldsParsingScenariosZsimple_project_urlsa  
                [metadata]
                project_urls =
                    Bug Tracker = https://bugs.launchpad.net/pbr/
                    Documentation = https://docs.openstack.org/pbr/
                    Source Code = https://opendev.org/openstack/pbr
                zhttps://bugs.launchpad.net/pbr/zhttps://docs.openstack.org/pbr/z!https://opendev.org/openstack/pbr)zBug TrackerZDocumentationzSource Code)r>   expected_project_urlsZquery_parametersaG  
                [metadata]
                project_urls =
                    Bug Tracker = https://bugs.launchpad.net/pbr/?query=true
                    Documentation = https://docs.openstack.org/pbr/?foo=bar
                    Source Code = https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=hash
                z*https://bugs.launchpad.net/pbr/?query=truez'https://docs.openstack.org/pbr/?foo=barz@https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=hashc                 C   s*   t | j}t|}| | j|d  d S )NZproject_urls)r   r>   r   r<   rK   rV   rL   r   r   r   test_project_url_parsing   s    

z6TestMapFieldsParsingScenarios.test_project_url_parsingN)rB   rC   rD   rO   rW   r   r   r   r   rU      s    rU   c                   @   s8   e Zd Zdddddgdfddd	gdfgZd
d ZdS )TestKeywordsParsingScenariosZkeywords_listz
                [metadata]
                keywords =
                    one
                    two
                    three
                onetwothree)r>   expected_keywordsZinline_keywordszW
                [metadata]
                keywords = one, two, three
                zone, two, threec                 C   s*   t | j}t|}| | j|d  d S )Nkeywords)r   r>   r   r<   rK   r\   rL   r   r   r   test_keywords_parsing  s    

z2TestKeywordsParsingScenarios.test_keywords_parsingN)rB   rC   rD   rO   r^   r   r   r   r   rX      s   rX   c                   @   s   e Zd Zdd ZdS )TestProvidesExtrasc                 C   s.   d}t |}t|}| ddg|d  d S )NzX
        [metadata]
        provides_extras = foo
                          bar
        r   r!   r2   )r   r   r<   rK   )r=   r   r   rM   r   r   r   test_provides_extras  s    
z'TestProvidesExtras.test_provides_extrasN)rB   rC   rD   r`   r   r   r   r   r_     s   r_   c                   @   s.   e Zd ZdddddgfgdfgZdd Zd	S )
TestDataFilesParsingr9   z
            [files]
            data_files =
                'i like spaces/' =
                    'dir with space/file with spc 2'
                    'dir with space/file with spc 1'
            zi like spaces/zdir with space/file with spc 2zdir with space/file with spc 1)r>   r9   c                 C   s*   t | j}t|}| | j|d  d S )Nr9   )r   r>   r   r<   rK   r9   rL   r   r   r   )test_handling_of_whitespace_in_data_files+  s    

z>TestDataFilesParsing.test_handling_of_whitespace_in_data_filesN)rB   rC   rD   rO   rb   r   r   r   r   ra     s   ra   c                   @   s   e Zd Zdd ZdS )TestUTF8DescriptionFilec           	   	   C   sh   t  \}}d}d}|| }tj|ddd}|| W 5 Q R X t|}t|}| ||d  d S )Nz:
        [metadata]
        description_file = %s
        u    UTF8 description: é"…-ʃŋ'

wutf8)encodingr,   )	tempfilemkstempr   openwriter   r   r<   rK   )	r=   _pathZini_templateZunicode_descriptionr   fr   rM   r   r   r   test_utf8_description_file3  s    
z2TestUTF8DescriptionFile.test_utf8_description_fileN)rB   rC   rD   rn   r   r   r   r   rc   2  s   rc   )r   rg   r   r	   Z	six.movesr   r   Z	pbr.testsr   Zpbrr   r   ZBaseTestCaser   rE   rP   rU   rX   r_   ra   rc   r   r   r   r   <module>   s    f1(