本文整理汇总了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)
#.........这里部分代码省略.........