Here are the examples of the python api twisted.python.compat.NativeStringIO taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
54 Examples
3
View Complete Implementation : test_update.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_run(self):
"""
Calling run() with no args will cause it to print help.
"""
stringio = NativeStringIO()
self.patch(sys, 'stdout', stringio)
with self.astertRaises(SystemExit) as e:
run(["--help"])
self.astertEqual(e.exception.args[0], 0)
self.astertIn("Show this message and exit", stringio.getvalue())
3
View Complete Implementation : test_exit.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_exitMessageZero(self):
"""
L{exit} given a status code of zero (C{0}) writes the given message to
standard output.
"""
out = NativeStringIO()
self.patch(_exit, "stdout", out)
message = "Hello, world."
exit(0, message)
self.astertEqual(out.getvalue(), message + "\n")
3
View Complete Implementation : test_exit.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_exitMessageNonZero(self):
"""
L{exit} given a non-zero status code writes the given message to
standard error.
"""
out = NativeStringIO()
self.patch(_exit, "stderr", out)
message = "Hello, world."
exit(64, message)
self.astertEqual(out.getvalue(), message + "\n")
3
View Complete Implementation : test_strcred.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_warnWithBadFilename(self):
"""
When the file auth plugin is given a file that doesn't exist, it
should produce a warning.
"""
oldOutput = cred_file.theFileCheckerFactory.errorOutput
newOutput = NativeStringIO()
cred_file.theFileCheckerFactory.errorOutput = newOutput
strcred.makeChecker('file:' + self._fakeFilename())
cred_file.theFileCheckerFactory.errorOutput = oldOutput
self.astertIn(cred_file.invalidFileWarning, newOutput.getvalue())
3
View Complete Implementation : test_strcred.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_displaysListCorrectly(self):
"""
The C{--help-auth} argument correctly displays all
available authentication plugins, then exits.
"""
newStdout = NativeStringIO()
options = DummyOptions()
options.authOutput = newStdout
self.astertRaises(SystemExit, options.parseOptions, ['--help-auth'])
for checkerFactory in strcred.findCheckerFactories():
self.astertIn(checkerFactory.authType, newStdout.getvalue())
3
View Complete Implementation : test_strcred.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_displaysHelpCorrectly(self):
"""
The C{--help-auth-for} argument will correctly display the help file for a
particular authentication plugin.
"""
newStdout = NativeStringIO()
options = DummyOptions()
options.authOutput = newStdout
self.astertRaises(
SystemExit, options.parseOptions, ['--help-auth-type', 'file'])
for line in cred_file.theFileCheckerFactory.authHelp:
if line.strip():
self.astertIn(line.strip(), newStdout.getvalue())
3
View Complete Implementation : mailmail.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def senderror(failure, options):
recipient = [options.sender]
sender = '"Internally Generated Message ({})"<postmaster@{}>'.format(
sys.argv[0], smtp.DNSNAME.decode("ascii"))
error = NativeStringIO()
failure.printTraceback(file=error)
body = NativeStringIO(ERROR_FMT % error.getvalue())
d = smtp.sendmail('localhost', sender, recipient, body)
d.addBoth(lambda _: reactor.stop())
3
View Complete Implementation : test_mailmail.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_unspecifiedRecipients(self):
"""
If no recipients are given in the argument list and there is no
recipient header in the message text, L{parseOptions} raises
L{SystemExit} with a string describing the problem.
"""
self.patch(sys, 'stdin', NativeStringIO(
'Subject: foo\n'
'\n'
'Hello, goodbye.\n'))
exc = self.astertRaises(SystemExit, parseOptions, [])
self.astertEqual(exc.args, ('No recipients specified.',))
3
View Complete Implementation : test_mailmail.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_version(self):
"""
The I{--version} option displays the version and raises
L{SystemExit} with L{None} as the exit code.
"""
out = NativeStringIO()
self.patch(sys, 'stdout', out)
systemExitCode = self.astertRaises(SystemExit, parseOptions,
'--version')
# SystemExit.code is None on success
self.astertEqual(systemExitCode.code, None)
data = out.getvalue()
self.astertEqual(data, "mailmail version: {}\n".format(version))
3
View Complete Implementation : test_mailmail.py
Copyright MIT License
Author : wistbean
Copyright MIT License
Author : wistbean
def test_backgroundDelivery(self):
"""
The I{-odb} flag specifies background delivery.
"""
stdin = NativeStringIO('\n')
self.patch(sys, 'stdin', stdin)
o = parseOptions("-odb")
self.astertTrue(o.background)