Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Zope
Commits
6a406941
Commit
6a406941
authored
Jul 31, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace and remove some code fossils
parent
53e652e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
41 deletions
+30
-41
src/Products/ZCatalog/tests/testBrains.py
src/Products/ZCatalog/tests/testBrains.py
+25
-29
src/Products/ZCatalog/tests/testCatalog.py
src/Products/ZCatalog/tests/testCatalog.py
+1
-4
src/Products/ZCatalog/tests/testLazySequences.py
src/Products/ZCatalog/tests/testLazySequences.py
+4
-8
No files found.
src/Products/ZCatalog/tests/testBrains.py
View file @
6a406941
...
...
@@ -11,8 +11,7 @@
#
##############################################################################
"""Unittests for Catalog brains
$Id$"""
"""
import
unittest
import
Acquisition
...
...
@@ -35,20 +34,20 @@ class Conflicter(Happy):
"""Object that raises ConflictError when accessed"""
def
check
(
self
):
raise
ConflictError
class
DummyRequest
(
Acquisition
.
Implicit
):
def
physicalPathToURL
(
self
,
path
,
relative
=
False
):
if
not
relative
:
path
=
'http://superbad.com'
+
path
return
path
_marker
=
object
()
class
DummyCatalog
(
Acquisition
.
Implicit
):
_objs
=
{
'/happy'
:
Happy
(
'happy'
),
'/secret'
:
Secret
(
'secret'
),
_objs
=
{
'/happy'
:
Happy
(
'happy'
),
'/secret'
:
Secret
(
'secret'
),
'/conflicter'
:
Conflicter
(
'conflicter'
)}
_paths
=
_objs
.
keys
()
+
[
'/zonked'
]
_paths
.
sort
()
...
...
@@ -71,26 +70,26 @@ class DummyCatalog(Acquisition.Implicit):
if
default
is
not
_marker
:
return
default
raise
def
getpath
(
self
,
rid
):
return
self
.
_paths
[
rid
]
def
getobject
(
self
,
rid
):
return
self
.
restrictedTraverse
(
self
.
_paths
[
rid
])
def
resolve_url
(
self
,
path
,
REQUEST
):
path
=
path
[
path
.
find
(
'/'
,
path
.
find
(
'//'
)
+
1
):]
# strip server part
return
self
.
restrictedTraverse
(
path
)
class
ConflictingCatalog
(
DummyCatalog
):
def
getpath
(
self
,
rid
):
raise
ConflictError
class
BrainsTestBase
:
_old_flag
=
None
def
setUp
(
self
):
self
.
cat
=
DummyCatalog
()
self
.
cat
.
REQUEST
=
DummyRequest
()
...
...
@@ -108,7 +107,7 @@ class BrainsTestBase:
def
_restore_getOb_flag
(
self
):
from
Products.ZCatalog
import
CatalogBrains
CatalogBrains
.
GETOBJECT_RAISES
=
self
.
_old_flag
def
_makeBrain
(
self
,
rid
):
from
Products.ZCatalog.CatalogBrains
import
AbstractCatalogBrain
class
Brain
(
AbstractCatalogBrain
):
...
...
@@ -120,38 +119,38 @@ class BrainsTestBase:
self
.
failUnless
(
b
.
has_key
(
'test_field'
))
self
.
failUnless
(
b
.
has_key
(
'data_record_id_'
))
self
.
failIf
(
b
.
has_key
(
'godel'
))
def
testGetPath
(
self
):
b
=
[
self
.
_makeBrain
(
rid
)
for
rid
in
range
(
3
)]
self
.
assertEqual
(
b
[
0
].
getPath
(),
'/conflicter'
)
self
.
assertEqual
(
b
[
1
].
getPath
(),
'/happy'
)
self
.
assertEqual
(
b
[
2
].
getPath
(),
'/secret'
)
def
testGetPathPropagatesConflictErrors
(
self
):
self
.
cat
=
ConflictingCatalog
()
b
=
self
.
_makeBrain
(
0
)
self
.
assertRaises
(
ConflictError
,
b
.
getPath
)
def
testGetURL
(
self
):
b
=
self
.
_makeBrain
(
0
)
self
.
assertEqual
(
b
.
getURL
(),
'http://superbad.com/conflicter'
)
def
testGetRID
(
self
):
b
=
self
.
_makeBrain
(
42
)
self
.
assertEqual
(
b
.
getRID
(),
42
)
def
testGetObjectHappy
(
self
):
b
=
self
.
_makeBrain
(
1
)
self
.
assertEqual
(
b
.
getPath
(),
'/happy'
)
self
.
failUnless
(
b
.
getObject
().
aq_base
is
self
.
cat
.
getobject
(
1
).
aq_base
)
def
testGetObjectPropagatesConflictErrors
(
self
):
b
=
self
.
_makeBrain
(
0
)
self
.
assertEqual
(
b
.
getPath
(),
'/conflicter'
)
self
.
assertRaises
(
ConflictError
,
b
.
getObject
)
class
TestBrains
(
BrainsTestBase
,
unittest
.
TestCase
):
def
_flag_value
(
self
):
return
True
...
...
@@ -160,16 +159,16 @@ class TestBrains(BrainsTestBase, unittest.TestCase):
b
=
self
.
_makeBrain
(
2
)
self
.
assertEqual
(
b
.
getPath
(),
'/secret'
)
self
.
assertRaises
(
Unauthorized
,
b
.
getObject
)
def
testGetObjectRaisesNotFoundForMissing
(
self
):
from
zExceptions
import
NotFound
b
=
self
.
_makeBrain
(
3
)
self
.
assertEqual
(
b
.
getPath
(),
'/zonked'
)
self
.
assertRaises
(
KeyError
,
self
.
cat
.
getobject
,
3
)
self
.
assertRaises
((
NotFound
,
AttributeError
,
KeyError
),
b
.
getObject
)
class
TestBrainsOldBehavior
(
BrainsTestBase
,
unittest
.
TestCase
):
def
_flag_value
(
self
):
return
False
...
...
@@ -177,18 +176,15 @@ class TestBrainsOldBehavior(BrainsTestBase, unittest.TestCase):
b
=
self
.
_makeBrain
(
2
)
self
.
assertEqual
(
b
.
getPath
(),
'/secret'
)
self
.
assertEqual
(
b
.
getObject
(),
None
)
def
testGetObjectReturnsNoneForMissing
(
self
):
b
=
self
.
_makeBrain
(
3
)
self
.
assertEqual
(
b
.
getPath
(),
'/zonked'
)
self
.
assertRaises
(
KeyError
,
self
.
cat
.
getobject
,
3
)
self
.
assertEqual
(
b
.
getObject
(),
None
)
self
.
assertEqual
(
b
.
getObject
(),
None
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestBrains
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestBrainsOldBehavior
))
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
src/Products/ZCatalog/tests/testCatalog.py
View file @
6a406941
...
...
@@ -259,7 +259,7 @@ class TestZCatalog(unittest.TestCase):
self
.
_catalog
.
reindexIndex
(
'title'
,
{})
data
=
self
.
_catalog
.
getMetadataForUID
(
'0'
)
self
.
assertEqual
(
data
[
'title'
],
'0'
)
def
testReindexIndexesFalse
(
self
):
# setup
false_id
=
self
.
upper
+
1
...
...
@@ -873,6 +873,3 @@ def test_suite():
suite
.
addTest
(
unittest
.
makeSuite
(
TestMerge
)
)
suite
.
addTest
(
unittest
.
makeSuite
(
TestZCatalogGetObject
)
)
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
src/Products/ZCatalog/tests/testLazySequences.py
View file @
6a406941
...
...
@@ -11,8 +11,7 @@
#
##############################################################################
"""Unittests for Lazy sequence classes
$Id$"""
"""
import
unittest
...
...
@@ -60,7 +59,7 @@ class TestLazyCat(BaseSequenceTest):
seq3
=
list
(
letters
)
lcat
=
apply
(
self
.
_createLSeq
,
[
self
.
_createLSeq
(
seq
)
for
seq
in
(
seq1
,
seq2
,
seq3
)])
self
.
_compare
(
lcat
[
5
:
-
5
],
seq1
[
5
:]
+
seq2
+
seq3
[:
-
5
])
self
.
_compare
(
lcat
[
5
:
-
5
],
seq1
[
5
:]
+
seq2
+
seq3
[:
-
5
])
def
testConsistentLength
(
self
):
# Unaccessed length
...
...
@@ -102,7 +101,7 @@ class TestLazyMap(TestLazyCat):
class
TestLazyFilter
(
TestLazyCat
):
def
_createLSeq
(
self
,
*
seq
):
return
self
.
_createLFilter
(
lambda
x
:
True
,
*
seq
)
def
_createLFilter
(
self
,
filter
,
*
seq
):
from
Products.ZCatalog.Lazy
import
LazyFilter
totalseq
=
[]
...
...
@@ -162,7 +161,7 @@ class TestLazyMop(TestLazyCat):
def
testConsistentLengthWithMop
(
self
):
from
string
import
letters
seq
=
range
(
10
)
+
list
(
letters
)
def
filter
(
x
):
if
isinstance
(
x
,
int
):
...
...
@@ -214,6 +213,3 @@ def test_suite():
suite
.
addTest
(
unittest
.
makeSuite
(
TestLazyMop
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestLazyValues
))
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'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