Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pyfakefs/tests/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pyfakefs/tests/__pycache__/test_utils.cpython-37.pyc

B

��\);�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZGdd�de
�ZGdd�dej�ZGd	d
�d
e
�ZGdd�dee�ZdS)
z;Common helper classes used in tests, or as test class base.�N)�fake_filesystem)�is_byte_stringc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�	DummyTimezBMock replacement for time.time. Increases returned time on access.cCs||_||_d|_dS)NF)�	curr_time�	increment�started)�selfrr�r	�J/opt/alt/python37/lib/python3.7/site-packages/pyfakefs/tests/test_utils.py�__init__"szDummyTime.__init__cCs
d|_dS)NT)r)rr	r	r
�start'szDummyTime.startcOs|jr|j|j7_|jS)N)rrr)r�args�kwargsr	r	r
�__call__*szDummyTime.__call__N)�__name__�
__module__�__qualname__�__doc__rrrr	r	r	r
rsrc@sXeZdZdZejdkZejdkZejdkZej	ddkZ
dZdd	�Zd
d�Z
dd
�ZdS)�TestCasez<Test base class with some convenience methods and attributes�win32�cygwin�darwinr�NcCs|�t�|�t�|��S)N)�assertEqual�stat�S_IMODE)rZexpected�actualr	r	r
�assert_mode_equal8szTestCase.assert_mode_equalc
OsNy|||�|�d�Wn0tk
rH}z|�||j�Wdd}~XYnXdS)z5Asserts that a specific subtype of IOError is raised.z)No exception was raised, IOError expectedN)�fail�IOErrorr�errno)r�subtype�
expressionr
r�excr	r	r
�assert_raises_io_error;s

zTestCase.assert_raises_io_errorc
OsNy|||�|�d�Wn0tk
rH}z|�||j�Wdd}~XYnXdS)z5Asserts that a specific subtype of OSError is raised.z)No exception was raised, OSError expectedN)r�OSErrorrr )rr!r"r
rr#r	r	r
�assert_raises_os_errorCs

zTestCase.assert_raises_os_error)rrrr�sys�platform�
is_windowsZ	is_cygwin�is_macos�version_info�
is_python2�symlinks_can_be_testedrr$r&r	r	r	r
r0s


rc@s�eZdZdZdd�Zedd��Zdd�Zedd	��Zed
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd6d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd7d,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd+S)8�RealFsTestMixina�Test mixin to allow tests to run both in the fake filesystem and in the
    real filesystem.
    To run tests in the real filesystem, a new test class can be derived from
    the test class testing the fake filesystem which overwrites
    `use_real_fs()` to return `True`.
    All tests in the real file system operate inside the local temp path.

    In order to make a test able to run in the real FS, it must not use the
    fake filesystem functions directly. For access to `os` and `open`,
    the respective attributes must be used, which point either to the native
    or to the fake modules. A few convenience methods allow to compose
    paths, create files and directories.
    cCs>d|_t|_t|_tjddk|_d|_|��r:t�	�|_dS)Nr�)
�
filesystem�open�osr'r+r,�	base_path�use_real_fs�tempfile�mkdtemp)rr	r	r
r[szRealFsTestMixin.__init__cCstjS)N)rr))rr	r	r
�
is_windows_fsdszRealFsTestMixin.is_windows_fscCs*|jdk	r&||j_|rd|j_|��dS)NF)r0r7r*�create_basepath)r�valuer	r	r
�set_windows_fshs

zRealFsTestMixin.set_windows_fscCstjS)N)rr*)rr	r	r
r*oszRealFsTestMixin.is_macoscCst��dkS)N�PyPy)r(�python_implementation)rr	r	r
�is_pypysszRealFsTestMixin.is_pypycCsdS)z4Return True if the real file system shall be tested.Fr	)rr	r	r
r4wszRealFsTestMixin.use_real_fscCs|��rtjjSdS)zNCan be overwritten to use a specific separator in the
        fake filesystem.�/)r4r2�path�sep)rr	r	r
�path_separator{szRealFsTestMixin.path_separatorcCs(|��rtjs$t�d��n
|�d�dS)z�If called at test start, the real FS test is executed only under
        Windows, and the fake filesystem test emulates a Windows system.
        z&Testing Windows specific functionalityTN)r4rr)�unittest�SkipTestr:)rr	r	r
�check_windows_only�s
z"RealFsTestMixin.check_windows_onlycCs6|��r tjstjr2t�d��n|�d�d|j_dS)z�If called at test start, the real FS test is executed only under
        Linux, and the fake filesystem test emulates a Linux system.
        z$Testing Linux specific functionalityFN)r4rr*r)rBrCr:r0)rr	r	r
�check_linux_only�s
z RealFsTestMixin.check_linux_onlycCs0|��rtjs,t�d��n|�d�d|j_dS)z�If called at test start, the real FS test is executed only under
        MacOS, and the fake filesystem test emulates a MacOS system.
        z$Testing MacOS specific functionalityFTN)r4rr*rBrCr:r0)rr	r	r
�check_macos_only�s
z RealFsTestMixin.check_macos_onlycCs&|��rtjr"t�d��nd|j_dS)z�If called at test start, the real FS test is executed only under
        Linux and Windows, and the fake filesystem test emulates a Linux
        system under MacOS.
        zTesting non-MacOs functionalityFN)r4rr*rBrCr0)rr	r	r
�check_linux_and_windows�s
z'RealFsTestMixin.check_linux_and_windowscCs,|��r tjs(tjs(t�d��nd|j_dS)z�If called at test start, the real FS test is executed only in a
        case-insensitive FS (e.g. Windows or MacOS), and the fake filesystem
        test emulates a case-insensitive FS under the running OS.
        z/Testing case insensitive specific functionalityFN)r4rr*r)rBrCr0�is_case_sensitive)rr	r	r
�check_case_insensitive_fs�s
z)RealFsTestMixin.check_case_insensitive_fscCs,|��r tjstjr(t�d��nd|j_dS)z�If called at test start, the real FS test is executed only in a
        case-sensitive FS (e.g. under Linux), and the fake file system test
        emulates a case-sensitive FS under the running OS.
        z-Testing case sensitive specific functionalityTN)r4rr*r)rBrCr0rH)rr	r	r
�check_case_sensitive_fs�s
z'RealFsTestMixin.check_case_sensitive_fscCs(|��rtjr$t�d��n
|�d�dS)z�If called at test start, the real FS test is executed only under
        Linux and MacOS, and the fake filesystem test emulates a Linux
        system under Windows.
        z$Testing Posix specific functionalityFN)r4rr)rBrCr:)rr	r	r
�check_posix_only�s
z RealFsTestMixin.check_posix_onlycCs|��rt�d��dS)z5If called at test start, no real FS test is executed.zOnly tests fake FSN)r4rBrC)rr	r	r
�skip_real_fs�szRealFsTestMixin.skip_real_fsTcCsf|��rbtjr|sDtjs |r |sDtjr*|sDtjs:tjs:|sDtjsb|rbtjrN|sXtjsb|rbt�d��dS)z�If called at test start, no real FS test is executed for the given
        conditions. This is used to mark tests that do not pass correctly under
        certain systems and shall eventually be fixed.
        z.Skipping because FakeFS does not match real FSN)r4rr)r*r,rBrC)rZskip_windowsZ
skip_posixZ
skip_macosZ
skip_linuxZskip_python2Zskip_python3r	r	r
�skip_real_fs_failure�s





z$RealFsTestMixin.skip_real_fs_failurec	Csrtjr|��sdStjdkrl|�d�}y&|j�|j|�dt_|j�|�Wnt	t
fk
rjdt_YnXtjS)z�Used to check if symlinks and hard links can be tested under
        Windows. All tests are skipped under Windows for Python versions
        not supporting links, and real tests are skipped if running without
        administrator rights.
        TN�linkF)rr)r4r-�	make_pathr2�symlinkr3�remover%�NotImplementedError)r�	link_pathr	r	r
�symlink_can_be_tested�s

z%RealFsTestMixin.symlink_can_be_testedcCsH|��rtjs|��s2|jjr2tjdkr2t�d��|�	�sDt�d��dS)zQIf called at test start, tests are skipped if symlinks are not
        supported.)rrz:Symlinks are not supported under Windows before Python 3.3z,Symlinks under Windows need admin privilegesN)
r4rr)r0r7r'r+rBrCrT)rr	r	r
�skip_if_symlink_not_supporteds
z-RealFsTestMixin.skip_if_symlink_not_supportedcGsv|js t|dt�r |j��}n|j}t|dttf�rb|}x |dD]}|jj�	||�}qFW|S|jjj	|f|��S)a$Create a path with the given component(s). A base path is prepended
        to the path which represents a temporary directory in the real FS,
        and a fixed path in the fake filesystem.
        Always use to compose absolute paths for tests also running in the
        real FS.
        r)
r,�
isinstance�bytesr3�encode�list�tupler2r?�join)rr
r3r?�argr	r	r
rOszRealFsTestMixin.make_pathcCsz|}g}x4|r<|jj�|�s<|jj�|�\}}|�d|�q
Wx6|D].}|jj�||�}|j�|�|j�|d�qDWdS)z�Create the directory at `dir_path`, including subdirectories.
        `dir_path` shall be composed using `make_path()`.
        ri�N)r2r?�exists�split�insertr[�mkdir�chmod)r�dir_pathZ
existing_path�
components�	componentr	r	r
�
create_dir!s
zRealFsTestMixin.create_dirNc	Cs�|�|jj�|��|dk	s$t|�r(dnd}|dk	rF|dk	rF|�|�}|�||��}|dk	rf|�|�WdQRX|j�|d�dS)z�Create the given file at `file_path` with optional contents,
        including subdirectories. `file_path` shall be composed using
        `make_path()`.
        N�wb�wi�)	rer2r?�dirnamerrXr1�writera)r�	file_path�contents�encoding�mode�fr	r	r
�create_file/s
zRealFsTestMixin.create_filecCs&|�|jj�|��|j�||�dS)z�Create the path at `link_path`, and a symlink to this path at
        `target_path`. `link_path` shall be composed using `make_path()`.
        N)rer2r?rhrP)rrS�target_pathr	r	r
�create_symlink?szRealFsTestMixin.create_symlinkc	Cs<t|�rdnd}|�||��}|�||���WdQRXdS)zcCompare `contents` with the contents of the file at `file_path`.
        Asserts equality.
        �rb�rN)rr1r�read)rrjrkrmrnr	r	r
�check_contentsFszRealFsTestMixin.check_contentscCstj}|jr|jrtj}|S)N)r �ENOTDIRr7r,�EINVAL)r�errorr	r	r
�
not_dir_errorNszRealFsTestMixin.not_dir_errorcCs||jdk	rx|j}|jjd|_|jr0d|j|_||jkrx|dk	rL|j��|j�|j�sh|j�|j�|dk	rx|��dS)z1Create the path used as base path in `make_path`.NZbasepathzC:)r0r3rAr7�resetr]re�setUpFileSystem)rZ
old_base_pathr	r	r
r8Ts


zRealFsTestMixin.create_basepath)TTTTTT)NN)rrrrr�propertyr7r:r*r=r4rArDrErFrGrIrJrKrLrMrTrUrOrerorqruryr8r	r	r	r
r.Ls8
	


r.c@sJeZdZdZddd�Zdd�Zdd�Zed	d
��Zedd��Z	d
d�Z
dS)�RealFsTestCasezMCan be used as base class for tests also running in the real
    file system.�runTestcCst�||�t�|�dS)N)rrr.)rZ
methodNamer	r	r
rhszRealFsTestCase.__init__cCsjt��|_|��sJtj|��d�|_t�|j�|_	t�
|j�|_|��ntj�
d�s^|��|��dS)N)rAZTEST_REAL_FS)r2�getcwd�cwdr4r�FakeFilesystemrAr0�FakeFileOpenr1�FakeOsModuler8�environ�getrLr{)rr	r	r
�setUpls

zRealFsTestCase.setUpcCsdS)Nr	)rr	r	r
r{yszRealFsTestCase.setUpFileSystemcCs|��r|jS|jjS)N)r4r)r0r7)rr	r	r
r7|szRealFsTestCase.is_windows_fscCs|��rtjS|jjS)N)r4rr*r0)rr	r	r
r*�szRealFsTestCase.is_macoscCs@|��r<|j�tj�|j��tj|jdd�|j�|j�dS)NT)�
ignore_errors)	r4r2�chdirr?rhr3�shutil�rmtreer�)rr	r	r
�tearDown�szRealFsTestCase.tearDownN)r~)rrrrrr�r{r|r7r*r�r	r	r	r
r}ds

r})rr r2r(r�rr'r5rB�pyfakefsr�pyfakefs.helpersr�objectrrr.r}r	r	r	r
�<module>s