File: //usr/lib/python3/dist-packages/sphinx/testing/__pycache__/comparer.cpython-310.pyc
o
$�aT � @ sX d Z ddlZddlZddlmZmZmZ G dd� d�Zdededed ee fd
d�Z dS )z�
sphinx.testing.comparer
~~~~~~~~~~~~~~~~~~~~~~~
Sphinx test comparer for pytest
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
� N)�Any�List�Unionc @ s� e Zd ZdZdeeejf fdd�Zdefdd�Z defdd �Z
d
eeejf defdd�Zd
eeejf de
e fd
d�Zd
eeejf de
e fdd�Zd
eeejf de
e fdd�Zdejdejde
e fdd�ZdS )�PathComparera�
OS-independent path comparison.
Windows path sep and posix path sep:
>>> '\to\index' == PathComparer('/to/index')
True
>>> '\to\index' == PathComparer('/to/index2')
False
Windows path with drive letters
>>> 'C:\to\index' == PathComparer('/to/index')
True
>>> 'C:\to\index' == PathComparer('C:/to/index')
True
>>> 'C:\to\index' == PathComparer('D:/to/index')
False
�pathc C s t �|�| _dS )zP
:param str path: path string, it will be cast as pathlib.Path.
N)�pathlib�Pathr )�selfr � r
�9/usr/lib/python3/dist-packages/sphinx/testing/comparer.py�__init__# s zPathComparer.__init__�returnc C s
| j �� S �N)r �as_posix�r r
r
r �__str__) �
zPathComparer.__str__c C s
d� | �S )Nz<{0.__class__.__name__}: '{0}'>)�formatr r
r
r �__repr__, r zPathComparer.__repr__�otherc C s t | �|�� S r )�bool�ldiff�r r r
r
r �__eq__/ s zPathComparer.__eq__c C s
| � |�S )a� compare self and other.
When different is not exist, return empty list.
>>> PathComparer('/to/index').diff('C:\to\index')
[]
When different is exist, return unified diff style list as:
>>> PathComparer('/to/index').diff('C:\to\index2')
[
'- C:/to/index'
'+ C:/to/index2'
'? +'
]
)r r r
r
r �diff2 s
zPathComparer.diffc C s | � | jt�|��S r )�_diffr r r r r
r
r r E s �zPathComparer.ldiffc C s | � t�|�| j�S r )r r r r r r
r
r �rdiffK s �zPathComparer.rdiff�lhs�rhsc C sp ||krg S |j s|j r|�� �� |�� �� }}n |�� |�� }}||kr)g S dd� t�� �|g|g�D �S )Nc S s g | ]}|� � �qS r
)�strip)�.0�liner
r
r �
<listcomp>^ s z&PathComparer._diff.<locals>.<listcomp>)�drive�absoluter �difflib�Differ�compare)r r r �s_path�o_pathr
r
r r Q s zPathComparer._diffN)�__name__�
__module__�__qualname__�__doc__r �strr r r r r r r r r r r r r
r
r
r r s "r �op�left�rightr
c C sH t |t�r| dkrdg|�|� S t |t�r"| dkr"dg|�|� S g S )Nz==zComparing path:)�
isinstancer r r )r/ r0 r1 r
r
r �pytest_assertrepr_comparea s
r3 )
r- r% r �typingr r r r r. r3 r
r
r
r �<module> s "R