本文整理汇总了Python中twisted.python.filepath.FilePath.parent方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.parent方法的具体用法?Python FilePath.parent怎么用?Python FilePath.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.parent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_file_logging_rotation_5_files
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_file_logging_rotation_5_files(self):
"""
Only 5 logfiles are kept.
"""
logfile = FilePath(self.mktemp()).child('foo.log')
logfile.parent().makedirs()
# This file will become foo.log.1
with logfile.open('w') as f:
f.write(b'0')
f.truncate(int(MiB(100).to_Byte().value))
# These file extensions will be incremented
for i in range(1, 5):
sibling = logfile.sibling(logfile.basename() + u'.' + unicode(i))
with sibling.open('w') as f:
f.write(bytes(i))
d = self.run_script(EliotScript, options=['--logfile', logfile.path])
def verify_logfiles(stdout_messages, logfile):
logfile_dir = logfile.parent()
self.assertEqual(
# The contents of the files will now be an integer one less
# than the integer in the file name.
map(bytes, range(0, 4)),
list(
logfile_dir.child('foo.log.{}'.format(i)).open().read(1)
for i
in range(1, 5)
)
)
d.addCallback(verify_logfiles, logfile=logfile)
return d
示例2: test_missingSource
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_missingSource(self):
"""
If a function the source of which is not available is including in the
C{offendingFunctions} list, L{TestCase.flushWarnings} raises
L{IOError}. Such a call flushes no warnings.
"""
package = FilePath(self.mktemp()).child('twisted_private_helper')
package.makedirs()
package.child('__init__.py').setContent('')
package.child('missingsourcefile.py').setContent('''
import warnings
def foo():
warnings.warn("oh no")
''')
sys.path.insert(0, package.parent().path)
self.addCleanup(sys.path.remove, package.parent().path)
from twisted_private_helper import missingsourcefile
self.addCleanup(sys.modules.pop, 'twisted_private_helper')
self.addCleanup(sys.modules.pop, missingsourcefile.__name__)
package.child('missingsourcefile.py').remove()
missingsourcefile.foo()
self.assertRaises(
IOError, self.flushWarnings, [missingsourcefile.foo])
self.assertEqual(len(self.flushWarnings()), 1)
示例3: test_file_logging
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_file_logging(self):
"""
Logged messages are written to ``logfile`` if ``--logfile`` is supplied
on the command line.
"""
logfile = FilePath(self.mktemp()).child('foo.log')
logfile.parent().makedirs()
d = self.run_script(EliotScript, options=['--logfile', logfile.path])
d.addCallback(self._assert_logfile_messages, logfile=logfile)
return d
示例4: test_mktemp_doesnt_exist
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_mktemp_doesnt_exist(self, test):
"""
``mktemp`` returns a path that doesn't exist inside a directory that
does.
"""
temp_path = FilePath(test.mktemp())
self.addCleanup(_remove_dir, temp_path.parent())
self.expectThat(temp_path.parent().path, DirExists())
self.expectThat(temp_path.path, Not(PathExists()))
self.assertThat(temp_path, BelowPath(FilePath(os.getcwd())))
示例5: test_rewriteCss
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_rewriteCss(self):
"""
Test that CSS processing works, and verify the header.
"""
clock = Clock()
fc = FileCache(lambda: clock.seconds(), 1)
temp = FilePath(self.mktemp() + '.css')
with temp.open('wb') as f:
f.write("p { color: red; }\n")
# BetterFile(temp.path) would not work because the processing happens
# in getChild. So, create a BetterFile for the .css file's parent dir.
bf = BetterFile(temp.parent().path, fileCache=fc, rewriteCss=True)
d = self._requestPostpathAndRender(bf, [temp.basename()])
headerRe = re.compile(r"/\* CSSResource processed ([0-9a-f]{32}?) \*/")
def assertProcessedContent((request, child)):
out = "".join(request.written)
lines = out.split("\n")
self.assertTrue(re.match(headerRe, lines[0]), lines[0])
self.assertEqual("p { color: red; }", lines[1])
self.assertEqual("", lines[2])
self.assertEqual(3, len(lines))
d.addCallback(assertProcessedContent)
return d
示例6: get_client
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def get_client(options):
cluster = FilePath(options["cluster-yml"])
if cluster.exists():
config = yaml.load(cluster.open())
certificates_path = cluster.parent()
user = config["users"][0]
control_service = None # figure it out based on cluster.yml
else:
certificates_path = FilePath(options["certs-path"])
if options["user"] is None:
raise UsageError("must specify --user")
user = options["user"]
if options["control-service"] is None:
raise UsageError("must specify --control-service")
control_service = options["control-service"]
user_certificate_filename = "%s.crt" % (user,)
user_key_filename = "%s.key" % (user,)
return txflocker_get_client(
certificates_path=certificates_path,
user_certificate_filename=user_certificate_filename,
user_key_filename=user_key_filename,
target_hostname=control_service,
)
示例7: test_reactorSelection
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_reactorSelection(self):
"""
L{AxiomaticStart} optionally takes the name of a reactor and
installs it instead of the default reactor.
"""
# Since this process is already hopelessly distant from the state in
# which I{axiomatic start} operates, it would make no sense to try a
# functional test of this behavior in this process. Since the
# behavior being tested involves lots of subtle interactions between
# lots of different pieces of code (the reactor might get installed
# at the end of a ten-deep chain of imports going through as many
# different projects), it also makes no sense to try to make this a
# unit test. So, start a child process and try to use the alternate
# reactor functionality there.
here = FilePath(__file__)
# Try to find it relative to the source of this test.
bin = here.parent().parent().parent().child("bin")
axiomatic = bin.child("axiomatic")
if axiomatic.exists():
# Great, use that one.
axiomatic = axiomatic.path
else:
# Try to find it on the path, instead.
axiomatics = which("axiomatic")
if axiomatics:
# Great, it was on the path.
axiomatic = axiomatics[0]
else:
# Nope, not there, give up.
raise SkipTest(
"Could not find axiomatic script on path or at %s" % (
axiomatic.path,))
# Create a store for the child process to use and put an item in it.
# This will force an import of the module that defines that item's
# class when the child process starts. The module imports the default
# reactor at the top-level, making this the worst-case for the reactor
# selection code.
storePath = self.mktemp()
store = Store(storePath)
SomeItem(store=store)
store.close()
# Install select reactor because it available on all platforms, and
# it is still an error to try to install the select reactor even if
# the already installed reactor was the select reactor.
argv = [
sys.executable,
axiomatic, "-d", storePath,
"start", "--reactor", "select", "-n"]
expected = [
"reactor class: twisted.internet.selectreactor.SelectReactor.",
"reactor class: <class 'twisted.internet.selectreactor.SelectReactor'>"]
proto, complete = AxiomaticStartProcessProtocol.protocolAndDeferred(expected)
environ = os.environ.copy()
reactor.spawnProcess(proto, sys.executable, argv, env=environ)
return complete
示例8: test_mktemp_doesnt_exist
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_mktemp_doesnt_exist(self, base_test_case):
"""
``mktemp`` returns a path that doesn't exist inside a directory that
does.
"""
class SomeTest(base_test_case):
def test_pass(self):
pass
test = SomeTest('test_pass')
temp_path = FilePath(test.mktemp())
self.addCleanup(_remove_dir, temp_path.parent())
self.expectThat(temp_path.parent().path, DirExists())
self.expectThat(temp_path.path, Not(PathExists()))
self.assertThat(temp_path, BelowPath(FilePath(os.getcwd())))
示例9: test_noKnownHostsOption
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_noKnownHostsOption(self):
"""
L{default.verifyHostKey} should find your known_hosts file in
~/.ssh/known_hosts if you don't specify one explicitly on the command
line.
"""
l = []
tmpdir = self.mktemp()
oldHostsOption = self.hostsOption
hostsNonOption = FilePath(tmpdir).child(".ssh").child("known_hosts")
hostsNonOption.parent().makedirs()
FilePath(oldHostsOption).moveTo(hostsNonOption)
self.replaceHome(tmpdir)
self.options['known-hosts'] = None
default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey,
"I don't care.").addCallback(l.append)
self.assertEqual([1], l)
示例10: test_file_logging_rotation_at_100MiB
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_file_logging_rotation_at_100MiB(self):
"""
Logfiles are rotated when they reach 100MiB.
"""
logfile = FilePath(self.mktemp()).child('foo.log')
logfile.parent().makedirs()
with logfile.open('w') as f:
f.truncate(int(MiB(100).to_Byte().value - 1))
d = self.run_script(EliotScript, options=['--logfile', logfile.path])
def verify_logfiles(stdout_messages, logfile):
self.assertEqual(
set([logfile, logfile.sibling(logfile.basename() + u'.1')]),
set(logfile.parent().children())
)
d.addCallback(verify_logfiles, logfile=logfile)
return d
示例11: test_renamedSource
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_renamedSource(self):
"""
Warnings emitted by a function defined in a file which has been renamed
since it was initially compiled can still be flushed.
This is testing the code which specifically supports working around the
unfortunate behavior of CPython to write a .py source file name into
the .pyc files it generates and then trust that it is correct in
various places. If source files are renamed, .pyc files may not be
regenerated, but they will contain incorrect filenames.
"""
package = FilePath(self.mktemp()).child('twisted_private_helper')
package.makedirs()
package.child('__init__.py').setContent('')
package.child('module.py').setContent('''
import warnings
def foo():
warnings.warn("oh no")
''')
sys.path.insert(0, package.parent().path)
self.addCleanup(sys.path.remove, package.parent().path)
# Import it to cause pycs to be generated
from twisted_private_helper import module
# Clean up the state resulting from that import; we're not going to use
# this module, so it should go away.
del sys.modules['twisted_private_helper']
del sys.modules[module.__name__]
# Rename the source directory
package.moveTo(package.sibling('twisted_renamed_helper'))
# Import the newly renamed version
from twisted_renamed_helper import module
self.addCleanup(sys.modules.pop, 'twisted_renamed_helper')
self.addCleanup(sys.modules.pop, module.__name__)
# Generate the warning
module.foo()
# Flush it
self.assertEqual(len(self.flushWarnings([module.foo])), 1)
示例12: test_warnings_suppressed
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_warnings_suppressed(self):
"""
Warnings are suppressed for processes that import flocker.
"""
root = FilePath(flocker.__file__)
result = check_output(
[executable, b"-c", (b"import flocker; import warnings; " +
b"warnings.warn('ohno')")],
stderr=STDOUT,
# Make sure we can import flocker package:
cwd=root.parent().parent().path)
self.assertEqual(result, b"")
示例13: _get_cloudformation_full_path
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def _get_cloudformation_full_path():
"""
Get fully qualified pathname of cloudformation.py script.
:returns: Fully qualified pathname of cloudformation.py
:rtype: twisted.python.filepath.FilePath
"""
test_directory_filepath = FilePath(__file__)
installer_directory_filepath = test_directory_filepath.parent().parent()
cloudformation_filepath = installer_directory_filepath.childSearchPreauth(
u'cloudformation.py')
return cloudformation_filepath
示例14: test_missingSource
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def test_missingSource(self):
"""
Warnings emitted by a function the source code of which is not
available can still be flushed.
"""
package = FilePath(self.mktemp()).child('twisted_private_helper')
package.makedirs()
package.child('__init__.py').setContent('')
package.child('missingsourcefile.py').setContent('''
import warnings
def foo():
warnings.warn("oh no")
''')
sys.path.insert(0, package.parent().path)
self.addCleanup(sys.path.remove, package.parent().path)
from twisted_private_helper import missingsourcefile
self.addCleanup(sys.modules.pop, 'twisted_private_helper')
self.addCleanup(sys.modules.pop, missingsourcefile.__name__)
package.child('missingsourcefile.py').remove()
missingsourcefile.foo()
self.assertEqual(len(self.flushWarnings([missingsourcefile.foo])), 1)
示例15: opt_logfile
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import parent [as 别名]
def opt_logfile(self, logfile_path):
"""
Log to a file. Log is written to ``stdout`` by default. The logfile
directory is created if it does not already exist.
"""
logfile = FilePath(logfile_path)
logfile_directory = logfile.parent()
if not logfile_directory.exists():
logfile_directory.makedirs()
self['logfile'] = LogFile.fromFullPath(
logfile.path,
rotateLength=LOGFILE_LENGTH,
maxRotatedFiles=LOGFILE_COUNT,
)