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


Python SiteInfo.find_child方法代码示例

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


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

示例1: setup_method

# 需要导入模块: from hydeengine.siteinfo import SiteInfo [as 别名]
# 或者: from hydeengine.siteinfo.SiteInfo import find_child [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 (
#.........这里部分代码省略.........
开发者ID:lachenmayer,项目名称:hyde,代码行数:103,代码来源:test_siteinfo.py


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