Skip to content

Commit

Permalink
Merge e35c209 into 6df3804
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 19, 2018
2 parents 6df3804 + e35c209 commit 6f3b3fd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ python:
- 2.7
- 3.4
- 3.5
- 3.6
- pypy
script:
- coverage run `which zope-testrunner` --test-path=src --auto-color --auto-progress
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,8 @@ Changes
1.1.1 (unreleased)
------------------

- Nothing changed yet.
- When the ``TransactionLoop`` raises a ``CommitFailedError`` from a
``TypeError``, it preserves the original message.


1.1.0 (2017-04-17)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -9,9 +9,9 @@
}

TESTS_REQUIRE = [
'nose2[coverage_plugin]',
'zope.testrunner',
'nti.testing',
'fudge',
]

def _read(fname):
Expand All @@ -38,6 +38,7 @@ def _read(fname):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Framework :: ZODB',
Expand Down
19 changes: 15 additions & 4 deletions src/nti/transactions/tests/test_transaction.py
Expand Up @@ -40,13 +40,20 @@ def __init__(self, t=Exception):

def commit(self):
if self.t:
raise self.t()
raise self.t

def test_commit_raises_type_error(self):
def test_commit_raises_type_error_raises_commit_failed(self):
assert_that(calling(_do_commit).with_args(self.RaisingCommit(TypeError),
'', 0),
raises(CommitFailedError))

def test_commit_raises_type_error_raises_commit_failed_good_message(self):
assert_that(calling(_do_commit).with_args(
self.RaisingCommit(TypeError("A custom message")),
'', 0),
raises(CommitFailedError, "A custom message"))


@fudge.patch('nti.transactions.transactions.logger.exception')
def test_commit_raises_assertion_error(self, fake_logger):
fake_logger.expects_call()
Expand Down Expand Up @@ -179,10 +186,14 @@ def _TransactionLoop__free(self, tx):
result = Loop(lambda: 42)()
assert_that(result, is_(42))

@fudge.patch('transaction.begin', 'transaction.abort')
def test_abort_systemexit(self, fake_begin, fake_abort):
@fudge.patch('transaction.begin', 'transaction.abort',
'nti.transactions.transactions.print_exception')
def test_abort_systemexit(self, fake_begin, fake_abort, fake_print):
from zope.testing.loghandler import Handler

fake_begin.expects_call().returns_fake()
fake_abort.expects_call().raises(ValueError)
fake_print.is_callable()

class Loop(TransactionLoop):

Expand Down
5 changes: 3 additions & 2 deletions src/nti/transactions/transactions.py
Expand Up @@ -7,7 +7,6 @@
directly provides the :func:`add_abort_hooks` function; you should
call this if you need such functionality.
.. $Id$
"""

from __future__ import print_function, unicode_literals, absolute_import, division
Expand Down Expand Up @@ -278,7 +277,7 @@ def _do_commit(tx, description, long_commit_duration):
except TypeError:
# Translate this into something meaningful
exc_info = sys.exc_info()
six.reraise(CommitFailedError, None, exc_info[2])
six.reraise(CommitFailedError, CommitFailedError(exc_info[1]), exc_info[2])
except (AssertionError, ValueError):
# We've seen this when we are recalled during retry handling. The higher level
# is in the process of throwing a different exception and the transaction is
Expand All @@ -294,6 +293,8 @@ def _do_commit(tx, description, long_commit_duration):
six.reraise(*exc_info)

raise
finally:
del exc_info

from perfmetrics import Metric

Expand Down

0 comments on commit 6f3b3fd

Please sign in to comment.