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
6b525a6e
Commit
6b525a6e
authored
Dec 17, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate example code.
parent
de6a7506
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
110 deletions
+85
-110
docs/datamanager.rst
docs/datamanager.rst
+2
-2
docs/resourcemanager.rst
docs/resourcemanager.rst
+2
-2
transaction/tests/SampleDataManager.py
transaction/tests/SampleDataManager.py
+0
-89
transaction/tests/examples.py
transaction/tests/examples.py
+79
-1
transaction/tests/test_transaction.py
transaction/tests/test_transaction.py
+2
-16
No files found.
docs/datamanager.rst
View file @
6b525a6e
...
@@ -6,9 +6,9 @@ Simple Data Manager
...
@@ -6,9 +6,9 @@ Simple Data Manager
.. doctest::
.. doctest::
>>> from transaction.tests.
SampleDataManager
import DataManager
>>> from transaction.tests.
examples
import DataManager
This :class:`transaction.tests.
SampleDataManager
.DataManager` class
This :class:`transaction.tests.
examples
.DataManager` class
provides a trivial data-manager implementation and docstrings to illustrate
provides a trivial data-manager implementation and docstrings to illustrate
the the protocol and to provide a tool for writing tests.
the the protocol and to provide a tool for writing tests.
...
...
docs/resourcemanager.rst
View file @
6b525a6e
...
@@ -6,9 +6,9 @@ Simple Resource Manager
...
@@ -6,9 +6,9 @@ Simple Resource Manager
.. doctest::
.. doctest::
>>> from transaction.tests.
SampleResourceManager
import ResourceManager
>>> from transaction.tests.
examples
import ResourceManager
This :class:`transaction.tests.
SampleResourceManager
.ResourceManager`
This :class:`transaction.tests.
examples
.ResourceManager`
class provides a trivial resource-manager implementation and doc
class provides a trivial resource-manager implementation and doc
strings to illustrate the protocol and to provide a tool for writing
strings to illustrate the protocol and to provide a tool for writing
tests.
tests.
...
...
transaction/tests/SampleDataManager.py
deleted
100644 → 0
View file @
de6a7506
##############################################################################
#
# Copyright (c) 2004 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.
#
##############################################################################
"""Sample objects for use in tests
Used by the 'datamanager' chapter in the Sphinx docs.
"""
class
DataManager
(
object
):
"""Sample data manager
"""
def
__init__
(
self
):
self
.
state
=
0
self
.
sp
=
0
self
.
transaction
=
None
self
.
delta
=
0
self
.
prepared
=
False
def
inc
(
self
,
n
=
1
):
self
.
delta
+=
n
def
prepare
(
self
,
transaction
):
if
self
.
prepared
:
raise
TypeError
(
'Already prepared'
)
self
.
_checkTransaction
(
transaction
)
self
.
prepared
=
True
self
.
transaction
=
transaction
self
.
state
+=
self
.
delta
def
_checkTransaction
(
self
,
transaction
):
if
(
transaction
is
not
self
.
transaction
and
self
.
transaction
is
not
None
):
raise
TypeError
(
"Transaction missmatch"
,
transaction
,
self
.
transaction
)
def
abort
(
self
,
transaction
):
self
.
_checkTransaction
(
transaction
)
if
self
.
transaction
is
not
None
:
self
.
transaction
=
None
if
self
.
prepared
:
self
.
state
-=
self
.
delta
self
.
prepared
=
False
self
.
delta
=
0
def
commit
(
self
,
transaction
):
if
not
self
.
prepared
:
raise
TypeError
(
'Not prepared to commit'
)
self
.
_checkTransaction
(
transaction
)
self
.
delta
=
0
self
.
transaction
=
None
self
.
prepared
=
False
def
savepoint
(
self
,
transaction
):
if
self
.
prepared
:
raise
TypeError
(
"Can't get savepoint during two-phase commit"
)
self
.
_checkTransaction
(
transaction
)
self
.
transaction
=
transaction
self
.
sp
+=
1
return
Rollback
(
self
)
class
Rollback
(
object
):
def
__init__
(
self
,
dm
):
self
.
dm
=
dm
self
.
sp
=
dm
.
sp
self
.
delta
=
dm
.
delta
self
.
transaction
=
dm
.
transaction
def
rollback
(
self
):
if
self
.
transaction
is
not
self
.
dm
.
transaction
:
raise
TypeError
(
"Attempt to rollback stale rollback"
)
if
self
.
dm
.
sp
<
self
.
sp
:
raise
TypeError
(
"Attempt to roll back to invalid save point"
,
self
.
sp
,
self
.
dm
.
sp
)
self
.
dm
.
sp
=
self
.
sp
self
.
dm
.
delta
=
self
.
delta
transaction/tests/
SampleResourceManager
.py
→
transaction/tests/
examples
.py
View file @
6b525a6e
...
@@ -13,11 +13,89 @@
...
@@ -13,11 +13,89 @@
##############################################################################
##############################################################################
"""Sample objects for use in tests
"""Sample objects for use in tests
Used by the 'resourcemanager' chapter in the Sphinx docs.
"""
"""
class
DataManager
(
object
):
"""Sample data manager
Used by the 'datamanager' chapter in the Sphinx docs.
"""
def
__init__
(
self
):
self
.
state
=
0
self
.
sp
=
0
self
.
transaction
=
None
self
.
delta
=
0
self
.
prepared
=
False
def
inc
(
self
,
n
=
1
):
self
.
delta
+=
n
def
prepare
(
self
,
transaction
):
if
self
.
prepared
:
raise
TypeError
(
'Already prepared'
)
self
.
_checkTransaction
(
transaction
)
self
.
prepared
=
True
self
.
transaction
=
transaction
self
.
state
+=
self
.
delta
def
_checkTransaction
(
self
,
transaction
):
if
(
transaction
is
not
self
.
transaction
and
self
.
transaction
is
not
None
):
raise
TypeError
(
"Transaction missmatch"
,
transaction
,
self
.
transaction
)
def
abort
(
self
,
transaction
):
self
.
_checkTransaction
(
transaction
)
if
self
.
transaction
is
not
None
:
self
.
transaction
=
None
if
self
.
prepared
:
self
.
state
-=
self
.
delta
self
.
prepared
=
False
self
.
delta
=
0
def
commit
(
self
,
transaction
):
if
not
self
.
prepared
:
raise
TypeError
(
'Not prepared to commit'
)
self
.
_checkTransaction
(
transaction
)
self
.
delta
=
0
self
.
transaction
=
None
self
.
prepared
=
False
def
savepoint
(
self
,
transaction
):
if
self
.
prepared
:
raise
TypeError
(
"Can't get savepoint during two-phase commit"
)
self
.
_checkTransaction
(
transaction
)
self
.
transaction
=
transaction
self
.
sp
+=
1
return
Rollback
(
self
)
class
Rollback
(
object
):
def
__init__
(
self
,
dm
):
self
.
dm
=
dm
self
.
sp
=
dm
.
sp
self
.
delta
=
dm
.
delta
self
.
transaction
=
dm
.
transaction
def
rollback
(
self
):
if
self
.
transaction
is
not
self
.
dm
.
transaction
:
raise
TypeError
(
"Attempt to rollback stale rollback"
)
if
self
.
dm
.
sp
<
self
.
sp
:
raise
TypeError
(
"Attempt to roll back to invalid save point"
,
self
.
sp
,
self
.
dm
.
sp
)
self
.
dm
.
sp
=
self
.
sp
self
.
dm
.
delta
=
self
.
delta
class
ResourceManager
(
object
):
class
ResourceManager
(
object
):
""" Sample resource manager.
Used by the 'resourcemanager' chapter in the Sphinx docs.
"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
state
=
0
self
.
state
=
0
self
.
sp
=
0
self
.
sp
=
0
...
...
transaction/tests/test_transaction.py
View file @
6b525a6e
...
@@ -307,7 +307,7 @@ class MiscellaneousTests(unittest.TestCase):
...
@@ -307,7 +307,7 @@ class MiscellaneousTests(unittest.TestCase):
# The join method is provided for "backward-compatability" with ZODB 4
# The join method is provided for "backward-compatability" with ZODB 4
# data managers.
# data managers.
from
transaction
import
Transaction
from
transaction
import
Transaction
from
transaction.tests.
SampleDataManager
import
DataManager
from
transaction.tests.
examples
import
DataManager
from
transaction._transaction
import
DataManagerAdapter
from
transaction._transaction
import
DataManagerAdapter
# The argument to join must be a zodb4 data manager,
# The argument to join must be a zodb4 data manager,
# transaction.interfaces.IDataManager.
# transaction.interfaces.IDataManager.
...
@@ -469,23 +469,9 @@ class HoserJar(BasicJar):
...
@@ -469,23 +469,9 @@ class HoserJar(BasicJar):
HoserJar
.
committed
+=
1
HoserJar
.
committed
+=
1
def
hook
():
pass
def
test_suite
():
def
test_suite
():
from
doctest
import
DocTestSuite
return
unittest
.
TestSuite
((
suite
=
unittest
.
TestSuite
((
DocTestSuite
(),
unittest
.
makeSuite
(
TransactionManagerTests
),
unittest
.
makeSuite
(
TransactionManagerTests
),
unittest
.
makeSuite
(
Test_oid_repr
),
unittest
.
makeSuite
(
Test_oid_repr
),
unittest
.
makeSuite
(
MiscellaneousTests
),
unittest
.
makeSuite
(
MiscellaneousTests
),
))
))
return
suite
# additional_tests is for setuptools "setup.py test" support
additional_tests
=
test_suite
if
__name__
==
'__main__'
:
unittest
.
TextTestRunner
().
run
(
test_suite
())
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