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
f29ef98d
Commit
f29ef98d
authored
Jun 23, 2007
by
Stefan H. Holek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a test_class to gain better control over fixture cleanup.
parent
b36d4e11
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
30 deletions
+45
-30
lib/python/Testing/ZopeTestCase/ZopeLite.py
lib/python/Testing/ZopeTestCase/ZopeLite.py
+1
-0
lib/python/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
.../Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
+44
-30
No files found.
lib/python/Testing/ZopeTestCase/ZopeLite.py
View file @
f29ef98d
...
...
@@ -216,6 +216,7 @@ DB = Zope2.DB
configure
=
Zope2
.
configure
def
startup
():
pass
Zope
=
Zope2
active
=
_patched
# ZODB sandbox factory
from
ZODB.DemoStorage
import
DemoStorage
...
...
lib/python/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
View file @
f29ef98d
...
...
@@ -20,9 +20,12 @@ if __name__ == '__main__':
execfile
(
os
.
path
.
join
(
sys
.
path
[
0
],
'framework.py'
))
from
unittest
import
TestSuite
from
Testing.ZopeTestCase
import
FunctionalDocTestSuite
from
Testing
import
ZopeTestCase
from
Testing.ZopeTestCase
import
ZopeLite
from
Testing.ZopeTestCase
import
ZopeDocTestSuite
from
Products.Five
import
zcml
from
zope.testing
import
cleanup
import
Products
def
testInstallPackage
():
...
...
@@ -31,15 +34,12 @@ def testInstallPackage():
>>> from Testing import ZopeTestCase
>>> from Products.Five import zcml
>>> import sys, Products
Rig sys.path so testpackage can be imported
>>> saved = sys.path[:]
>>> sys.path.append(ZopeTestCase.__path__[0])
Register testpackage
>>> ZopeTestCase.hasPackage('testpackage')
False
>>> config = '''
... <configure
... xmlns:five="http://namespaces.zope.org/five">
...
...
@@ -48,19 +48,18 @@ def testInstallPackage():
... initialize="testpackage.initialize"
... />
... </configure>'''
>>> ZopeTestCase.hasPackage('testpackage')
False
>>> zcml.load_string(config)
The package is registered now
>>> ZopeTestCase.hasPackage('testpackage')
True
N
ot yet installed
But n
ot yet installed
>>> app =
ZopeTestCase.
app()
>>> app =
self._
app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
False
>>> ZopeTestCase.close(app)
Install it
...
...
@@ -69,39 +68,54 @@ def testInstallPackage():
Now it shows up in Control_Panel
>>> app =
ZopeTestCase.
app()
>>> app =
self._
app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
True
>>> ZopeTestCase.close(app)
hasPackage still returns True
>>> ZopeTestCase.hasPackage('testpackage')
True
Clean up
A package is only installed once, subsequent calls to installPackage
are ignored:
>>> import testpackage
>>> Products._registered_packages.remove(testpackage)
>>> sys.path[:] = saved
>>> ZopeTestCase.installPackage('testpackage', quiet=True)
"""
def
setUp
(
self
):
class
TestClass
(
ZopeTestCase
.
FunctionalTestCase
):
def
afterSetUp
(
self
):
cleanup
.
cleanUp
()
zcml
.
_initialized
=
False
zcml
.
load_site
()
def
tearDown
(
self
):
self
.
saved
=
sys
.
path
[:]
sys
.
path
.
append
(
ZopeTestCase
.
__path__
[
0
])
def
afterClear
(
self
):
cleanup
.
cleanUp
()
zcml
.
_initialized
=
False
sys
.
path
[:]
=
self
.
saved
registered
=
getattr
(
Products
,
'_registered_packages'
,
None
)
if
registered
is
not
None
:
Products
.
_registered_packages
=
[
m
for
m
in
registered
if
m
.
__name__
!=
'testpackage'
]
to_initialize
=
getattr
(
Products
,
'_packages_to_initialize'
,
None
)
if
to_initialize
is
not
None
:
Products
.
_packages_to_initialize
=
[(
m
,
f
)
for
(
m
,
f
)
in
to_initialize
if
m
.
__name__
!=
'testpackage'
]
def
test_suite
():
if
ZopeLite
.
active
:
return
TestSuite
((
# Must use functional because installPackage commits
FunctionalDocTestSuite
(
setUp
=
setUp
,
tearDown
=
tearDown
),
ZopeDocTestSuite
(
test_class
=
TestClass
),
))
else
:
return
TestSuite
()
if
__name__
==
'__main__'
:
framework
()
...
...
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