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


Python CachingFilePath.parent方法代码示例

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


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

示例1: ExtendedAttributesPropertyStoreTests

# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import parent [as 别名]
class ExtendedAttributesPropertyStoreTests(TestCase):
    """
    Tests for L{xattrPropertyStore}.
    """
    if xattrPropertyStore is None:
        skip = "xattr package missing, cannot test xattr property store"

    def setUp(self):
        """
        Create a resource and a xattr property store for it.
        """
        self.resourcePath = FilePath(self.mktemp())
        self.resourcePath.setContent("")
        self.attrs = xattr(self.resourcePath.path)
        self.resource = DAVFile(self.resourcePath.path)
        self.propertyStore = xattrPropertyStore(self.resource)


    def test_getAbsent(self):
        """
        L{xattrPropertyStore.get} raises L{HTTPError} with a I{NOT FOUND}
        response code if passed the name of an attribute for which there is no
        corresponding value.
        """
        error = self.assertRaises(HTTPError, self.propertyStore.get, ("foo", "bar"))
        self.assertEquals(error.response.code, NOT_FOUND)


    def _forbiddenTest(self, method):
        # Remove access to the directory containing the file so that getting
        # extended attributes from it fails with EPERM.
        self.resourcePath.parent().chmod(0)
        # Make sure to restore access to it later so that it can be deleted
        # after the test run is finished.
        self.addCleanup(self.resourcePath.parent().chmod, 0700)

        # Try to get a property from it - and fail.
        document = self._makeValue()
        error = self.assertRaises(
            HTTPError,
            getattr(self.propertyStore, method),
            document.root_element.qname())

        # Make sure that the status is FORBIDDEN, a roughly reasonable mapping
        # of the EPERM failure.
        self.assertEquals(error.response.code, FORBIDDEN)

    def _missingTest(self, method):
        # Remove access to the directory containing the file so that getting
        # extended attributes from it fails with EPERM.
        self.resourcePath.parent().chmod(0)
        # Make sure to restore access to it later so that it can be deleted
        # after the test run is finished.
        self.addCleanup(self.resourcePath.parent().chmod, 0700)

        # Try to get a property from it - and fail.
        document = self._makeValue()
        error = self.assertRaises(
            HTTPError,
            getattr(self.propertyStore, method),
            document.root_element.qname())

        # Make sure that the status is FORBIDDEN, a roughly reasonable mapping
        # of the EPERM failure.
        self.assertEquals(error.response.code, FORBIDDEN)


    def test_getErrors(self):
        """
        If there is a problem getting the specified property (aside from the
        property not existing), L{xattrPropertyStore.get} raises L{HTTPError}
        with a status code which is determined by the nature of the problem.
        """
        self._forbiddenTest('get')

    def test_getMissing(self):
        """
        Test missing file.
        """

        resourcePath = FilePath(self.mktemp())
        resource = DAVFile(resourcePath.path)
        propertyStore = xattrPropertyStore(resource)

        # Try to get a property from it - and fail.
        document = self._makeValue()
        error = self.assertRaises(
            HTTPError,
            propertyStore.get,
            document.root_element.qname())

        # Make sure that the status is NOT FOUND.
        self.assertEquals(error.response.code, NOT_FOUND)

    def _makeValue(self, uid=None):
        """
        Create and return any old WebDAVDocument for use by the get tests.
        """
        element = Depth(uid if uid is not None else "0")
        document = WebDAVDocument(element)
#.........这里部分代码省略.........
开发者ID:anemitz,项目名称:calendarserver,代码行数:103,代码来源:test_xattrprops.py


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