Your IP : 216.73.216.213
B
��\H � @ s� d Z ddlZddlZddlZddlZyddlZdZW n ek
rL dZY nX dd� Zdd� Z d d
� Z
dd� Zd
d� Zdd� Z
dd� ZdS )a�
Example module that is tested in :py:class`pyfakefs.example_test.TestExample`.
This demonstrates the usage of the
:py:class`pyfakefs.fake_filesystem_unittest.TestCase` base class.
The modules related to file handling are bound to the respective fake modules:
>>> os #doctest: +ELLIPSIS
<pyfakefs.fake_filesystem.FakeOsModule object...>
>>> os.path #doctest: +ELLIPSIS
<pyfakefs.fake_filesystem.FakePathModule object...>
>>> shutil #doctest: +ELLIPSIS
<pyfakefs.fake_filesystem_shutil.FakeShutilModule object...>
Both `open()` and `file` built-ins are bound to the fake `open()` in Python 2.
In Python 3, `open()` is an alias for `io.open()` and is bound to
`FakeIoModule.open` instead.
� NTFc C s4 t | d�� }|�d�| �� |�d� W dQ R X dS )a� Create the specified file and add some content to it. Use the `open()`
built in function.
For example, the following file operations occur in the fake file system.
In the real file system, we would not even have permission
to write `/test`:
>>> os.path.isdir('/test')
False
>>> os.mkdir('/test')
>>> os.path.isdir('/test')
True
>>> os.path.exists('/test/file.txt')
False
>>> create_file('/test/file.txt')
>>> os.path.exists('/test/file.txt')
True
>>> with open('/test/file.txt') as f:
... f.readlines()
["This is test file '/test/file.txt'.\n", 'It was created using open().\n']
�wzThis is test file '{0}'.
zIt was created using open().
N)�open�write�format)�path�f� r �G/opt/alt/python37/lib/python3.7/site-packages/pyfakefs/tests/example.py�create_file/ s r
c C s t �| � dS )a0 Delete the specified file.
For example:
>>> os.mkdir('/test')
>>> os.path.exists('/test/file.txt')
False
>>> create_file('/test/file.txt')
>>> os.path.exists('/test/file.txt')
True
>>> delete_file('/test/file.txt')
>>> os.path.exists('/test/file.txt')
False
N)�os�remove)r r r r �delete_fileK s r
c C s t j�| �S )a5 Return True if the specified file exists.
For example:
>>> path_exists('/test')
False
>>> os.mkdir('/test')
>>> path_exists('/test')
True
>>>
>>> path_exists('/test/file.txt')
False
>>> create_file('/test/file.txt')
>>> path_exists('/test/file.txt')
True
)r r �exists)r r r r �path_exists] s r c C s
t � | �S )a Return the list of paths matching the specified glob expression.
For example:
>>> os.mkdir('/test')
>>> create_file('/test/file1.txt')
>>> create_file('/test/file2.txt')
>>> file_names = sorted(get_glob('/test/file*.txt'))
>>>
>>> import sys
>>> if sys.platform.startswith('win'):
... # Windows style path
... file_names == [r'\test\file1.txt', r'\test\file2.txt']
... else:
... # UNIX style path
... file_names == ['/test/file1.txt', '/test/file2.txt']
True
)�glob)Z glob_pathr r r �get_globq s r c C s t �| � dS )z$Delete the specified file hierarchy.N)�shutil�rmtree)r r r r �rm_tree� s r c C s2 t rtt�| ��S tjdkr*tt�| ��S t�dS )z6Return a list of directory entries for the given path.)� � N)�has_scandir�list�scandir�sys�version_infor �NotImplementedError)r r r r �scan_dir� s
r c C s t | d��
}|�� S Q R X dS )z4Return the contents of the given path as byte array.�rbN)r �read)r r r r r �
file_contents� s r )�__doc__r r r r r r �ImportErrorr
r
r r r r r r r r r �<module>! s