Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
transaction
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
transaction
Commits
005a161c
Commit
005a161c
authored
Dec 18, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coverage for Transaction commit hooks APIs.
parent
d3a286d5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
2 deletions
+74
-2
transaction/_transaction.py
transaction/_transaction.py
+0
-2
transaction/tests/test__transaction.py
transaction/tests/test__transaction.py
+74
-0
No files found.
transaction/_transaction.py
View file @
005a161c
...
@@ -306,7 +306,6 @@ class Transaction(object):
...
@@ -306,7 +306,6 @@ class Transaction(object):
finally
:
finally
:
del
t
,
v
,
tb
del
t
,
v
,
tb
def
_saveAndRaiseCommitishError
(
self
):
def
_saveAndRaiseCommitishError
(
self
):
t
=
None
t
=
None
v
=
None
v
=
None
...
@@ -317,7 +316,6 @@ class Transaction(object):
...
@@ -317,7 +316,6 @@ class Transaction(object):
finally
:
finally
:
del
t
,
v
,
tb
del
t
,
v
,
tb
def
getBeforeCommitHooks
(
self
):
def
getBeforeCommitHooks
(
self
):
""" See ITransaction.
""" See ITransaction.
"""
"""
...
...
transaction/tests/test__transaction.py
View file @
005a161c
...
@@ -540,6 +540,80 @@ class TransactionTests(unittest.TestCase):
...
@@ -540,6 +540,80 @@ class TransactionTests(unittest.TestCase):
self
.
assertTrue
(
synch
.
_before
is
t
)
self
.
assertTrue
(
synch
.
_before
is
t
)
self
.
assertTrue
(
synch
.
_after
is
t
)
#called in _cleanup
self
.
assertTrue
(
synch
.
_after
is
t
)
#called in _cleanup
def
test_getBeforeCommitHooks_empty
(
self
):
tm
=
self
.
_makeOne
()
self
.
assertEqual
(
list
(
tm
.
getBeforeCommitHooks
()),
[])
def
test_addBeforeCommitHook
(
self
):
def
_hook
(
*
args
,
**
kw
):
pass
tm
=
self
.
_makeOne
()
tm
.
addBeforeCommitHook
(
_hook
,
(
'one'
,),
dict
(
uno
=
1
))
self
.
assertEqual
(
list
(
tm
.
getBeforeCommitHooks
()),
[(
_hook
,
(
'one'
,),
{
'uno'
:
1
})])
def
test_addBeforeCommitHook_w_kws
(
self
):
def
_hook
(
*
args
,
**
kw
):
pass
tm
=
self
.
_makeOne
()
tm
.
addBeforeCommitHook
(
_hook
,
(
'one'
,))
self
.
assertEqual
(
list
(
tm
.
getBeforeCommitHooks
()),
[(
_hook
,
(
'one'
,),
{})])
def
test_getAfterCommitHooks_empty
(
self
):
tm
=
self
.
_makeOne
()
self
.
assertEqual
(
list
(
tm
.
getAfterCommitHooks
()),
[])
def
test_addAfterCommitHook
(
self
):
def
_hook
(
*
args
,
**
kw
):
pass
tm
=
self
.
_makeOne
()
tm
.
addAfterCommitHook
(
_hook
,
(
'one'
,),
dict
(
uno
=
1
))
self
.
assertEqual
(
list
(
tm
.
getAfterCommitHooks
()),
[(
_hook
,
(
'one'
,),
{
'uno'
:
1
})])
def
test_addAfterCommitHook_wo_kws
(
self
):
def
_hook
(
*
args
,
**
kw
):
pass
tm
=
self
.
_makeOne
()
tm
.
addAfterCommitHook
(
_hook
,
(
'one'
,))
self
.
assertEqual
(
list
(
tm
.
getAfterCommitHooks
()),
[(
_hook
,
(
'one'
,),
{})])
def
test_callAfterCommitHook_w_error
(
self
):
from
transaction.tests.common
import
DummyLogger
from
transaction.tests.common
import
Monkey
from
transaction
import
_transaction
_hooked2
=
[]
def
_hook1
(
*
args
,
**
kw
):
raise
ValueError
()
def
_hook2
(
*
args
,
**
kw
):
_hooked2
.
append
((
args
,
kw
))
logger
=
DummyLogger
()
with
Monkey
(
_transaction
,
_LOGGER
=
logger
):
tm
=
self
.
_makeOne
()
logger
.
_clear
()
tm
.
addAfterCommitHook
(
_hook1
,
(
'one'
,))
tm
.
addAfterCommitHook
(
_hook2
,
(
'two'
,),
dict
(
dos
=
2
))
tm
.
_callAfterCommitHooks
()
# second hook gets called even if first raises
self
.
assertEqual
(
_hooked2
,
[((
True
,
'two'
,),
{
'dos'
:
2
})])
self
.
assertEqual
(
len
(
logger
.
_log
),
1
)
self
.
assertEqual
(
logger
.
_log
[
0
][
0
],
'error'
)
self
.
assertTrue
(
logger
.
_log
[
0
][
1
].
startswith
(
"Error in after commit hook"
))
def
test_callAfterCommitHook_w_abort
(
self
):
_hooked2
=
[],
[]
def
_hook1
(
*
args
,
**
kw
):
raise
ValueError
()
def
_hook2
(
*
args
,
**
kw
):
_hooked2
.
append
((
args
,
kw
))
tm
=
self
.
_makeOne
()
tm
.
addAfterCommitHook
(
_hook1
,
(
'one'
,))
tm
.
addAfterCommitHook
(
_hook2
,
(
'two'
,),
dict
(
dos
=
2
))
tm
.
_callAfterCommitHooks
()
def
test_note
(
self
):
def
test_note
(
self
):
t
=
self
.
_makeOne
()
t
=
self
.
_makeOne
()
try
:
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment