Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
c58b0c7a
Commit
c58b0c7a
authored
Sep 18, 2008
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't import MUT at module scope of test; use jar from utils.
parent
4618b7b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
74 deletions
+66
-74
src/persistent/tests/testPersistent.py
src/persistent/tests/testPersistent.py
+66
-74
No files found.
src/persistent/tests/testPersistent.py
View file @
c58b0c7a
...
...
@@ -11,84 +11,29 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import
pickle
import
time
import
unittest
from
persistent
import
Persistent
,
GHOST
,
UPTODATE
,
CHANGED
,
STICKY
from
persistent.cPickleCache
import
PickleCache
from
persistent.TimeStamp
import
TimeStamp
from
ZODB.utils
import
p64
class
Jar
(
object
):
"""Testing stub for _p_jar attribute."""
def
__init__
(
self
):
self
.
cache
=
PickleCache
(
self
)
self
.
oid
=
1
self
.
registered
=
{}
def
add
(
self
,
obj
):
obj
.
_p_oid
=
p64
(
self
.
oid
)
self
.
oid
+=
1
obj
.
_p_jar
=
self
self
.
cache
[
obj
.
_p_oid
]
=
obj
def
close
(
self
):
pass
# the following methods must be implemented to be a jar
def
setklassstate
(
self
):
# I don't know what this method does, but the pickle cache
# constructor calls it.
pass
def
register
(
self
,
obj
):
self
.
registered
[
obj
]
=
1
def
setstate
(
self
,
obj
):
# Trivial setstate() implementation that just re-initializes
# the object. This isn't what setstate() is supposed to do,
# but it suffices for the tests.
obj
.
__class__
.
__init__
(
obj
)
class
P
(
Persistent
):
pass
class
H1
(
Persistent
):
def
__init__
(
self
):
self
.
n
=
0
def
__getattr__
(
self
,
attr
):
self
.
n
+=
1
return
self
.
n
class
H2
(
Persistent
):
def
__init__
(
self
):
self
.
n
=
0
def
__getattribute__
(
self
,
attr
):
supergetattr
=
super
(
H2
,
self
).
__getattribute__
try
:
return
supergetattr
(
attr
)
except
AttributeError
:
n
=
supergetattr
(
"n"
)
self
.
n
=
n
+
1
return
n
+
1
Picklable
=
None
# avoid global import of Persistent; updated later
class
PersistenceTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
jar
=
Jar
()
from
persistent.tests.utils
import
ResettingJar
self
.
jar
=
ResettingJar
()
def
tearDown
(
self
):
self
.
jar
.
close
()
def
_make_P
(
self
):
from
persistent
import
Persistent
class
P
(
Persistent
):
pass
return
P
()
def
testOidAndJarAttrs
(
self
):
obj
=
P
()
obj
=
self
.
_make_
P
()
self
.
assertEqual
(
obj
.
_p_oid
,
None
)
obj
.
_p_oid
=
12
self
.
assertEqual
(
obj
.
_p_oid
,
12
)
...
...
@@ -112,7 +57,10 @@ class PersistenceTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
setoid
)
def
testChangedAndState
(
self
):
obj
=
P
()
from
persistent
import
CHANGED
from
persistent
import
GHOST
from
persistent
import
UPTODATE
obj
=
self
.
_make_P
()
self
.
jar
.
add
(
obj
)
# The value returned for _p_changed can be one of:
...
...
@@ -146,7 +94,7 @@ class PersistenceTest(unittest.TestCase):
self
.
assertEqual
(
obj
.
_p_changed
,
None
)
self
.
assertEqual
(
obj
.
_p_state
,
GHOST
)
obj
=
P
()
obj
=
self
.
_make_
P
()
self
.
jar
.
add
(
obj
)
obj
.
_p_changed
=
1
# You can transition directly from modified to ghost if
...
...
@@ -156,9 +104,13 @@ class PersistenceTest(unittest.TestCase):
self
.
assertEqual
(
obj
.
_p_state
,
GHOST
)
def
testStateReadonly
(
self
):
from
persistent
import
CHANGED
from
persistent
import
GHOST
from
persistent
import
STICKY
from
persistent
import
UPTODATE
# make sure we can't write to _p_state; we don't want yet
# another way to change state!
obj
=
P
()
obj
=
self
.
_make_
P
()
def
setstate
(
value
):
obj
.
_p_state
=
value
self
.
assertRaises
(
Exception
,
setstate
,
GHOST
)
...
...
@@ -167,7 +119,9 @@ class PersistenceTest(unittest.TestCase):
self
.
assertRaises
(
Exception
,
setstate
,
STICKY
)
def
testInvalidate
(
self
):
obj
=
P
()
from
persistent
import
GHOST
from
persistent
import
UPTODATE
obj
=
self
.
_make_P
()
self
.
jar
.
add
(
obj
)
self
.
assertEqual
(
obj
.
_p_changed
,
0
)
...
...
@@ -184,7 +138,7 @@ class PersistenceTest(unittest.TestCase):
def
testSerial
(
self
):
noserial
=
"
\
000
"
*
8
obj
=
P
()
obj
=
self
.
_make_
P
()
self
.
assertEqual
(
obj
.
_p_serial
,
noserial
)
def
set
(
val
):
...
...
@@ -199,7 +153,9 @@ class PersistenceTest(unittest.TestCase):
self
.
assertEqual
(
obj
.
_p_serial
,
noserial
)
def
testMTime
(
self
):
obj
=
P
()
import
time
from
persistent.TimeStamp
import
TimeStamp
obj
=
self
.
_make_P
()
self
.
assertEqual
(
obj
.
_p_mtime
,
None
)
t
=
int
(
time
.
time
())
...
...
@@ -209,13 +165,32 @@ class PersistenceTest(unittest.TestCase):
self
.
assert_
(
isinstance
(
obj
.
_p_mtime
,
float
))
def
testPicklable
(
self
):
obj
=
P
()
import
pickle
from
persistent
import
Persistent
global
Picklable
class
Picklable
(
Persistent
):
pass
obj
=
Picklable
()
obj
.
attr
=
"test"
s
=
pickle
.
dumps
(
obj
)
obj2
=
pickle
.
loads
(
s
)
self
.
assertEqual
(
obj
.
attr
,
obj2
.
attr
)
def
testGetattr
(
self
):
from
persistent
import
CHANGED
from
persistent
import
Persistent
class
H1
(
Persistent
):
def
__init__
(
self
):
self
.
n
=
0
def
__getattr__
(
self
,
attr
):
self
.
n
+=
1
return
self
.
n
obj
=
H1
()
self
.
assertEqual
(
obj
.
larry
,
1
)
self
.
assertEqual
(
obj
.
curly
,
2
)
...
...
@@ -234,6 +209,23 @@ class PersistenceTest(unittest.TestCase):
self
.
assertEqual
(
obj
.
moe
,
3
)
def
testGetattribute
(
self
):
from
persistent
import
CHANGED
from
persistent
import
Persistent
class
H2
(
Persistent
):
def
__init__
(
self
):
self
.
n
=
0
def
__getattribute__
(
self
,
attr
):
supergetattr
=
super
(
H2
,
self
).
__getattribute__
try
:
return
supergetattr
(
attr
)
except
AttributeError
:
n
=
supergetattr
(
"n"
)
self
.
n
=
n
+
1
return
n
+
1
obj
=
H2
()
self
.
assertEqual
(
obj
.
larry
,
1
)
self
.
assertEqual
(
obj
.
curly
,
2
)
...
...
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