Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
persistent
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
persistent
Commits
122d7098
Commit
122d7098
authored
Feb 18, 2011
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zap the 'new' state.
parent
8f3ce99a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
108 deletions
+16
-108
persistent/pyPersistence.py
persistent/pyPersistence.py
+2
-4
persistent/tests/test_pyPersistence.py
persistent/tests/test_pyPersistence.py
+14
-104
No files found.
persistent/pyPersistence.py
View file @
122d7098
...
...
@@ -216,13 +216,11 @@ class Persistent(object):
# The '_p_status' property is not (yet) part of the API: for now,
# it exists to simplify debugging and testing assertions.
def
_get_status
(
self
):
if
self
.
__jar
is
None
:
return
'unsaved'
if
self
.
__flags
is
None
:
if
self
.
__jar
is
None
:
return
'new'
return
'ghost'
if
self
.
__flags
&
_CHANGED
:
if
self
.
__jar
is
None
:
return
'unsaved'
result
=
'changed'
else
:
result
=
'saved'
...
...
persistent/tests/test_pyPersistence.py
View file @
122d7098
...
...
@@ -75,6 +75,7 @@ class PersistentTests(unittest.TestCase):
self
.
assertEqual
(
inst
.
_p_serial
,
_INITIAL_SERIAL
)
self
.
assertEqual
(
inst
.
_p_changed
,
None
)
self
.
assertEqual
(
inst
.
_p_sticky
,
False
)
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test_assign_p_jar_w_invalid_jar
(
self
):
inst
=
self
.
_makeOne
()
...
...
@@ -195,39 +196,20 @@ class PersistentTests(unittest.TestCase):
inst
.
_p_changed
=
False
self
.
assertEqual
(
inst
.
_p_changed
,
False
)
def
test_assign_p_changed_none_from_new
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
None
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
def
test_assign_p_changed_true_from_new
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test_assign_p_changed_false_from_new
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
False
# activates
self
.
assertEqual
(
inst
.
_p_status
,
'saved'
)
def
test_assign_p_changed_none_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
inst
.
_p_changed
=
None
# can't transition 'unsaved' -> 'new'
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test_assign_p_changed_true_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
inst
.
_p_changed
=
True
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test_assign_p_changed_false_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
inst
.
_p_changed
=
False
self
.
assertEqual
(
inst
.
_p_status
,
'saved'
)
self
.
assertEqual
(
inst
.
_p_status
,
'
un
saved'
)
def
test_assign_p_changed_none_from_ghost
(
self
):
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
...
...
@@ -318,16 +300,10 @@ class PersistentTests(unittest.TestCase):
inst
.
_p_changed
=
None
self
.
assertRaises
(
ValueError
,
_test
)
def
test_delete_p_changed_from_new
(
self
):
inst
=
self
.
_makeOne
()
del
inst
.
_p_changed
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
def
test_delete_p_changed_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
del
inst
.
_p_changed
self
.
assertEqual
(
inst
.
_p_status
,
'
new
'
)
self
.
assertEqual
(
inst
.
_p_status
,
'
unsaved
'
)
def
test_delete_p_changed_from_ghost
(
self
):
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
...
...
@@ -389,13 +365,8 @@ class PersistentTests(unittest.TestCase):
inst
.
_p_sticky
=
False
self
.
failIf
(
inst
.
_p_sticky
)
def
test__p_status_new
(
self
):
inst
=
self
.
_makeOne
()
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
def
test__p_status_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test__p_status_ghost
(
self
):
...
...
@@ -510,17 +481,10 @@ class PersistentTests(unittest.TestCase):
getattr
(
inst
,
name
,
None
)
self
.
assertEqual
(
jar
.
_cache
.
_mru
,
[])
def
test___getattribute__normal_name_from_new
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'value'
inst
=
Derived
()
self
.
assertEqual
(
getattr
(
inst
,
'normal'
,
None
),
'value'
)
def
test___getattribute__normal_name_from_unsaved
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'value'
inst
=
Derived
()
inst
.
_p_changed
=
True
self
.
assertEqual
(
getattr
(
inst
,
'normal'
,
None
),
'value'
)
def
test___getattribute__normal_name_from_ghost
(
self
):
...
...
@@ -565,18 +529,10 @@ class PersistentTests(unittest.TestCase):
setattr
(
inst
,
name
,
value
)
self
.
assertEqual
(
jar
.
_cache
.
_mru
,
[])
def
test___setattr__normal_name_from_new
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'before'
inst
=
Derived
()
setattr
(
inst
,
'normal'
,
'after'
)
self
.
assertEqual
(
getattr
(
inst
,
'normal'
,
None
),
'after'
)
def
test___setattr__normal_name_from_unsaved
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'before'
inst
=
Derived
()
inst
.
_p_changed
=
True
setattr
(
inst
,
'normal'
,
'after'
)
self
.
assertEqual
(
getattr
(
inst
,
'normal'
,
None
),
'after'
)
...
...
@@ -625,22 +581,12 @@ class PersistentTests(unittest.TestCase):
self
.
assertEqual
(
jar
.
_cache
.
_mru
,
[])
self
.
assertEqual
(
jar
.
_registered
,
[])
def
test___delattr__normal_name_from_new
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'before'
def
__init__
(
self
):
self
.
__dict__
[
'normal'
]
=
'after'
inst
=
Derived
()
delattr
(
inst
,
'normal'
)
self
.
assertEqual
(
getattr
(
inst
,
'normal'
,
None
),
'before'
)
def
test___delattr__normal_name_from_unsaved
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'before'
def
__init__
(
self
):
self
.
__dict__
[
'normal'
]
=
'after'
inst
=
Derived
()
inst
.
_p_changed
=
True
delattr
(
inst
,
'normal'
)
self
.
assertEqual
(
getattr
(
inst
,
'normal'
,
None
),
'before'
)
...
...
@@ -752,43 +698,25 @@ class PersistentTests(unittest.TestCase):
self
.
assertEqual
(
second
,
(
Derived
,
'a'
,
'b'
))
self
.
assertEqual
(
third
,
{
'foo'
:
'bar'
})
def
test__p_activate_from_
new
(
self
):
def
test__p_activate_from_
unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_activate
()
inst
.
_p_activate
()
# noop w/o jar
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test__p_activate_from_ghost
(
self
):
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
inst
.
_p_activate
()
self
.
assertEqual
(
inst
.
_p_status
,
'saved'
)
def
test__p_activate_from_saved
(
self
):
inst
=
self
.
_makeOne
()
inst
,
jar
,
OID
=
self
.
_makeOneWithJar
()
inst
.
_p_changed
=
False
inst
.
_p_activate
()
# noop from 'unsaved' state
self
.
assertEqual
(
inst
.
_p_status
,
'saved'
)
def
test__p_activate_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
inst
.
_p_activate
()
# noop from 'saved' state
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test__p_deactivate_from_new
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_deactivate
()
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
def
test__p_deactivate_from_new_w_dict
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'before'
def
__init__
(
self
):
self
.
__dict__
[
'normal'
]
=
'after'
inst
=
Derived
()
inst
.
_p_deactivate
()
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
self
.
assertEqual
(
inst
.
__dict__
,
{
'normal'
:
'after'
})
self
.
assertEqual
(
inst
.
_p_status
,
'saved'
)
def
test__p_deactivate_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
inst
.
_p_deactivate
()
# can't transition 'unsaved' -> 'new'
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
def
test__p_deactivate_from_unsaved_w_dict
(
self
):
...
...
@@ -799,7 +727,6 @@ class PersistentTests(unittest.TestCase):
inst
=
Derived
()
inst
.
_p_changed
=
True
inst
.
_p_deactivate
()
# can't transition 'unsaved' -> 'new'
self
.
assertEqual
(
inst
.
_p_status
,
'unsaved'
)
self
.
assertEqual
(
inst
.
__dict__
,
{
'normal'
:
'after'
})
...
...
@@ -865,26 +792,10 @@ class PersistentTests(unittest.TestCase):
inst
.
_p_sticky
=
True
self
.
assertRaises
(
ValueError
,
inst
.
_p_deactivate
)
def
test__p_invalidate_from_new
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_invalidate
()
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
def
test__p_invalidate_from_new_w_dict
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
normal
=
'before'
def
__init__
(
self
):
self
.
__dict__
[
'normal'
]
=
'after'
inst
=
Derived
()
inst
.
_p_invalidate
()
self
.
assertEqual
(
inst
.
_p_status
,
'new'
)
self
.
assertEqual
(
inst
.
__dict__
,
{})
def
test__p_invalidate_from_unsaved
(
self
):
inst
=
self
.
_makeOne
()
inst
.
_p_changed
=
True
inst
.
_p_invalidate
()
self
.
assertEqual
(
inst
.
_p_status
,
'
new
'
)
self
.
assertEqual
(
inst
.
_p_status
,
'
unsaved
'
)
def
test__p_invalidate_from_unsaved_w_dict
(
self
):
class
Derived
(
self
.
_getTargetClass
()):
...
...
@@ -892,9 +803,8 @@ class PersistentTests(unittest.TestCase):
def
__init__
(
self
):
self
.
__dict__
[
'normal'
]
=
'after'
inst
=
Derived
()
inst
.
_p_changed
=
True
inst
.
_p_invalidate
()
self
.
assertEqual
(
inst
.
_p_status
,
'
new
'
)
self
.
assertEqual
(
inst
.
_p_status
,
'
unsaved
'
)
self
.
assertEqual
(
inst
.
__dict__
,
{})
def
test__p_invalidate_from_ghost
(
self
):
...
...
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