Skip to content

Commit

Permalink
Added sync registration and explit tests for the thread local manager
Browse files Browse the repository at this point in the history
Because coveralls. :/
  • Loading branch information
jimfulton committed Oct 14, 2018
1 parent 0084eab commit e095120
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions transaction/tests/test__manager.py
Expand Up @@ -11,6 +11,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import mock
import unittest


Expand Down Expand Up @@ -694,6 +695,54 @@ def run(self):
stopped.set()
runner.join(1)


class TestThreadTransactionManager(unittest.TestCase):

def test_sync_registration_thread_local_manager(self):
import transaction

sync = mock.MagicMock()
transaction.manager.registerSynch(sync)
t = transaction.begin()
sync.newTransaction.assert_called_with(t)
transaction.abort()
sync.beforeCompletion.assert_called_with(t)
sync.afterCompletion.assert_called_with(t)
transaction.manager.unregisterSynch(sync)
sync.reset_mock()
transaction.begin()
transaction.abort()
sync.newTransaction.assert_not_called()
sync.beforeCompletion.assert_not_called()
sync.afterCompletion.assert_not_called()

transaction.manager.registerSynch(sync)
t = transaction.begin()
sync.newTransaction.assert_called_with(t)
transaction.abort()
sync.beforeCompletion.assert_called_with(t)
sync.afterCompletion.assert_called_with(t)
transaction.manager.clearSynchs()
sync.reset_mock()
transaction.begin()
transaction.abort()
sync.newTransaction.assert_not_called()
sync.beforeCompletion.assert_not_called()
sync.afterCompletion.assert_not_called()

def test_explicit_thread_local_manager(self):
import transaction.interfaces

self.assertFalse(transaction.manager.explicit)
transaction.abort()
transaction.manager.explicit = True
self.assertTrue(transaction.manager.explicit)
with self.assertRaises(transaction.interfaces.NoTransaction):
transaction.abort()
transaction.manager.explicit = False
transaction.abort()


class AttemptTests(unittest.TestCase):

def _makeOne(self, manager):
Expand Down

0 comments on commit e095120

Please sign in to comment.