本文整理汇总了Python中mock.MagicMock.node方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.node方法的具体用法?Python MagicMock.node怎么用?Python MagicMock.node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.node方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_create(self):
if system() == "Darwin":
return
handle, target_file = mkstemp()
remove(target_file)
bundle = MagicMock()
bundle.bundle_dir = mkdtemp()
bundle.bundle_data_dir = mkdtemp()
bundle.node = Node('localhost')
Repository().add_node(bundle.node)
item = files.File(
bundle,
target_file,
{
'content_type': 'mako',
'owner': getuser(),
'source': 'my_template',
},
)
mkdir(item.item_dir)
with open(join(item.item_dir, "my_template"), 'w') as f:
f.write("Hi from ${node.name}!")
item.apply(interactive=False)
with open(target_file) as f:
content = f.read()
try:
self.assertEqual(content, "Hi from localhost!")
finally:
remove(target_file)
示例2: test_chmod
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_chmod(self):
node = MagicMock()
bundle = MagicMock()
bundle.node = node
f = files.File(
bundle,
"/foo",
{'owner': "jcleese", 'group': "mp"},
)
f._fix_owner(MagicMock())
node.run.assert_called_once_with("chown jcleese:mp -- /foo")
示例3: test_chmod
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_chmod(self):
node = MagicMock()
bundle = MagicMock()
bundle.node = node
f = symlinks.Symlink(
bundle,
"/foo",
{'owner': "jcleese", 'group': "mp", 'target': "/bar"},
)
f._fix_owner(MagicMock())
node.run.assert_called_once_with("chown -h jcleese:mp -- /foo")
示例4: test_file_previews
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_file_previews(self):
args = MagicMock()
args.file_preview_path = self.tmpdir
args.node = "node1"
args.show_repr = False
list(items.bw_items(self.repo, args))
self.assertTrue(exists(join(self.tmpdir, "foo/47")))
self.assertFalse(exists(join(self.tmpdir, "foo/48")))
with open(join(self.tmpdir, "foo/47")) as f:
self.assertEqual(f.read(), "content")
示例5: test_regular
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_regular(self):
node = MagicMock()
bundle = MagicMock()
bundle.bundle_dir = "/b/dir"
bundle.node = node
f = files.File(
bundle,
"/foo",
{'content': "47", 'content_type': 'mako'},
)
f._fix_content(MagicMock())
node.upload.assert_called_once()
示例6: test_rm
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_rm(self, fix_content):
node = MagicMock()
bundle = MagicMock()
bundle.node = node
f = files.File(
bundle,
"/foo",
{},
)
f._fix_type(MagicMock())
assert call("rm -rf -- /foo") in node.run.call_args_list
assert call("mkdir -p -- /") in node.run.call_args_list
fix_content.assert_called_once()
示例7: test_rm
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_rm(self, fix_owner):
node = MagicMock()
bundle = MagicMock()
bundle.node = node
f = symlinks.Symlink(
bundle,
"/foo",
{'target': "/bar"},
)
f._fix_type(MagicMock())
assert call("rm -rf -- /foo") in node.run.call_args_list
assert call("ln -s -- /bar /foo") in node.run.call_args_list
fix_owner.assert_called_once()
示例8: test_rm
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_rm(self, fix_mode, fix_owner):
node = MagicMock()
bundle = MagicMock()
bundle.node = node
f = directories.Directory(
bundle,
"/foo",
{},
)
f._fix_type(MagicMock())
assert call("rm -rf -- /foo") in node.run.call_args_list
assert call("mkdir -p -- /foo") in node.run.call_args_list
fix_mode.assert_called_once()
fix_owner.assert_called_once()
示例9: test_interactive
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_interactive(self, interact):
args = MagicMock()
args.node = None
repo_obj = MagicMock()
repo_obj.path = "/dev/null"
repo_obj_validated = MagicMock()
with patch(
'blockwart.cmdline.repo.Repository',
return_value=repo_obj_validated,
) as repo_class:
repo.bw_repo_debug(repo_obj, args)
repo_class.assert_called_with(repo_obj.path)
interact.assert_called_with(
repo.DEBUG_BANNER,
local={'repo': repo_obj_validated},
)
示例10: test_simple_item_list
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_simple_item_list(self):
args = MagicMock()
args.file_preview_path = None
args.node = "node1"
args.show_repr = False
output = list(items.bw_items(self.repo, args))
self.assertEqual(
output,
[
"type1:item1",
"type1:item2",
"directory:/bar/baz",
"file:/foo/47",
"file:/foo/48",
],
)
示例11: test_binary
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_binary(self):
node = MagicMock()
bundle = MagicMock()
bundle.bundle_dir = "/b/dir"
bundle.node = node
f = files.File(
bundle,
"/foo",
{'content_type': 'binary', 'source': 'foobar'},
)
f._fix_content(MagicMock())
node.upload.assert_called_once_with(
"/b/dir/files/foobar",
"/foo",
owner="root",
group="root",
mode="0664",
)
示例12: test_interactive_node
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_interactive_node(self, interact):
args = MagicMock()
args.node = "node1"
args.itemid = None
node = MagicMock()
node.name = args.node
repo_obj = MagicMock()
repo_obj.path = "/dev/null"
repo_obj_validated = MagicMock()
repo_obj_validated.get_node = MagicMock(return_value=node)
with patch(
'blockwart.cmdline.repo.Repository',
return_value=repo_obj_validated,
):
repo.bw_repo_debug(repo_obj, args)
interact.assert_called_with(
repo.DEBUG_BANNER_NODE,
local={
'node': node,
'repo': repo_obj_validated,
},
)
示例13: test_output
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import node [as 别名]
def test_output(self):
class FakeItem1(Item):
BUNDLE_ATTRIBUTE_NAME = "fakes1"
ITEM_TYPE_NAME = "type1"
class FakeItem2(Item):
BUNDLE_ATTRIBUTE_NAME = "fakes1"
ITEM_TYPE_NAME = "type2"
class FakeItem3(Item):
BUNDLE_ATTRIBUTE_NAME = "fakes1"
ITEM_TYPE_NAME = "type3"
class FakeBundle(object):
bundle_dir = "/dev/null"
bundle_data_dir = "/dev/null"
node = None
item1 = FakeItem1(FakeBundle(), "item1", {})
item2 = FakeItem1(FakeBundle(), "item2", {})
item3 = FakeItem2(FakeBundle(), "item1", {})
item3.needs = ["type1:item1"]
item4 = FakeItem3(FakeBundle(), "item1", {})
item4.NEEDS_STATIC = ["type2:"]
bundle1 = MagicMock()
bundle1.name = "bundle1"
bundle1.items = [item1, item2, item3]
for item in bundle1.items:
item.bundle = bundle1
bundle2 = MagicMock()
bundle2.name = "bundle2"
bundle2.items = [item4]
for item in bundle2.items:
item.bundle = bundle2
node = MagicMock()
node.bundles = [bundle1, bundle2]
node.items = [item1, item2, item3, item4]
node.name = "node"
args = MagicMock()
args.node = "node"
args.depends_static = True
args.depends_regular = True
args.depends_auto = True
rep = MagicMock()
rep.get_node.return_value = node
self.assertEqual(
"\n".join(list(plot.bw_plot_node(rep, args))),
"digraph bundlewrap\n"
"{\n"
"rankdir = LR\n"
"graph [color=\"#303030\"; "
"fontname=Helvetica; "
"penwidth=2; "
"shape=box; "
"style=\"rounded,dashed\"]\n"
"node [color=\"#303030\"; "
"fillcolor=\"#303030\"; "
"fontcolor=white; "
"fontname=Helvetica; "
"shape=box; "
"style=\"rounded,filled\"]\n"
"edge [arrowhead=vee]\n"
"subgraph cluster_0\n"
"{\n"
"label = \"bundle2\"\n"
"\"bundle:bundle2\"\n"
"\"type3:item1\"\n"
"}\n"
"subgraph cluster_1\n"
"{\n"
"label = \"bundle1\"\n"
"\"bundle:bundle1\"\n"
"\"type1:item1\"\n"
"\"type1:item2\"\n"
"\"type2:item1\"\n"
"}\n"
"\"bundle:bundle2\" -> \"type3:item1\" [color=\"#6BB753\",penwidth=2]\n"
"\"bundle:bundle1\" -> \"type1:item1\" [color=\"#6BB753\",penwidth=2]\n"
"\"bundle:bundle1\" -> \"type1:item2\" [color=\"#6BB753\",penwidth=2]\n"
"\"bundle:bundle1\" -> \"type2:item1\" [color=\"#6BB753\",penwidth=2]\n"
"\"type1:\" -> \"type1:item1\" [color=\"#6BB753\",penwidth=2]\n"
"\"type1:\" -> \"type1:item2\" [color=\"#6BB753\",penwidth=2]\n"
"\"type3:\" -> \"type3:item1\" [color=\"#6BB753\",penwidth=2]\n"
"\"type2:\" -> \"type2:item1\" [color=\"#6BB753\",penwidth=2]\n"
"\"type2:item1\" -> \"type1:item1\" [color=\"#C24948\",penwidth=2]\n"
"\"type3:item1\" -> \"type2:\" [color=\"#3991CC\",penwidth=2]\n"
"fontsize = 28\n"
"label = \"node\"\n"
"labelloc = \"t\"\n"
"}"
,
)