本文整理汇总了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/')
示例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()
示例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()
示例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()
示例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()
示例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
示例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
示例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
示例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
示例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
示例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()
示例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
示例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()
示例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()
示例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"])