Here are the examples of the python api twisted.internet.defer.FirstError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
7 Examples
3
Source : test_defer.py
with MIT License
from autofelix
with MIT License
from autofelix
def test_repr(self):
"""
The repr of a L{FirstError} instance includes the repr of the value of
the sub-failure and the index which corresponds to the L{FirstError}.
"""
exc = ValueError("some text")
try:
raise exc
except:
f = failure.Failure()
error = defer.FirstError(f, 3)
self.assertEqual(
repr(error),
"FirstError[#3, %s]" % (repr(exc),))
def test_str(self):
3
Source : test_defer.py
with MIT License
from autofelix
with MIT License
from autofelix
def test_str(self):
"""
The str of a L{FirstError} instance includes the str of the
sub-failure and the index which corresponds to the L{FirstError}.
"""
exc = ValueError("some text")
try:
raise exc
except:
f = failure.Failure()
error = defer.FirstError(f, 5)
self.assertEqual(
str(error),
"FirstError[#5, %s]" % (str(f),))
def test_comparison(self):
3
Source : test_interpolate_secrets.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_secret_not_found(self):
command = Interpolate("echo %(secret:fuo)s")
yield self.assertFailure(self.build.render(command), defer.FirstError)
gc.collect()
self.flushLoggedErrors(defer.FirstError)
self.flushLoggedErrors(KeyError)
class TestInterpolateSecretsNoService(TestReactorMixin, unittest.TestCase,
3
Source : test_interpolate_secrets.py
with GNU General Public License v2.0
from flathub
with GNU General Public License v2.0
from flathub
def test_secret(self):
command = Interpolate("echo %(secret:fuo)s")
yield self.assertFailure(self.build.render(command), defer.FirstError)
gc.collect()
self.flushLoggedErrors(defer.FirstError)
self.flushLoggedErrors(KeyError)
class TestInterpolateSecretsHiddenSecrets(TestReactorMixin, unittest.TestCase):
3
Source : __init__.py
with Apache License 2.0
from matrix-org
with Apache License 2.0
from matrix-org
def unwrapFirstError(failure: Failure) -> Failure:
# defer.gatherResults and DeferredLists wrap failures.
failure.trap(defer.FirstError)
return failure.value.subFailure # type: ignore[union-attr] # Issue in Twisted's annotations
@attr.s(slots=True)
0
Source : ftp.py
with MIT License
from autofelix
with MIT License
from autofelix
def _unwrapFirstError(failure):
failure.trap(defer.FirstError)
return failure.value.subFailure
class FTPDataPortFactory(protocol.ServerFactory):
0
Source : test_defer.py
with MIT License
from autofelix
with MIT License
from autofelix
def test_comparison(self):
"""
L{FirstError} instances compare equal to each other if and only if
their failure and index compare equal. L{FirstError} instances do not
compare equal to instances of other types.
"""
try:
1 // 0
except:
firstFailure = failure.Failure()
one = defer.FirstError(firstFailure, 13)
anotherOne = defer.FirstError(firstFailure, 13)
try:
raise ValueError("bar")
except:
secondFailure = failure.Failure()
another = defer.FirstError(secondFailure, 9)
self.assertTrue(one == anotherOne)
self.assertFalse(one == another)
self.assertTrue(one != another)
self.assertFalse(one != anotherOne)
self.assertFalse(one == 10)
class AlreadyCalledTests(unittest.SynchronousTestCase):