U
    jP^                     @   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dS )    N)configparser)base)utilc                 C   sd   i }t jdkrt }nt }tt| } |	t
|  | D ]}t||||< qH|S )N)      )sysversion_infor   ConfigParserZSafeConfigParsertextwrapdedentsixuZreadfpioStringIOZsectionsdictitems)iniconfigparserZsection r   5/usr/lib/python3/dist-packages/pbr/tests/test_util.pyconfig_from_ini   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
                foozbar==1.0zbaz>=3.2zrequests-mockZordereddict)firstsecondtesttest:(python_version=='2.6'))config_text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.6barZzaz)r   r   Z	no_extraszG
            [metadata]
            long_description = foo
            c                 C   s*   t | j}t|}| | j|d  d S )NZextras_require)r   r   r   setup_cfg_to_setup_kwargsassertEqualr   selfr   kwargsr   r   r   test_extras_parsingR   s
    

z5TestExtrasRequireParsingScenarios.test_extras_parsingN)__name__
__module____qualname__	scenariosr&   r   r   r   r   r   )   s(   
	'r   c                   @   s   e Zd Zdd ZdS )TestInvalidMarkersc                 C   s    dddii}|  ttj| d S )NZextrasr   zfoo :bad_marker>'1.0')ZassertRaisesSyntaxErrorr   r!   )r$   r   r   r   r    test_invalid_marker_raises_error\   s    z3TestInvalidMarkers.test_invalid_marker_raises_errorN)r'   r(   r)   r-   r   r   r   r   r+   Z   s   r+   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://git.openstack.org/cgit/openstack-dev/pbr/
                zhttps://bugs.launchpad.net/pbr/zhttps://docs.openstack.org/pbr/z1https://git.openstack.org/cgit/openstack-dev/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!   r"   r/   r#   r   r   r   test_project_url_parsing   s    

z6TestMapFieldsParsingScenarios.test_project_url_parsingN)r'   r(   r)   r*   r0   r   r   r   r   r.   a   s    r.   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
                ZoneZtwoZ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!   r"   r2   r#   r   r   r   test_keywords_parsing   s    

z2TestKeywordsParsingScenarios.test_keywords_parsingN)r'   r(   r)   r*   r4   r   r   r   r   r1      s   r1   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    Zprovides_extras)r   r   r!   r"   )r$   r   r   r%   r   r   r   test_provides_extras   s    
z'TestProvidesExtras.test_provides_extrasN)r'   r(   r)   r6   r   r   r   r   r5      s   r5   c                   @   s.   e Zd ZdddddgfgdfgZdd Zd	S )
TestDataFilesParsing
data_filesz
            [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   r8   c                 C   s.   t | j}t|}| | jt|d  d S )Nr8   )r   r   r   r!   r"   r8   listr#   r   r   r   )test_handling_of_whitespace_in_data_files   s
    


z>TestDataFilesParsing.test_handling_of_whitespace_in_data_filesN)r'   r(   r)   r*   r:   r   r   r   r   r7      s   r7   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)encodingZlong_description)	tempfileZmkstempr   openwriter   r   r!   r"   )	r$   _pathZini_templateZunicode_descriptionr   fr   r%   r   r   r   test_utf8_description_file   s    
z2TestUTF8DescriptionFile.test_utf8_description_fileN)r'   r(   r)   rE   r   r   r   r   r;      s   r;   )r   r?   r
   r   Z	six.movesr   r   Z	pbr.testsr   Zpbrr   r   ZBaseTestCaser   r+   r.   r1   r5   r7   r;   r   r   r   r   <module>   s   1(