B
    ”Ü‡\¿  ã               @   sd   d Z ddlZddlZddlmZ ejG dd„ deƒƒZG dd„ deƒZdd	d
gZ	dd„ Z
dd„ ZdS )zS
this is a place where we put datastructures used by legacy apis
we hope ot remove
é    N)Ú
UsageErrorc               @   s,   e Zd ZdZe ¡ Zedd„ ƒZdd„ Z	dS )ÚMarkMappingzfProvides a local mapping for markers where item access
    resolves to True if the marker is present. c             C   s   dd„ |  ¡ D ƒ}| |ƒS )Nc             S   s   h | ]
}|j ’qS © )Úname)Ú.0Úmarkr   r   ú2lib/python3.7/site-packages/_pytest/mark/legacy.pyú	<setcomp>   s    z(MarkMapping.from_item.<locals>.<setcomp>)Úiter_markers)ÚclsÚitemZ
mark_namesr   r   r   Ú	from_item   s    zMarkMapping.from_itemc             C   s
   || j kS )N)Úown_mark_names)Úselfr   r   r   r   Ú__getitem__   s    zMarkMapping.__getitem__N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚattrZibr   Úclassmethodr   r   r   r   r   r   r      s   r   c               @   s,   e Zd ZdZdd„ Zedd„ ƒZdd„ ZdS )	ÚKeywordMappingzwProvides a local mapping for keywords.
    Given a list of names, map any substring of one of these names to True.
    c             C   s
   || _ d S )N)Ú_names)r   Únamesr   r   r   Ú__init__!   s    zKeywordMapping.__init__c             C   s~   t ƒ }dd l}x(| ¡ D ]}t||jƒs| |j¡ qW | | ¡ ¡ t	|dƒr^| |j
j¡ | dd„ | ¡ D ƒ¡ | |ƒS )Nr   Úfunctionc             s   s   | ]}|j V  qd S )N)r   )r   r   r   r   r   ú	<genexpr>7   s    z+KeywordMapping.from_item.<locals>.<genexpr>)ÚsetÚpytestZ	listchainÚ
isinstanceZInstanceÚaddr   ÚupdateZlistextrakeywordsÚhasattrr   Ú__dict__r
   )r   r   Zmapped_namesr   r   r   r   r   $   s    
zKeywordMapping.from_itemc             C   s    x| j D ]}||krdS qW dS )NTF)r   )r   Úsubnamer   r   r   r   r   ;   s    zKeywordMapping.__getitem__N)r   r   r   r   r   r   r   r   r   r   r   r   r      s   r   ÚorÚandÚnotc          
   C   sJ   yt |i t | ¡ƒS  tk
rD } ztt|ƒd ƒ‚W dd}~X Y nX dS )zBTries to match on any marker names, attached to the given colitem.z(
Marker expression must be valid Python!N)Úevalr   r   ÚSyntaxErrorÚstr)ÚcolitemZmarkexprÚer   r   r   Ú	matchmarkE   s    r-   c             C   s¬   t  | ¡}d|kr|| S | d¡rFd|dd… krF||dd…   S x0| ¡ D ]$}t |¡rP|tkrPtd |¡ƒ‚qPW yt	|i |ƒS  t
k
r¦   td |¡ƒ‚Y nX dS )a|  Tries to match given keyword expression to given collector item.

    Will match on the name of colitem, including the names of its parents.
    Only matches names of items which are either a :class:`Class` or a
    :class:`Function`.
    Additionally, matches on names in the 'extra_keyword_matches' set of
    any item, as well as names directly assigned to test functions.
    ú znot é   Nz>Python keyword '{}' not accepted in expressions passed to '-k'z#Wrong expression passed to '-k': {})r   r   Ú
startswithÚsplitÚkeywordÚ	iskeywordÚpython_keywords_allowed_listr   Úformatr(   r)   )r+   ZkeywordexprÚmappingZkwdr   r   r   ÚmatchkeywordM   s    	
r7   )r   r2   r   Z_pytest.configr   ÚsÚobjectr   r   r4   r-   r7   r   r   r   r   Ú<module>   s   &
