Python twisted.trial.unittest.FailTest() Examples

The following are 30 code examples of twisted.trial.unittest.FailTest(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.trial.unittest , or try the search function .
Example #1
Source File: test_dirdbm.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def test_nonStringKeys(self):
        """
        L{dirdbm.DirDBM} operations only support string keys: other types
        should raise a C{AssertionError}. This really ought to be a
        C{TypeError}, but it'll stay like this for backward compatibility.
        """
        self.assertRaises(AssertionError, self.dbm.__setitem__, 2, "3")
        try:
            self.assertRaises(AssertionError, self.dbm.__setitem__, "2", 3)
        except unittest.FailTest:
            # dirdbm.Shelf.__setitem__ supports non-string values
            self.assertIsInstance(self.dbm, dirdbm.Shelf)
        self.assertRaises(AssertionError, self.dbm.__getitem__, 2)
        self.assertRaises(AssertionError, self.dbm.__delitem__, 2)
        self.assertRaises(AssertionError, self.dbm.has_key, 2)
        self.assertRaises(AssertionError, self.dbm.__contains__, 2)
        self.assertRaises(AssertionError, self.dbm.getModificationTime, 2) 
Example #2
Source File: test_dirdbm.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def test_nonStringKeys(self):
        """
        L{dirdbm.DirDBM} operations only support string keys: other types
        should raise a L{TypeError}.
        """
        self.assertRaises(TypeError, self.dbm.__setitem__, 2, "3")
        try:
            self.assertRaises(TypeError, self.dbm.__setitem__, "2", 3)
        except unittest.FailTest:
            # dirdbm.Shelf.__setitem__ supports non-string values
            self.assertIsInstance(self.dbm, dirdbm.Shelf)
        self.assertRaises(TypeError, self.dbm.__getitem__, 2)
        self.assertRaises(TypeError, self.dbm.__delitem__, 2)
        self.assertRaises(TypeError, self.dbm.has_key, 2)
        self.assertRaises(TypeError, self.dbm.__contains__, 2)
        self.assertRaises(TypeError, self.dbm.getModificationTime, 2) 
Example #3
Source File: test_threadable.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def testThreadedSynchronization(self):
        o = TestObject()

        errors = []

        def callMethodLots():
            try:
                for i in range(1000):
                    o.aMethod()
            except AssertionError as e:
                errors.append(str(e))

        threads = []
        for x in range(5):
            t = threading.Thread(target=callMethodLots)
            threads.append(t)
            t.start()

        for t in threads:
            t.join()

        if errors:
            raise unittest.FailTest(errors) 
Example #4
Source File: test_release.py    From learn_python3_spider with MIT License 6 votes vote down vote up
def doNotFailOnNetworkError(func):
    """
    A decorator which makes APIBuilder tests not fail because of intermittent
    network failures -- mamely, APIBuilder being unable to get the "object
    inventory" of other projects.

    @param func: The function to decorate.

    @return: A decorated function which won't fail if the object inventory
        fetching fails.
    """
    @functools.wraps(func)
    def wrapper(*a, **kw):
        try:
            func(*a, **kw)
        except FailTest as e:
            if e.args[0].startswith("'Failed to get object inventory from "):
                raise SkipTest(
                    ("This test is prone to intermittent network errors. "
                     "See ticket 8753. Exception was: {!r}").format(e))
            raise
    return wrapper 
Example #5
Source File: test_threadable.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def testThreadedSynchronization(self):
        o = TestObject()

        errors = []

        def callMethodLots():
            try:
                for i in range(1000):
                    o.aMethod()
            except AssertionError as e:
                errors.append(str(e))

        threads = []
        for x in range(5):
            t = threading.Thread(target=callMethodLots)
            threads.append(t)
            t.start()

        for t in threads:
            t.join()

        if errors:
            raise unittest.FailTest(errors) 
Example #6
Source File: test_dirdbm.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_nonStringKeys(self):
        """
        L{dirdbm.DirDBM} operations only support string keys: other types
        should raise a L{TypeError}.
        """
        self.assertRaises(TypeError, self.dbm.__setitem__, 2, "3")
        try:
            self.assertRaises(TypeError, self.dbm.__setitem__, "2", 3)
        except unittest.FailTest:
            # dirdbm.Shelf.__setitem__ supports non-string values
            self.assertIsInstance(self.dbm, dirdbm.Shelf)
        self.assertRaises(TypeError, self.dbm.__getitem__, 2)
        self.assertRaises(TypeError, self.dbm.__delitem__, 2)
        self.assertRaises(TypeError, self.dbm.has_key, 2)
        self.assertRaises(TypeError, self.dbm.__contains__, 2)
        self.assertRaises(TypeError, self.dbm.getModificationTime, 2) 
Example #7
Source File: test_release.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def doNotFailOnNetworkError(func):
    """
    A decorator which makes APIBuilder tests not fail because of intermittent
    network failures -- mamely, APIBuilder being unable to get the "object
    inventory" of other projects.

    @param func: The function to decorate.

    @return: A decorated function which won't fail if the object inventory
        fetching fails.
    """
    @functools.wraps(func)
    def wrapper(*a, **kw):
        try:
            func(*a, **kw)
        except FailTest as e:
            if e.args[0].startswith("'Failed to get object inventory from "):
                raise SkipTest(
                    ("This test is prone to intermittent network errors. "
                     "See ticket 8753. Exception was: {!r}").format(e))
            raise
    return wrapper 
Example #8
Source File: detests.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        return defer.fail(unittest.FailTest('i fail')) 
Example #9
Source File: test_epoll.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_create(self):
        """
        Test the creation of an epoll object.
        """
        try:
            p = _epoll.epoll(16)
        except OSError, e:
            raise unittest.FailTest(str(e)) 
Example #10
Source File: test_names.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def _cbRoundRobinBackoff(self, result):
        raise unittest.FailTest("Lookup address succeeded, should have timed out") 
Example #11
Source File: test_util.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def testRaises(self):
        self.assertTrue(util.raises(ZeroDivisionError, divmod, 1, 0))
        self.assertFalse(util.raises(ZeroDivisionError, divmod, 0, 1))

        try:
            util.raises(TypeError, divmod, 1, 0)
        except ZeroDivisionError:
            pass
        else:
            raise unittest.FailTest("util.raises didn't raise when it should have") 
Example #12
Source File: test_util.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def testRaises(self):
        self.failUnless(util.raises(ZeroDivisionError, divmod, 1, 0))
        self.failIf(util.raises(ZeroDivisionError, divmod, 0, 1))

        try:
            util.raises(TypeError, divmod, 1, 0)
        except ZeroDivisionError:
            pass
        else:
            raise unittest.FailTest, "util.raises didn't raise when it should have" 
Example #13
Source File: test_names.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def _cbRoundRobinBackoff(self, result):
        raise unittest.FailTest("Lookup address succeeded, should have timed out") 
Example #14
Source File: test_util.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def testRaises(self):
        self.failUnless(util.raises(ZeroDivisionError, divmod, 1, 0))
        self.failIf(util.raises(ZeroDivisionError, divmod, 0, 1))

        try:
            util.raises(TypeError, divmod, 1, 0)
        except ZeroDivisionError:
            pass
        else:
            raise unittest.FailTest, "util.raises didn't raise when it should have" 
Example #15
Source File: test_assertions.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def testExceptions(self):
        exc = self.assertRaises(ZeroDivisionError, lambda: 1/0)
        assert isinstance(exc, ZeroDivisionError), "ZeroDivisionError instance not returned"
        
        for func in [lambda: 1/0, lambda: None]:
            try:
                self.assertRaises(ValueError, func)
            except unittest.FailTest:
                # Success!
                pass
            except:
                raise unittest.FailTest("FailTest not raised", failure.Failure().getTraceback())
            else:
                raise unittest.FailTest("FailTest not raised") 
Example #16
Source File: detests.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        return defer.fail(unittest.FailTest('i fail')) 
Example #17
Source File: test_nooldstyle.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_newStyleClassesOnly(self):
        """
        Test that C{self.module} has no old-style classes in it.
        """
        try:
            module = namedAny(self.module)
        except ImportError as e:
            raise unittest.SkipTest("Not importable: {}".format(e))

        oldStyleClasses = []

        for name, val in inspect.getmembers(module):
            if hasattr(val, "__module__") \
               and val.__module__ == self.module:
                if isinstance(val, types.ClassType):
                    oldStyleClasses.append(fullyQualifiedName(val))

        if oldStyleClasses:

            self.todo = "Not all classes are made new-style yet. See #8243."

            for x in forbiddenModules:
                if self.module.startswith(x):
                    delattr(self, "todo")

            raise unittest.FailTest(
                "Old-style classes in {module}: {val}".format(
                    module=self.module,
                    val=", ".join(oldStyleClasses))) 
Example #18
Source File: test_text.py    From imaginary with MIT License 5 votes vote down vote up
def testMega(self):
        # trial should support this use case.
        failures = []
        for n, (start, finish, output, msg) in enumerate(self.testData):
            got = finish.toVT102(start)

            if got != output:
                failures.append((got, output, str(n) + ': ' + msg))

        if failures:
            failures.insert(0,
                            ('received', 'expected', "what's up"))
            raise unittest.FailTest(pprint.pformat(failures)) 
Example #19
Source File: test_ssh.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def ssh_USERAUTH_SUCCESS(self, packet):
            if not self.canSucceedPassword and self.canSucceedPublicKey:
                raise unittest.FailTest(
                    'got USERAUTH_SUCCESS before password and publickey')
            userauth.SSHUserAuthClient.ssh_USERAUTH_SUCCESS(self, packet) 
Example #20
Source File: test_ssh.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def receiveUnimplemented(self, seqID):
            raise unittest.FailTest('got unimplemented: seqid %s' % (seqID,))
            self.expectedLoseConnection = 1
            self.loseConnection() 
Example #21
Source File: test_ssh.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def connectionLost(self, reason):
            if self.done:
                return
            if not hasattr(self, 'expectedLoseConnection'):
                raise unittest.FailTest(
                    'unexpectedly lost connection %s\n%s' % (self, reason))
            self.done = 1 
Example #22
Source File: test_release.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_doesNotSkipOnDifferentError(self):
        """
        If there is a L{FailTest} that is not the intersphinx fetching error,
        it will be passed through.
        """
        @doNotFailOnNetworkError
        def inner():
            self.assertEqual("Error!!!!", "")

        try:
            inner()
        except Exception as e:
            self.assertIsInstance(e, FailTest) 
Example #23
Source File: test_release.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_skipsOnAssertionError(self):
        """
        When the test raises L{FailTest} and the assertion failure starts with
        "'Failed to get object inventory from ", the test will be skipped
        instead.
        """
        @doNotFailOnNetworkError
        def inner():
            self.assertEqual("Failed to get object inventory from blah", "")

        try:
            inner()
        except Exception as e:
            self.assertIsInstance(e, SkipTest) 
Example #24
Source File: test_util.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def testRaises(self):
        self.assertTrue(util.raises(ZeroDivisionError, divmod, 1, 0))
        self.assertFalse(util.raises(ZeroDivisionError, divmod, 0, 1))

        try:
            util.raises(TypeError, divmod, 1, 0)
        except ZeroDivisionError:
            pass
        else:
            raise unittest.FailTest("util.raises didn't raise when it should have") 
Example #25
Source File: detests.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def setUp(self):
        return defer.fail(unittest.FailTest('i fail')) 
Example #26
Source File: test_nooldstyle.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_newStyleClassesOnly(self):
        """
        Test that C{self.module} has no old-style classes in it.
        """
        try:
            module = namedAny(self.module)
        except ImportError as e:
            raise unittest.SkipTest("Not importable: {}".format(e))

        oldStyleClasses = []

        for name, val in inspect.getmembers(module):
            if hasattr(val, "__module__") \
               and val.__module__ == self.module:
                if isinstance(val, types.ClassType):
                    oldStyleClasses.append(fullyQualifiedName(val))

        if oldStyleClasses:

            self.todo = "Not all classes are made new-style yet. See #8243."

            for x in forbiddenModules:
                if self.module.startswith(x):
                    delattr(self, "todo")

            raise unittest.FailTest(
                "Old-style classes in {module}: {val}".format(
                    module=self.module,
                    val=", ".join(oldStyleClasses))) 
Example #27
Source File: test_ssh.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def ssh_USERAUTH_SUCCESS(self, packet):
            if not self.canSucceedPassword and self.canSucceedPublicKey:
                raise unittest.FailTest(
                    'got USERAUTH_SUCCESS before password and publickey')
            userauth.SSHUserAuthClient.ssh_USERAUTH_SUCCESS(self, packet) 
Example #28
Source File: test_ssh.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def receiveUnimplemented(self, seqID):
            raise unittest.FailTest('got unimplemented: seqid %s' % (seqID,))
            self.expectedLoseConnection = 1
            self.loseConnection() 
Example #29
Source File: test_ssh.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def connectionLost(self, reason):
            if self.done:
                return
            if not hasattr(self, 'expectedLoseConnection'):
                raise unittest.FailTest(
                    'unexpectedly lost connection %s\n%s' % (self, reason))
            self.done = 1 
Example #30
Source File: test_release.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_doesNotSkipOnDifferentError(self):
        """
        If there is a L{FailTest} that is not the intersphinx fetching error,
        it will be passed through.
        """
        @doNotFailOnNetworkError
        def inner():
            self.assertEqual("Error!!!!", "")

        try:
            inner()
        except Exception as e:
            self.assertIsInstance(e, FailTest)