當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。