관리-도구
편집 파일: fake_filesystem_unittest.cpython-311.pyc
� �܋f�� � �� � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" ddl#Z#ddl$Z$ddl#m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- dd l.m/Z/ dd l0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: dd l4m;Z; ddl4m<Z< ddl4m=Z= ddl>m?Z?m@Z@ e@rddl4mAZA ejB dk rdndZCejB dk rdndZD d4ddddde*jE ddd�dee deeeeFef deee deeeFef deGdeGd e*d!eGd"eGd#efd$�ZHdZIddddde*jE dfd%ed&e%d'ed(edeeeeFef deee deeeFef deGdeGd e*d!eGd#e%fd)�ZJ G d*� d+� � ZK G d,� d-e#jL eK� � ZL G d.� d/� � ZM G d0� d1� � ZN G d2� d3ee� � ZOdS )5a� This module provides a base class derived from `unittest.TestClass` for unit tests using the :py:class:`pyfakefs` module. `fake_filesystem_unittest.TestCase` searches `sys.modules` for modules that import the `os`, `io`, `path` `shutil`, and `pathlib` modules. The `setUpPyfakefs()` method binds these modules to the corresponding fake modules from `pyfakefs`. Further, the `open()` built-in is bound to a fake `open()`. It is expected that `setUpPyfakefs()` be invoked at the beginning of the derived class' `setUp()` method. There is no need to add anything to the derived class' `tearDown()` method. During the test, everything uses the fake file system and modules. This means that even in your test fixture, familiar functions like `open()` and `os.makedirs()` manipulate the fake file system. Existing unit tests that use the real file system can be retrofitted to use pyfakefs by simply changing their base class from `:py:class`unittest.TestCase` to `:py:class`pyfakefs.fake_filesystem_unittest.TestCase`. � N)�Loader�MetaPathFinder)� ModuleType� TracebackType�FunctionType) �Any�Callable�Dict�List�Set�Tuple�Optional�Union�Type�Iterator�cast� ItemsView�Sequence)� TestSuite)�set_uid�set_gid� reset_ids� PatchMode�FakeFilesystem)�IS_PYPY)�StubOutForTesting)� ModuleSpec)�reload)�fake_filesystem�fake_io�fake_os� fake_open� fake_path� fake_file)�fake_filesystem_shutil)�fake_pathlib)�mox3_stubout)�pathlib2�use_scandir)�fake_scandir�win32�nt�posix�ntpath� posixpathTF��additional_skip_names�modules_to_reload�modules_to_patch�allow_root_user�use_known_patches�patch_open_code�patch_default_args� use_cache�_funcr1 r2 r3 r4 r5 r6 r7 r8 �returnc �� ��������� dt dt f��������fd�} | rRt | � � st d� � �t | d� � rt | j � � | _ | | � � S | S )a= Convenience decorator to use patcher with additional parameters in a test function. Usage:: @patchfs def test_my_function(fake_fs): fake_fs.create_file('foo') @patchfs(allow_root_user=False) def test_with_patcher_args(fs): os.makedirs('foo/bar') �fr: c �X �� � t j � � � ��� ������ f d�� � }|S )Nc �� � � t ������ �� �� � 5 }t | � � } | � |j � � �| i |��cd d d � � S # 1 swxY w Y d S )Nr0 )�Patcher�list�append�fs)�args�kwargs�pr1 r4 r<