本文整理汇总了Python中twisted.python.filepath.FilePath.touch方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.touch方法的具体用法?Python FilePath.touch怎么用?Python FilePath.touch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.touch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapper
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import touch [as 别名]
def wrapper(case, *args, **kwargs):
test_file = FilePath(case.mktemp())
test_file.touch()
test_file.chmod(0o000)
permissions = test_file.getPermissions()
test_file.chmod(0o777)
if permissions != Permissions(0o000):
raise SkipTest("Can't run test on filesystem with broken permissions.")
return test_method(case, *args, **kwargs)
示例2: _testNonDirectoryChildEntry
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import touch [as 别名]
def _testNonDirectoryChildEntry(self):
path = FilePath(self.mktemp())
self.failIf(path.exists())
path.touch()
child = path.child("test_package").path
plugins.__path__.append(child)
try:
plgs = list(plugin.getPlugins(plugin.ITestPlugin))
self.assertEqual(len(plgs), 1)
finally:
plugins.__path__.remove(child)
示例3: test_nonDirectoryChildEntry
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import touch [as 别名]
def test_nonDirectoryChildEntry(self):
"""
Test that getCache skips over any entries in a plugin package's
C{__path__} which refer to children of paths which are not directories.
"""
path = FilePath(self.mktemp())
self.failIf(path.exists())
path.touch()
child = path.child("test_package").path
self.module.__path__.append(child)
try:
plgs = list(plugin.getPlugins(ITestPlugin, self.module))
self.assertEqual(len(plgs), 1)
finally:
self.module.__path__.remove(child)
示例4: test_runnerDebuggerDefaultsToPdb
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import touch [as 别名]
def test_runnerDebuggerDefaultsToPdb(self):
"""
Trial uses pdb if no debugger is specified by `--debugger`
"""
self.parseOptions(['--debug', 'twisted.trial.test.sample'])
pdbrcFile = FilePath("pdbrc")
pdbrcFile.touch()
self.runcall_called = False
def runcall(pdb, suite, result):
self.runcall_called = True
self.patch(pdb.Pdb, "runcall", runcall)
self.runSampleSuite(self.getRunner())
self.assertTrue(self.runcall_called)
示例5: OptionsTests
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import touch [as 别名]
class OptionsTests(unittest.TestCase):
"""
Tests for L{txghbot._api.Options}
"""
def setUp(self):
self.secretFilePath = self.mktemp()
self.secretFile = FilePath(self.secretFilePath)
self.secretFromPathOption = "--secret-from-path={}".format(
self.secretFilePath)
self.stringEnviron = {}
self.bytesEnviron = {}
self.osModuleFake = _FakeOSModule.fromdicts(self.stringEnviron,
self.bytesEnviron)
self.config = Options(self.osModuleFake)
def tearDown(self):
if self.secretFile.exists():
self.secretFile.remove()
def secretFromEnvironmentOption(self, variable):
"""
Generate the secret from environment variable command line
option.
@type variable: L{str}
@param variable: The variable name
@return: The formatted option containing the path.
@rtype: L{str}
"""
return "--secret-from-env={}".format(variable)
def test_retrieveSecretFromEmptyPath(self):
"""
An empty secret file raises an L{OSError}
"""
self.secretFile.touch()
exc = self.assertRaises(
UsageError,
self.config.parseOptions, [self.secretFromPathOption],
)
self.assertIn("empty", str(exc).lower())
def test_retrieveSecretFromMissingPath(self):
"""
An missing secret file raises an L{IOError}
"""
self.assertRaises(
IOError,
self.config.parseOptions, [self.secretFromPathOption],
)
def test_retrieveSecretFromPath(self):
"""
A newline-stripped secret is returned. Internal whitespace is
preserved.
"""
with self.secretFile.open('wb') as f:
f.write(b" this is a secret \r\n")
self.config.parseOptions([self.secretFromPathOption])
self.assertEqual(self.config["secret"], b" this is a secret ")
def test_retrieveSecretFromEmptyEnvironment(self):
"""
A L{UsageError} is raised when attempting to retrieve a secret
from an environment that doesn't contain the provided
variable.
"""
self.assertRaises(UsageError,
self.config.parseOptions,
[self.secretFromEnvironmentOption("MISSING")])
def test_retrieveSecretFromEnvironment(self):
"""
The secret is retrieved as bytes from the process'
environment.
"""
self.bytesEnviron[b"SECRET"] = b"a secret"
self.stringEnviron["SECRET"] = "a secret"
self.config.parseOptions([self.secretFromEnvironmentOption("SECRET")])
self.assertEqual(self.config["secret"], b"a secret")
def test_missingSecret(self):
"""
Omitting both a secret path and a secret environment variable
name results in a L{UsageError}.
"""
self.assertRaises(UsageError, self.config.parseOptions, [])
def test_bothSecrets(self):
"""
Including both a secret path and a secret environment variable
name results in a L{UsageError}.
#.........这里部分代码省略.........