当前位置: 首页>>代码示例>>Python>>正文


Python fake_filesystem_unittest.Patcher方法代码示例

本文整理汇总了Python中pyfakefs.fake_filesystem_unittest.Patcher方法的典型用法代码示例。如果您正苦于以下问题:Python fake_filesystem_unittest.Patcher方法的具体用法?Python fake_filesystem_unittest.Patcher怎么用?Python fake_filesystem_unittest.Patcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyfakefs.fake_filesystem_unittest的用法示例。


在下文中一共展示了fake_filesystem_unittest.Patcher方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def setup(self):
        """Setup before each method"""
        config_data = basic_streamalert_config()

        self.fs_patcher = fake_filesystem_unittest.Patcher()
        self.fs_patcher.setUp()

        self.fs_patcher.fs.create_file(
            './conf/global.json', contents=json.dumps(config_data['global']))
        self.fs_patcher.fs.create_file(
            './conf/threat_intel.json', contents=json.dumps(config_data['threat_intel']))
        self.fs_patcher.fs.create_file(
            './conf/normalized_types.json', contents=json.dumps(config_data['normalized_types']))
        self.fs_patcher.fs.create_file(
            './conf/lambda.json', contents=json.dumps(config_data['lambda']))
        self.fs_patcher.fs.create_file(
            './conf/clusters/prod.json', contents=json.dumps(config_data['clusters']['prod']))

        # Create the config instance after creating the fake filesystem so that
        # CLIConfig uses our mocked config files instead of the real ones.
        self.config = CLIConfig('./conf/') 
开发者ID:airbnb,项目名称:streamalert,代码行数:23,代码来源:test_cli_config.py

示例2: test_delete_upload_file

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_delete_upload_file(self, mock_open):

        resource_id = str(uuid.uuid4())
        path = '/doesnt_exist/resources/{}/{}/{}'.format(
            resource_id[0:3], resource_id[3:6], resource_id[6:]
        )

        patcher = fake_filesystem_unittest.Patcher()
        patcher.setUp()
        patcher.fs.CreateFile(path)

        assert os.path.exists(path)

        delete_local_uploaded_file(resource_id)

        assert not os.path.exists(path)

        patcher.tearDown() 
开发者ID:frictionlessdata,项目名称:ckanext-validation,代码行数:20,代码来源:test_utils.py

示例3: test_delete_file_not_deleted_if_resources_first

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_delete_file_not_deleted_if_resources_first(self, mock_open):

        resource_id = str(uuid.uuid4())
        path = '/doesnt_exist/resources/{}'.format(resource_id)

        patcher = fake_filesystem_unittest.Patcher()
        patcher.setUp()
        patcher.fs.CreateFile(path)

        assert os.path.exists(path)
        with mock.patch('ckanext.validation.utils.get_local_upload_path',
                        return_value=path):
            delete_local_uploaded_file(resource_id)

        assert not os.path.exists(path)
        assert os.path.exists('/doesnt_exist/resources')

        patcher.tearDown() 
开发者ID:frictionlessdata,项目名称:ckanext-validation,代码行数:20,代码来源:test_utils.py

示例4: test_delete_file_not_deleted_if_resources_second

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_delete_file_not_deleted_if_resources_second(self, mock_open):

        resource_id = str(uuid.uuid4())
        path = '/doesnt_exist/resources/data/{}'.format(resource_id)

        patcher = fake_filesystem_unittest.Patcher()
        patcher.setUp()
        patcher.fs.CreateFile(path)

        assert os.path.exists(path)
        with mock.patch('ckanext.validation.utils.get_local_upload_path',
                        return_value=path):
            delete_local_uploaded_file(resource_id)

        assert not os.path.exists(path)
        assert os.path.exists('/doesnt_exist/resources')

        patcher.tearDown() 
开发者ID:frictionlessdata,项目名称:ckanext-validation,代码行数:20,代码来源:test_utils.py

示例5: test_delete_passes_if_os_exeception

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_delete_passes_if_os_exeception(self, mock_open):

        resource_id = str(uuid.uuid4())
        path = '/doesnt_exist/resources/{}/{}/{}'.format(
            resource_id[0:3], resource_id[3:6], resource_id[6:]
        )

        patcher = fake_filesystem_unittest.Patcher()
        patcher.setUp()
        patcher.fs.CreateFile(path)

        assert os.path.exists(path)
        with mock.patch('ckanext.validation.utils.os.remove',
                        side_effect=OSError):

            delete_local_uploaded_file(resource_id)


        patcher.tearDown() 
开发者ID:frictionlessdata,项目名称:ckanext-validation,代码行数:21,代码来源:test_utils.py

示例6: test_discarding_nothing_no_filter

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_discarding_nothing_no_filter(capsys):
    class Case1(TestCase):
        def test_something(self):
            pass

    class Case2(TestCase):
        def test_something(self):
            pass

    class MockSuite(TestSuite):
        components = [Case1, Case2]

    with Patcher() as patcher:
        patcher.fs.add_real_file(DEFAULT_CONFIG_PATH)
        patcher.fs.add_real_file(DEFAULT_SCHEMA_PATH)
        patcher.fs.create_file("some_test.py")

        with mock.patch("rotest.cli.client.discover_tests_under_paths",
                        return_value={MockSuite}):
            sys.argv = ["rotest", "some_test.py", "--list"]

            main()
            out, _ = capsys.readouterr()
            assert "Case1.test_something" in out
            assert "Case2.test_something" in out 
开发者ID:gregoil,项目名称:rotest,代码行数:27,代码来源:test_client.py

示例7: test_discarding_nothing_star_filter

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_discarding_nothing_star_filter(capsys):
    class Case1(TestCase):
        def test_something(self):
            pass

    class Case2(TestCase):
        def test_something(self):
            pass

    with Patcher() as patcher:
        patcher.fs.add_real_file(DEFAULT_CONFIG_PATH)
        patcher.fs.add_real_file(DEFAULT_SCHEMA_PATH)
        patcher.fs.create_file("some_test.py")

        with mock.patch("rotest.cli.client.discover_tests_under_paths",
                        return_value={Case1, Case2}):
            sys.argv = ["rotest", "some_test.py", "--filter", "*", "--list"]

            main()
            out, _ = capsys.readouterr()
            assert "Case1.test_something" in out
            assert "Case2.test_something" in out 
开发者ID:gregoil,项目名称:rotest,代码行数:24,代码来源:test_client.py

示例8: test_discarding_some_tests_by_name

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_discarding_some_tests_by_name(capsys):
    class Case1(TestCase):
        def test_something(self):
            pass

    class Case2(TestCase):
        def test_something(self):
            pass

    with Patcher() as patcher:
        patcher.fs.add_real_file(DEFAULT_CONFIG_PATH)
        patcher.fs.add_real_file(DEFAULT_SCHEMA_PATH)
        patcher.fs.create_file("some_test.py")

        with mock.patch("rotest.cli.client.discover_tests_under_paths",
                        return_value={Case1, Case2}):
            sys.argv = ["rotest", "some_test.py",
                        "--filter", "Case2",
                        "--list"]

            main()
            out, _ = capsys.readouterr()
            assert "Case1.test_something" not in out
            assert "Case2.test_something" in out 
开发者ID:gregoil,项目名称:rotest,代码行数:26,代码来源:test_client.py

示例9: test_basic_cpython

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_basic_cpython(caplog):

    # Use very basic settings without networking.
    import test.settings.basic as settings

    with FakeFS():

        with caplog.at_level(logging.DEBUG):

            # Invoke bootloader.
            bootloader = invoke_umal()

            # Start datalogger with a single duty cycle on a fake filesystem.
            from terkin.datalogger import TerkinDatalogger
            datalogger = TerkinDatalogger(settings, platform_info=bootloader.platform_info)
            datalogger.setup()
            datalogger.duty_task()

            # Capture log output.
            captured = caplog.text

            # Proof it works by verifying log output.
            assert "Starting Terkin datalogger" in captured, captured
            assert "platform: linux2" in captured, captured 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:26,代码来源:test_basic.py

示例10: mock_fs

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def mock_fs():
    """Mock filesystem calls with pyfakefs."""

    # Ordering matters for reloading modules. Patch upstream dependencies first, otherwise downstream dependencies will
    # "cache" before monkey-patching occurs. i.e. config uses xdg, xdg needs to be reloaded first
    modules_to_reload = [
        xdg,
        config,
    ]

    with Patcher(modules_to_reload=modules_to_reload) as patcher:
        yield patcher.fs 
开发者ID:edmundmok,项目名称:mealpy,代码行数:14,代码来源:conftest.py

示例11: fs_reload_deployer

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def fs_reload_deployer() -> Generator[FakeFilesystem, None, None]:
    patcher = Patcher(
        modules_to_reload=[raiden_contracts.contract_manager, raiden_contracts.deploy.__main__]
    )
    patcher.setUp()
    yield patcher.fs
    patcher.tearDown() 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:9,代码来源:test_deploy_script.py

示例12: test_yielding_test_files

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_yielding_test_files():
    with Patcher() as patcher:
        patcher.fs.create_dir("root")
        patcher.fs.create_file(os.path.join("root", "test_something.py"))
        patcher.fs.create_file(os.path.join("root", "some_test.py"))

        sub_files = {os.path.join(os.sep, "root", "test_something.py"),
                     os.path.join(os.sep, "root", "some_test.py")}

        assert set(get_test_files(["root"])) == sub_files 
开发者ID:gregoil,项目名称:rotest,代码行数:12,代码来源:test_discover.py

示例13: test_skipping_files_by_whitelist

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_skipping_files_by_whitelist():
    with Patcher() as patcher:
        patcher.fs.create_dir("root")
        patcher.fs.create_file("root/some_file.txt")

        assert set(get_test_files(["root"])) == set() 
开发者ID:gregoil,项目名称:rotest,代码行数:8,代码来源:test_discover.py

示例14: test_skipping_files_by_blacklist

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_skipping_files_by_blacklist():
    with Patcher() as patcher:
        patcher.fs.create_dir("root")
        patcher.fs.create_dir("root/.git")
        patcher.fs.create_file("root/.git/test_something.py")

        assert set(get_test_files(["root"])) == set() 
开发者ID:gregoil,项目名称:rotest,代码行数:9,代码来源:test_discover.py

示例15: test_importing_bad_file

# 需要导入模块: from pyfakefs import fake_filesystem_unittest [as 别名]
# 或者: from pyfakefs.fake_filesystem_unittest import Patcher [as 别名]
def test_importing_bad_file():
    """Assert that importing a class with bugs raises an import error."""
    with Patcher() as patcher:
        patcher.fs.create_file("some_bad_test.py",
                               contents="from lie import non_existing")

        with pytest.raises(ImportError):
            discover_tests_under_paths(["some_bad_test.py"]) 
开发者ID:gregoil,项目名称:rotest,代码行数:10,代码来源:test_discover.py


注:本文中的pyfakefs.fake_filesystem_unittest.Patcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。