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
f87c10cb
Commit
f87c10cb
authored
Dec 17, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
One test module per main module.
parent
5c10c95c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
100 deletions
+108
-100
transaction/tests/test__manager.py
transaction/tests/test__manager.py
+108
-0
transaction/tests/test_attempt.py
transaction/tests/test_attempt.py
+0
-100
No files found.
transaction/tests/test__manager.py
View file @
f87c10cb
...
@@ -189,6 +189,26 @@ class TransactionManagerTests(unittest.TestCase):
...
@@ -189,6 +189,26 @@ class TransactionManagerTests(unittest.TestCase):
self
.
assertFalse
(
txn
.
_committed
)
self
.
assertFalse
(
txn
.
_committed
)
self
.
assertTrue
(
txn
.
_aborted
)
self
.
assertTrue
(
txn
.
_aborted
)
def
test_savepoint_default
(
self
):
class
_Test
(
object
):
_sp
=
None
def
savepoint
(
self
,
optimistic
):
self
.
_sp
=
optimistic
tm
=
self
.
_makeOne
()
tm
.
_txn
=
txn
=
_Test
()
tm
.
savepoint
()
self
.
assertFalse
(
txn
.
_sp
)
def
test_savepoint_explicit
(
self
):
class
_Test
(
object
):
_sp
=
None
def
savepoint
(
self
,
optimistic
):
self
.
_sp
=
optimistic
tm
=
self
.
_makeOne
()
tm
.
_txn
=
txn
=
_Test
()
tm
.
savepoint
(
True
)
self
.
assertTrue
(
txn
.
_sp
)
# basic tests with two sub trans jars
# basic tests with two sub trans jars
# really we only need one, so tests for
# really we only need one, so tests for
# sub1 should identical to tests for sub2
# sub1 should identical to tests for sub2
...
@@ -334,6 +354,93 @@ class TransactionManagerTests(unittest.TestCase):
...
@@ -334,6 +354,93 @@ class TransactionManagerTests(unittest.TestCase):
assert
nosub1
.
_p_jar
.
ctpc_abort
==
1
assert
nosub1
.
_p_jar
.
ctpc_abort
==
1
class
AttemptTests
(
unittest
.
TestCase
):
def
_makeOne
(
self
,
manager
):
from
transaction._manager
import
Attempt
return
Attempt
(
manager
)
def
test___enter__
(
self
):
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
inst
.
__enter__
()
self
.
assertTrue
(
manager
.
entered
)
def
test___exit__no_exc_no_commit_exception
(
self
):
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
result
=
inst
.
__exit__
(
None
,
None
,
None
)
self
.
assertFalse
(
result
)
self
.
assertTrue
(
manager
.
committed
)
def
test___exit__no_exc_nonretryable_commit_exception
(
self
):
manager
=
DummyManager
(
raise_on_commit
=
ValueError
)
inst
=
self
.
_makeOne
(
manager
)
self
.
assertRaises
(
ValueError
,
inst
.
__exit__
,
None
,
None
,
None
)
self
.
assertTrue
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__no_exc_abort_exception_after_nonretryable_commit_exc
(
self
):
manager
=
DummyManager
(
raise_on_abort
=
ValueError
,
raise_on_commit
=
KeyError
)
inst
=
self
.
_makeOne
(
manager
)
self
.
assertRaises
(
ValueError
,
inst
.
__exit__
,
None
,
None
,
None
)
self
.
assertTrue
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__no_exc_retryable_commit_exception
(
self
):
from
transaction.interfaces
import
TransientError
manager
=
DummyManager
(
raise_on_commit
=
TransientError
)
inst
=
self
.
_makeOne
(
manager
)
result
=
inst
.
__exit__
(
None
,
None
,
None
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__with_exception_value_retryable
(
self
):
from
transaction.interfaces
import
TransientError
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
result
=
inst
.
__exit__
(
TransientError
,
TransientError
(),
None
)
self
.
assertTrue
(
result
)
self
.
assertFalse
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__with_exception_value_nonretryable
(
self
):
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
self
.
assertRaises
(
KeyError
,
inst
.
__exit__
,
KeyError
,
KeyError
(),
None
)
self
.
assertFalse
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
class
DummyManager
(
object
):
entered
=
False
committed
=
False
aborted
=
False
def
__init__
(
self
,
raise_on_commit
=
None
,
raise_on_abort
=
None
):
self
.
raise_on_commit
=
raise_on_commit
self
.
raise_on_abort
=
raise_on_abort
def
_retryable
(
self
,
t
,
v
):
from
transaction._manager
import
TransientError
return
issubclass
(
t
,
TransientError
)
def
__enter__
(
self
):
self
.
entered
=
True
def
abort
(
self
):
self
.
aborted
=
True
if
self
.
raise_on_abort
:
raise
self
.
raise_on_abort
def
commit
(
self
):
self
.
committed
=
True
if
self
.
raise_on_commit
:
raise
self
.
raise_on_commit
class
DataObject
:
class
DataObject
:
def
__init__
(
self
,
transaction_manager
,
nost
=
0
):
def
__init__
(
self
,
transaction_manager
,
nost
=
0
):
...
@@ -436,4 +543,5 @@ def positive_id(obj):
...
@@ -436,4 +543,5 @@ def positive_id(obj):
def
test_suite
():
def
test_suite
():
return
unittest
.
TestSuite
((
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
TransactionManagerTests
),
unittest
.
makeSuite
(
TransactionManagerTests
),
unittest
.
makeSuite
(
AttemptTests
),
))
))
transaction/tests/test_attempt.py
deleted
100644 → 0
View file @
5c10c95c
##############################################################################
#
# Copyright (c) 2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import
unittest
class
TestAttempt
(
unittest
.
TestCase
):
def
_makeOne
(
self
,
manager
):
from
transaction._manager
import
Attempt
return
Attempt
(
manager
)
def
test___enter__
(
self
):
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
inst
.
__enter__
()
self
.
assertTrue
(
manager
.
entered
)
def
test___exit__no_exc_no_commit_exception
(
self
):
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
result
=
inst
.
__exit__
(
None
,
None
,
None
)
self
.
assertFalse
(
result
)
self
.
assertTrue
(
manager
.
committed
)
def
test___exit__no_exc_nonretryable_commit_exception
(
self
):
manager
=
DummyManager
(
raise_on_commit
=
ValueError
)
inst
=
self
.
_makeOne
(
manager
)
self
.
assertRaises
(
ValueError
,
inst
.
__exit__
,
None
,
None
,
None
)
self
.
assertTrue
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__no_exc_abort_exception_after_nonretryable_commit_exc
(
self
):
manager
=
DummyManager
(
raise_on_abort
=
ValueError
,
raise_on_commit
=
KeyError
)
inst
=
self
.
_makeOne
(
manager
)
self
.
assertRaises
(
ValueError
,
inst
.
__exit__
,
None
,
None
,
None
)
self
.
assertTrue
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__no_exc_retryable_commit_exception
(
self
):
from
transaction.interfaces
import
TransientError
manager
=
DummyManager
(
raise_on_commit
=
TransientError
)
inst
=
self
.
_makeOne
(
manager
)
result
=
inst
.
__exit__
(
None
,
None
,
None
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__with_exception_value_retryable
(
self
):
from
transaction.interfaces
import
TransientError
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
result
=
inst
.
__exit__
(
TransientError
,
TransientError
(),
None
)
self
.
assertTrue
(
result
)
self
.
assertFalse
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
def
test___exit__with_exception_value_nonretryable
(
self
):
manager
=
DummyManager
()
inst
=
self
.
_makeOne
(
manager
)
self
.
assertRaises
(
KeyError
,
inst
.
__exit__
,
KeyError
,
KeyError
(),
None
)
self
.
assertFalse
(
manager
.
committed
)
self
.
assertTrue
(
manager
.
aborted
)
class
DummyManager
(
object
):
entered
=
False
committed
=
False
aborted
=
False
def
__init__
(
self
,
raise_on_commit
=
None
,
raise_on_abort
=
None
):
self
.
raise_on_commit
=
raise_on_commit
self
.
raise_on_abort
=
raise_on_abort
def
_retryable
(
self
,
t
,
v
):
from
transaction._manager
import
TransientError
return
issubclass
(
t
,
TransientError
)
def
__enter__
(
self
):
self
.
entered
=
True
def
abort
(
self
):
self
.
aborted
=
True
if
self
.
raise_on_abort
:
raise
self
.
raise_on_abort
def
commit
(
self
):
self
.
committed
=
True
if
self
.
raise_on_commit
:
raise
self
.
raise_on_commit
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