本文整理汇总了Python中twisted.trial.unittest.SkipTest方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.SkipTest方法的具体用法?Python unittest.SkipTest怎么用?Python unittest.SkipTest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.trial.unittest
的用法示例。
在下文中一共展示了unittest.SkipTest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_wsgiErrorsExpectsOnlyNativeStringsInPython2
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_wsgiErrorsExpectsOnlyNativeStringsInPython2(self):
"""
The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
expects writes of only native strings in Python 2. Some existing WSGI
applications may write non-native (i.e. C{unicode}) strings so, for
compatibility, these elicit only a warning in Python 2.
"""
if _PY3:
raise SkipTest("Not relevant in Python 3")
request, result = self.prepareRequest()
request.requestReceived()
environ, _ = self.successResultOf(result)
errors = environ["wsgi.errors"]
with warnings.catch_warnings(record=True) as caught:
errors.write(u"fred")
self.assertEqual(1, len(caught))
self.assertEqual(UnicodeWarning, caught[0].category)
self.assertEqual(
"write() argument should be str, not u'fred' (unicode)",
str(caught[0].message))
示例2: test_wsgiErrorsAcceptsOnlyNativeStringsInPython3
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_wsgiErrorsAcceptsOnlyNativeStringsInPython3(self):
"""
The C{'wsgi.errors'} file-like object from the C{environ} C{dict}
permits writes of only native strings in Python 3, and raises
C{TypeError} for writes of non-native strings.
"""
if not _PY3:
raise SkipTest("Relevant only in Python 3")
request, result = self.prepareRequest()
request.requestReceived()
environ, _ = self.successResultOf(result)
errors = environ["wsgi.errors"]
error = self.assertRaises(TypeError, errors.write, b"fred")
self.assertEqual(
"write() argument must be str, not b'fred' (bytes)",
str(error))
示例3: test_isRunningInit
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_isRunningInit(self):
"""
L{PIDFile.isRunning} returns true for a process that we are not allowed
to kill (errno=EPERM).
@note: This differs from L{PIDFileTests.test_isRunningNotAllowed} in
that it actually invokes the C{kill} system call, which is useful for
testing of our chosen method for probing the existence of a process
that we are not allowed to kill.
@note: In this case, we try killing C{init}, which is process #1 on
POSIX systems, so this test is not portable. C{init} should always be
running and should not be killable by non-root users.
"""
if SYSTEM_NAME != "posix":
raise SkipTest("This test assumes POSIX")
pidFile = PIDFile(DummyFilePath())
pidFile._write(1) # PID 1 is init on POSIX systems
self.assertTrue(pidFile.isRunning())
示例4: test_decorateTestSuiteReferences
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_decorateTestSuiteReferences(self):
"""
When decorating a test suite in-place, the number of references to the
test objects in that test suite should stay the same.
Previously, L{unittest.decorate} recreated a test suite, so the
original suite kept references to the test objects. This test is here
to ensure the problem doesn't reappear again.
"""
getrefcount = getattr(sys, 'getrefcount', None)
if getrefcount is None:
raise unittest.SkipTest(
"getrefcount not supported on this platform")
test = self.TestCase()
suite = unittest.TestSuite([test])
count1 = getrefcount(test)
unittest.decorate(suite, unittest.TestDecorator)
count2 = getrefcount(test)
self.assertEqual(count1, count2)
示例5: mktime
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def mktime(t9):
"""
Call L{mktime_real}, and if it raises L{OverflowError}, catch it and raise
SkipTest instead.
@param t9: A time as a 9-item tuple.
@type t9: L{tuple}
@return: A timestamp.
@rtype: L{float}
"""
try:
return mktime_real(t9)
except OverflowError:
raise SkipTest(
"Platform cannot construct time zone for {0!r}"
.format(t9)
)
示例6: test_formatTimeDefault
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_formatTimeDefault(self):
"""
Time is first field. Default time stamp format is RFC 3339 and offset
respects the timezone as set by the standard C{TZ} environment variable
and L{tzset} API.
"""
if tzset is None:
raise SkipTest(
"Platform cannot change timezone; unable to verify offsets."
)
addTZCleanup(self)
setTZ("UTC+00")
t = mktime((2013, 9, 24, 11, 40, 47, 1, 267, 1))
event = dict(log_format=u"XYZZY", log_time=t)
self.assertEqual(
formatEventAsClassicLogText(event),
u"2013-09-24T11:40:47+0000 [-#-] XYZZY\n",
)
示例7: test_UDP
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_UDP(self):
"""
Test L{internet.UDPServer} with a random port: starting the service
should give it valid port, and stopService should free it so that we
can start a server on the same port again.
"""
if not interfaces.IReactorUDP(reactor, None):
raise unittest.SkipTest("This reactor does not support UDP sockets")
p = protocol.DatagramProtocol()
t = internet.UDPServer(0, p)
t.startService()
num = t._port.getHost().port
self.assertNotEqual(num, 0)
def onStop(ignored):
t = internet.UDPServer(num, p)
t.startService()
return t.stopService()
return defer.maybeDeferred(t.stopService).addCallback(onStop)
示例8: test_ecSuccessWithRealBindings
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_ecSuccessWithRealBindings(self):
"""
Integration test that checks the positive code path to ensure that we
use the API properly.
"""
try:
defaultCurve = sslverify._OpenSSLECCurve(
sslverify._defaultCurveName
)
except NotImplementedError:
raise unittest.SkipTest(
"Underlying pyOpenSSL is not based on cryptography."
)
opts = sslverify.OpenSSLCertificateOptions(
privateKey=self.sKey,
certificate=self.sCert,
)
self.assertEqual(defaultCurve, opts._ecCurve)
# Exercise positive code path. getContext swallows errors so we do it
# explicitly by hand.
opts._ecCurve.addECKeyToContext(opts.getContext())
示例9: test_twistdPathInsert
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_twistdPathInsert(self):
"""
The twistd script adds the current working directory to sys.path so
that it's able to import modules from it.
"""
script = self.bin.child("twistd")
if not script.exists():
raise SkipTest(
"Script tests do not apply to installed configuration.")
cwd = getcwd()
self.addCleanup(chdir, cwd)
testDir = FilePath(self.mktemp())
testDir.makedirs()
chdir(testDir.path)
testDir.child("bar.tac").setContent(
"import sys\n"
"print sys.path\n")
output = outputFromPythonScript(script, '-ny', 'bar.tac')
self.assertIn(repr(testDir.path), output)
示例10: test_trialPathInsert
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_trialPathInsert(self):
"""
The trial script adds the current working directory to sys.path so that
it's able to import modules from it.
"""
script = self.bin.child("trial")
if not script.exists():
raise SkipTest(
"Script tests do not apply to installed configuration.")
cwd = getcwd()
self.addCleanup(chdir, cwd)
testDir = FilePath(self.mktemp())
testDir.makedirs()
chdir(testDir.path)
testDir.child("foo.py").setContent("")
output = outputFromPythonScript(script, 'foo')
self.assertIn("PASSED", output)
示例11: assertNoFDsLeaked
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def assertNoFDsLeaked(test_case):
"""Context manager that asserts no file descriptors are leaked.
:param test_case: The ``TestCase`` running this unit test.
:raise SkipTest: when /dev/fd virtual filesystem is not available.
"""
# Make sure there's no file descriptors that will be cleared by GC
# later on:
gc.collect()
def process_fds():
path = FilePath(b"/dev/fd")
if not path.exists():
raise SkipTest("/dev/fd is not available.")
return set([child.basename() for child in path.children()])
fds = process_fds()
try:
yield
finally:
test_case.assertEqual(process_fds(), fds)
示例12: test_unittest_raise_skip_issue748
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_unittest_raise_skip_issue748(testdir):
testdir.makepyfile(
test_foo="""
import unittest
class MyTestCase(unittest.TestCase):
def test_one(self):
raise unittest.SkipTest('skipping due to reasons')
"""
)
result = testdir.runpytest("-v", "-rs")
result.stdout.fnmatch_lines(
"""
*SKIP*[1]*test_foo.py*skipping due to reasons*
*1 skipped*
"""
)
示例13: setUp
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def setUp(self):
self.setUpTestReactor()
if requests is None:
raise unittest.SkipTest("Need to install requests to test oauth2")
self.patch(requests, 'request', mock.Mock(spec=requests.request))
self.patch(requests, 'post', mock.Mock(spec=requests.post))
self.patch(requests, 'get', mock.Mock(spec=requests.get))
self.giteaAuth = GiteaAuth(
'https://gitea.test',
'client-id',
'client-secret')
self._master = master = self.make_master(
url='h:/a/b/', auth=self.giteaAuth)
self.giteaAuth.reconfigAuth(master, master.config)
self.giteaAuth_secret = GiteaAuth(
'https://gitea.test',
Secret("client-id"),
Secret("client-secret"))
self._master = master = self.make_master(
url='h:/a/b/', auth=self.giteaAuth_secret)
fake_storage_service = FakeSecretStorage()
fake_storage_service.reconfigService(
secretdict={
"client-id": "secretClientId",
"client-secret": "secretClientSecret"
})
secret_service = SecretManager()
secret_service.services = [fake_storage_service]
secret_service.setServiceParent(self._master)
self.giteaAuth_secret.reconfigAuth(master, master.config)
示例14: test_topic_bytes
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def test_topic_bytes(self):
"""
`TypeError` results when the *topic* argument is a bytestring on Python 3.
"""
if not six.PY3:
raise unittest.SkipTest('str is bytes on Python 2')
self.failureResultOf(self.producer.send_messages(b'topic', msgs=[b'']), TypeError)
示例15: getFileType
# 需要导入模块: from twisted.trial import unittest [as 别名]
# 或者: from twisted.trial.unittest import SkipTest [as 别名]
def getFileType(self):
try:
from StringIO import StringIO
except ImportError:
raise SkipTest("StringIO.StringIO is not available.")
else:
return StringIO