T雓Z z d Z ddlZddlZddlZ ddlZdZn# e$ r dZdZY nw xY wd Zd Zd Z d Z
d Zd
Zd Z
dS )aL
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
>>> os.path #doctest: +ELLIPSIS
>>> shutil #doctest: +ELLIPSIS
`open()` is an alias for `io.open()` and is bound to `FakeIoModule.open`.
NTFc t | dd 5 }| d| d | d ddd dS # 1 swxY w Y 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', encoding='utf8') as f:
... f.readlines()
["This is test file '/test/file.txt'.\n", 'It was created using open().\n']
wutf8)encodingzThis is test file 'z'.
zIt was created using open().
N)openwritepathfs h/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pyfakefs/tests/example.pycreate_filer
. s .
dC& ) ) ) 2Q 0d000111 01112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s /AAAc . t j | 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)osremover
s r delete_filer J s IdOOOOO c @ 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
existsr s r path_existsr \ s " 7>>$r c * t j | 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) glob_paths r get_globr p s &