bg*dZddlZddlZddlZddlZddlmZddlmZddl m Z dZ Gddej Z ed krejdSdS) aV Test the :py:class`pyfakefs.example` module to demonstrate the usage of the :py:class`pyfakefs.fake_filesystem_unittest.TestCase` base class. Fake filesystem functions like `create_file()`, `create_dir()` or `create_symlink()` are often used to set up file structures at the beginning of a test. While you could also use the familiar `open()`, `os.mkdirs()` and similar functions, these functions can make the test code shorter and more readable. `create_file()` is particularly convenient because it creates all parent directories and allows you to specify the contents or the size of the file. N)fake_filesystem_unittest)use_scandir_package)examplec:tj|||tS)z9Load the pyfakefs/example.py doctest tests into unittest.)r load_doctestsr)loadertestsignores l/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pyfakefs/tests/example_test.py load_testsr 's # 1&% Q QQc~eZdZdZdZdZdZdZdZdZ dZ d Z e j e d d Zd Zd S) TestExamplezTest the example module. The os and shutil modules have been replaced with the fake modules, so that all of the calls to os and shutil in the tested example code occur in the fake filesystem. ctjt|_t j|jd5}||_dddn #1swxYwY| dS)aInvoke the :py:class:`pyfakefs.fake_filesystem_unittest.TestCase` `self.setUp()` method. This defines: * Attribute `self.fs`, an instance of :py:class:`pyfakefs.fake_filesystem.FakeFilesystem`. This is useful for creating test files. * Attribute `self.stubs`, an instance of :py:class:`pyfakefs.mox3_stubout.StubOutForTesting`. Use this if you need to define additional stubs. rbN) ospathrealpath__file__filepathioopenread real_contents setUpPyfakefs)selffs r setUpzTestExample.setUp3s((22 WT]D ) ) *Q!"D  * * * * * * * * * * * * * * * sA**A.1A.cdSNrs r tearDownzTestExample.tearDownFs r c|tjdtjd|tjd|tjdtjd|tjddS)zSTest example.create_file() which uses `open()` and `file.write()`. /testz/test/file.txtN) assertFalserrisdirmkdir assertTrueexistsr create_filer"s r test_create_filezTestExample.test_create_fileJs w//000   g../// (899:::,--- '78899999r c.|jdd|tjdt jd|tjddS)z4Test example.delete_file() which uses `os.remove()`.z/test/full.txtzFirst line Second Line )contentsN) fsr+r)rrr*r delete_filer&r"s r test_delete_filezTestExample.test_delete_fileVs{ ,7UVVV '788999,--- (899:::::r c|tjd|jd|tjddS)z9Test example.path_exists() which uses `os.path.exists()`.z/test/empty.txtN)r&r path_existsr/r+r)r"s r test_file_existszTestExample.test_file_exists]s] ,->??@@@ -... +,=>>?????r c|tjd|jd|tjdtjd|tjd|tj dgtj d}ttj d}|r||ddgd S||ddgd S) zTest example.get_glob().r%/test/dir1/dir2a/test/dir1/dir2bz/test/dir1/nonexistent*winz/test/dir1/dir*z/test/dir1\dir2az/test/dir1\dir2bN)r&rrr'r/ create_dirr)makedirs assertEqualrget_globsysplatform startswithsorted)r is_windowsmatching_pathss r test_get_globszTestExample.test_get_globscs- w//000 -...  &899::: &'''  &899::: )*CDDbIII\,,U33  01B C CDD  W   ^.ACV-W X X X X X   ^.@BT-U V V V V Vr c|jdtjd|tjd|tjdtjd| tj ddS)z/Test example.rm_tree() using `shutil.rmtree()`.r6r7z /test/dir1N) r/r9rr:r)rr'rrm_treer&r*r"s r test_rm_treezTestExample.test_rm_treets -... &'''  &899:::  &899::: %%%  5566666r c|jd|jd|jd|jddt t jdd}|dt||d |d j | |d  | |d  | |d  d S)zTest example.scandir() which uses `os.scandir()`. The os module has been replaced with the fake os module so the fake filesystem path entries are returned instead of `os.DirEntry` objects. /test/text.txt /test/dirz/linktest/linkedz/test/linked_filer%c|jSr namees r z-TestExample.test_os_scandir..!&r key linked_filerN)r/r+r9create_symlinkr@rscan_dirr;lenrLr)is_dir is_symlinkis_filerentriess r test_os_scandirzTestExample.test_os_scandirs' ,--- ;''' ./// 24FGGG)'228H8HIII CLL)))  888  ))++,,,  --//000  **,,-----r z+Testing only if scandir module is installedc|jd|jdtt jdd}|dt||d|dj| |d  | |d d S) zTest example.scandir() which uses `scandir.scandir()`. The scandir module has been replaced with the fake_scandir module so the fake filesystem path entries are returned instead of `scandir.DirEntry` objects. rHrIr%c|jSr rKrMs r rOz2TestExample.test_scandir_scandir..rPr rQrVztext.txtrUrN) r/r+r9r@rrXr;rYrLr)rZr\r]s r test_scandir_scandirz TestExample.test_scandir_scandirs ,--- ;''')'228H8HIII CLL))) WQZ_555  ))++,,,  **,,-----r c>|t5tj|jdddn #1swxYwY|j|j|tj|j|jdS)z_Test `example.file_contents()` for a real file after adding it using `add_real_file()`.N) assertRaisesOSErrorr file_contentsrr/ add_real_filer;rr"s r test_real_file_accessz!TestExample.test_real_file_accesss  w ' ' 1 1  !$- 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 dm,,, .t}==t?QRRRRRsAAAN)__name__ __module__ __qualname____doc__rr#r,r1r4rCrFr_unittestskipIfrrbrhr!r r rr,s &    : : :;;;@@@ WWW" 7 7 7...&X_ !N... SSSSSr r__main__)rlrrr=rmpyfakefsrpyfakefs.extra_packagesrpyfakefs.testsrr TestCaserrimainr!r r rus   ------777777""""""RRR SSSSS*3SSSD zHMOOOOOr