本文整理汇总了Python中twisted.python.util.sibpath方法的典型用法代码示例。如果您正苦于以下问题:Python util.sibpath方法的具体用法?Python util.sibpath怎么用?Python util.sibpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.util
的用法示例。
在下文中一共展示了util.sibpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFullAppend
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testFullAppend(self):
infile = util.sibpath(__file__, 'rfc822.message')
message = open(infile)
SimpleServer.theAccount.addMailbox('root/subthing')
def login():
return self.client.login(b'testuser', b'password-test')
def append():
return self.client.append(
'root/subthing',
message,
('\\SEEN', '\\DELETED'),
'Tue, 17 Jun 2003 11:22:16 -0600 (MDT)',
)
d1 = self.connected.addCallback(strip(login))
d1.addCallbacks(strip(append), self._ebGeneral)
d1.addCallbacks(self._cbStopClient, self._ebGeneral)
d2 = self.loopback()
d = defer.gatherResults([d1, d2])
return d.addCallback(self._cbTestFullAppend, infile)
示例2: testPartialAppend
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testPartialAppend(self):
infile = util.sibpath(__file__, 'rfc822.message')
SimpleServer.theAccount.addMailbox('PARTIAL/SUBTHING')
def login():
return self.client.login(b'testuser', b'password-test')
def append():
message = open(infile)
return self.client.sendCommand(
imap4.Command(
'APPEND',
'PARTIAL/SUBTHING (\\SEEN) "Right now" {%d}' % os.path.getsize(infile),
(), self.client._IMAP4Client__cbContinueAppend, message
)
)
d1 = self.connected.addCallback(strip(login))
d1.addCallbacks(strip(append), self._ebGeneral)
d1.addCallbacks(self._cbStopClient, self._ebGeneral)
d2 = self.loopback()
d = defer.gatherResults([d1, d2])
return d.addCallback(self._cbTestPartialAppend, infile)
示例3: test_FileRebuild
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def test_FileRebuild(self):
from twisted.python.util import sibpath
import shutil, time
shutil.copyfile(sibpath(__file__, "myrebuilder1.py"),
os.path.join(self.fakelibPath, "myrebuilder.py"))
from twisted_rebuild_fakelib import myrebuilder
a = myrebuilder.A()
b = myrebuilder.B()
i = myrebuilder.Inherit()
self.assertEqual(a.a(), 'a')
# Necessary because the file has not "changed" if a second has not gone
# by in unix. This sucks, but it's not often that you'll be doing more
# than one reload per second.
time.sleep(1.1)
shutil.copyfile(sibpath(__file__, "myrebuilder2.py"),
os.path.join(self.fakelibPath, "myrebuilder.py"))
rebuild.rebuild(myrebuilder)
b2 = myrebuilder.B()
self.assertEqual(b2.b(), 'c')
self.assertEqual(b.b(), 'c')
self.assertEqual(i.a(), 'd')
self.assertEqual(a.a(), 'b')
示例4: test_directory
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def test_directory(self):
"""
Test loader against a filesystem directory. It should handle
'path' and 'path/' the same way.
"""
path = util.sibpath(__file__, 'goodDirectory')
os.mkdir(path)
f = file(os.path.join(path, '__init__.py'), "w")
f.close()
try:
module = runner.filenameToModule(path)
self.assert_(module.__name__.endswith('goodDirectory'))
module = runner.filenameToModule(path + os.path.sep)
self.assert_(module.__name__.endswith('goodDirectory'))
finally:
shutil.rmtree(path)
示例5: testFullAppend
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testFullAppend(self):
infile = util.sibpath(__file__, 'rfc822.message')
message = open(infile)
SimpleServer.theAccount.addMailbox('root/subthing')
def login():
return self.client.login('testuser', 'password-test')
def append():
return self.client.append(
'root/subthing',
message,
('\\SEEN', '\\DELETED'),
'Tue, 17 Jun 2003 11:22:16 -0600 (MDT)',
)
d1 = self.connected.addCallback(strip(login))
d1.addCallbacks(strip(append), self._ebGeneral)
d1.addCallbacks(self._cbStopClient, self._ebGeneral)
d2 = self.loopback()
d = defer.gatherResults([d1, d2])
return d.addCallback(self._cbTestFullAppend, infile)
示例6: testPartialAppend
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testPartialAppend(self):
infile = util.sibpath(__file__, 'rfc822.message')
message = open(infile)
SimpleServer.theAccount.addMailbox('PARTIAL/SUBTHING')
def login():
return self.client.login('testuser', 'password-test')
def append():
message = file(infile)
return self.client.sendCommand(
imap4.Command(
'APPEND',
'PARTIAL/SUBTHING (\\SEEN) "Right now" {%d}' % os.path.getsize(infile),
(), self.client._IMAP4Client__cbContinueAppend, message
)
)
d1 = self.connected.addCallback(strip(login))
d1.addCallbacks(strip(append), self._ebGeneral)
d1.addCallbacks(self._cbStopClient, self._ebGeneral)
d2 = self.loopback()
d = defer.gatherResults([d1, d2])
return d.addCallback(self._cbTestPartialAppend, infile)
示例7: testStdio
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testStdio(self):
"""twisted.internet.stdio test."""
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_twisted.py")
p = Accumulator()
d = p.endedDeferred = defer.Deferred()
env = {"PYTHONPATH": os.pathsep.join(sys.path)}
reactor.spawnProcess(p, exe, [exe, "-u", scriptPath], env=env,
path=None, usePTY=self.usePTY)
p.transport.write("hello, world")
p.transport.write("abc")
p.transport.write("123")
p.transport.closeStdin()
def processEnded(ign):
self.assertEquals(p.outF.getvalue(), "hello, worldabc123",
"Output follows:\n"
"%s\n"
"Error message from process_twisted follows:\n"
"%s\n" % (p.outF.getvalue(), p.errF.getvalue()))
return d.addCallback(processEnded)
示例8: test_unsetPid
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def test_unsetPid(self):
"""
Test if pid is None/non-None before/after process termination. This
reuses process_echoer.py to get a process that blocks on stdin.
"""
finished = defer.Deferred()
p = TrivialProcessProtocol(finished)
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_echoer.py")
procTrans = reactor.spawnProcess(p, exe,
[exe, scriptPath], env=None)
self.failUnless(procTrans.pid)
def afterProcessEnd(ignored):
self.assertEqual(procTrans.pid, None)
p.transport.closeStdin()
return finished.addCallback(afterProcessEnd)
示例9: testManyProcesses
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testManyProcesses(self):
def _check(results, protocols):
for p in protocols:
self.assertEquals(p.stages, [1, 2, 3, 4, 5], "[%d] stages = %s" % (id(p.transport), str(p.stages)))
# test status code
f = p.reason
f.trap(error.ProcessTerminated)
self.assertEquals(f.value.exitCode, 23)
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_tester.py")
args = [exe, "-u", scriptPath]
protocols = []
deferreds = []
for i in xrange(50):
p = TestManyProcessProtocol()
protocols.append(p)
reactor.spawnProcess(p, exe, args, env=None)
deferreds.append(p.deferred)
deferredList = defer.DeferredList(deferreds, consumeErrors=True)
deferredList.addCallback(_check, protocols)
return deferredList
示例10: test_echo
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def test_echo(self):
"""
A spawning a subprocess which echoes its stdin to its stdout via
C{reactor.spawnProcess} will result in that echoed output being
delivered to outReceived.
"""
finished = defer.Deferred()
p = EchoProtocol(finished)
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_echoer.py")
reactor.spawnProcess(p, exe, [exe, scriptPath], env=None)
def asserts(ignored):
self.failIf(p.failure, p.failure)
self.failUnless(hasattr(p, 'buffer'))
self.assertEquals(len(''.join(p.buffer)), len(p.s * p.n))
def takedownProcess(err):
p.transport.closeStdin()
return err
return finished.addCallback(asserts).addErrback(takedownProcess)
示例11: testOpeningTTY
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def testOpeningTTY(self):
exe = sys.executable
scriptPath = util.sibpath(__file__, "process_tty.py")
p = Accumulator()
d = p.endedDeferred = defer.Deferred()
reactor.spawnProcess(p, exe, [exe, "-u", scriptPath], env=None,
path=None, usePTY=self.usePTY)
p.transport.write("hello world!\n")
def processEnded(ign):
self.assertRaises(
error.ProcessExitedAlready, p.transport.signalProcess, 'HUP')
self.assertEquals(
p.outF.getvalue(),
"hello world!\r\nhello world!\r\n",
"Error message from process_tty follows:\n\n%s\n\n" % p.outF.getvalue())
return d.addCallback(processEnded)
示例12: startServer
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def startServer(self, cgi):
root = resource.Resource()
cgipath = util.sibpath(__file__, cgi)
root.putChild("cgi", PythonScript(cgipath))
site = server.Site(root)
self.p = reactor.listenTCP(0, site)
return self.p.getHost().port
示例13: sibpath
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def sibpath(filename):
"""
For finding files in twisted/trial/test
"""
return util.sibpath(__file__, filename)
示例14: test_testmoduleOnModule
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def test_testmoduleOnModule(self):
"""
Check that --testmodule loads a suite which contains the tests
referred to in test-case-name inside its parameter.
"""
self.config.opt_testmodule(sibpath('moduletest.py'))
self.assertSuitesEqual(trial._getSuite(self.config),
['twisted.trial.test.test_log'])
示例15: test_testmoduleTwice
# 需要导入模块: from twisted.python import util [as 别名]
# 或者: from twisted.python.util import sibpath [as 别名]
def test_testmoduleTwice(self):
"""
When the same module is specified with two --testmodule flags, it
should only appear once in the suite.
"""
self.config.opt_testmodule(sibpath('moduletest.py'))
self.config.opt_testmodule(sibpath('moduletest.py'))
self.assertSuitesEqual(trial._getSuite(self.config),
['twisted.trial.test.test_log'])