本文整理汇总了Python中hydeengine.siteinfo.SiteInfo.walk方法的典型用法代码示例。如果您正苦于以下问题:Python SiteInfo.walk方法的具体用法?Python SiteInfo.walk怎么用?Python SiteInfo.walk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hydeengine.siteinfo.SiteInfo
的用法示例。
在下文中一共展示了SiteInfo.walk方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_method
# 需要导入模块: from hydeengine.siteinfo import SiteInfo [as 别名]
# 或者: from hydeengine.siteinfo.SiteInfo import walk [as 别名]
class TestSiteInfo:
def setup_method(self, method):
self.site = SiteInfo(settings, TEST_SITE.path)
self.site.refresh()
def assert_node_complete(self, node, folder):
assert node.folder.path == folder.path
test_case = self
class Visitor(object):
def visit_folder(self, folder):
child = node.find_child(folder)
assert child
test_case.assert_node_complete(child, folder)
def visit_file(self, a_file):
assert node.find_resource(a_file)
folder.list(Visitor())
def test_population(self):
assert self.site.name == "Your Site"
self.assert_node_complete(self.site.content_node,
TEST_SITE.child_folder("content"))
self.assert_node_complete(self.site.media_node,
TEST_SITE.child_folder("media"))
self.assert_node_complete(self.site.layout_node,
TEST_SITE.child_folder("layout"))
def test_type(self):
def assert_node_type(node_dir, type):
node = self.site.find_child(Folder(node_dir))
assert node
assert Folder(node_dir).same_as(node.folder)
for child in node.walk():
assert child.type == type
assert_node_type(settings.CONTENT_DIR, "content")
assert_node_type(settings.MEDIA_DIR, "media")
assert_node_type(settings.LAYOUT_DIR, "layout")
def test_attributes(self):
for node in self.site.walk():
self.assert_node_attributes(node)
for resource in node.resources:
self.assert_resource_attributes(resource)
def assert_node_attributes(self, node):
fragment = self.get_node_fragment(node)
if node.type == "content":
fragment = node.folder.get_fragment(self.site.content_folder)
elif node.type == "media":
fragment = node.folder.get_fragment(self.site.folder)
if node.type in ("content", "media"):
fragment = ("/" + fragment.strip("/")).rstrip("/")
assert fragment == node.url
assert settings.SITE_WWW_URL + fragment == node.full_url
else:
assert not node.url
assert not node.full_url
if node.type == "content":
for ancestor in node.ancestors:
assert(
ancestor.folder.is_ancestor_of(node.folder) or
ancestor.folder.same_as(node.folder))
assert node.source_folder == node.folder
if not node == self.site and node.type not in ("content", "media"):
assert not node.target_folder
assert not node.temp_folder
else:
assert node.target_folder.same_as(Folder(
os.path.join(settings.DEPLOY_DIR,
fragment.lstrip("/"))))
assert node.temp_folder.same_as(Folder(
os.path.join(settings.TMP_DIR,
fragment.lstrip("/"))))
def assert_resource_attributes(self, resource):
node = resource.node
fragment = self.get_node_fragment(node)
assert resource.name == resource.file.name
if resource.node.type in ("content", "media"):
assert (resource.url ==
url.join(node.url, resource.file.name))
assert (resource.full_url ==
url.join(node.full_url, resource.file.name))
assert resource.target_file.same_as(
File(node.target_folder.child(
resource.file.name)))
assert resource.temp_file.same_as(
File(node.temp_folder.child(resource.file.name)))
else:
assert not resource.url
assert not resource.full_url
if resource.node.type == "content":
self.assert_page_attributes(resource)
def assert_page_attributes(self, page):
if page.page_name in (
#.........这里部分代码省略.........