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
Hide 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
...
@@ -216,6 +216,7 @@ DB = Zope2.DB
configure
=
Zope2
.
configure
configure
=
Zope2
.
configure
def
startup
():
pass
def
startup
():
pass
Zope
=
Zope2
Zope
=
Zope2
active
=
_patched
# ZODB sandbox factory
# ZODB sandbox factory
from
ZODB.DemoStorage
import
DemoStorage
from
ZODB.DemoStorage
import
DemoStorage
...
...
lib/python/Testing/ZopeTestCase/zopedoctest/testPackageAsProduct.py
View file @
f29ef98d
...
@@ -20,9 +20,12 @@ if __name__ == '__main__':
...
@@ -20,9 +20,12 @@ if __name__ == '__main__':
execfile
(
os
.
path
.
join
(
sys
.
path
[
0
],
'framework.py'
))
execfile
(
os
.
path
.
join
(
sys
.
path
[
0
],
'framework.py'
))
from
unittest
import
TestSuite
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
Products.Five
import
zcml
from
zope.testing
import
cleanup
from
zope.testing
import
cleanup
import
Products
def
testInstallPackage
():
def
testInstallPackage
():
...
@@ -31,15 +34,12 @@ def testInstallPackage():
...
@@ -31,15 +34,12 @@ def testInstallPackage():
>>> from Testing import ZopeTestCase
>>> from Testing import ZopeTestCase
>>> from Products.Five import zcml
>>> 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
Register testpackage
>>> ZopeTestCase.hasPackage('testpackage')
False
>>> config = '''
>>> config = '''
... <configure
... <configure
... xmlns:five="http://namespaces.zope.org/five">
... xmlns:five="http://namespaces.zope.org/five">
...
@@ -48,19 +48,18 @@ def testInstallPackage():
...
@@ -48,19 +48,18 @@ def testInstallPackage():
... initialize="testpackage.initialize"
... initialize="testpackage.initialize"
... />
... />
... </configure>'''
... </configure>'''
>>> ZopeTestCase.hasPackage('testpackage')
False
>>> zcml.load_string(config)
>>> zcml.load_string(config)
The package is registered now
>>> ZopeTestCase.hasPackage('testpackage')
>>> ZopeTestCase.hasPackage('testpackage')
True
True
N
ot yet installed
But n
ot yet installed
>>> app =
ZopeTestCase.
app()
>>> app =
self._
app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
False
False
>>> ZopeTestCase.close(app)
Install it
Install it
...
@@ -69,39 +68,54 @@ def testInstallPackage():
...
@@ -69,39 +68,54 @@ def testInstallPackage():
Now it shows up in Control_Panel
Now it shows up in Control_Panel
>>> app =
ZopeTestCase.
app()
>>> app =
self._
app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
>>> 'testpackage' in app.Control_Panel.Products.objectIds()
True
True
>>> ZopeTestCase.close(app)
hasPackage still returns True
hasPackage still returns True
>>> ZopeTestCase.hasPackage('testpackage')
>>> ZopeTestCase.hasPackage('testpackage')
True
True
Clean up
A package is only installed once, subsequent calls to installPackage
are ignored:
>>> import testpackage
>>> ZopeTestCase.installPackage('testpackage', quiet=True)
>>> Products._registered_packages.remove(testpackage)
>>> sys.path[:] = saved
"""
"""
def
setUp
(
self
):
class
TestClass
(
ZopeTestCase
.
FunctionalTestCase
):
cleanup
.
cleanUp
()
zcml
.
_initialized
=
False
def
afterSetUp
(
self
):
zcml
.
load_site
()
cleanup
.
cleanUp
()
zcml
.
_initialized
=
False
zcml
.
load_site
()
self
.
saved
=
sys
.
path
[:]
sys
.
path
.
append
(
ZopeTestCase
.
__path__
[
0
])
def
afterClear
(
self
):
cleanup
.
cleanUp
()
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'
]
def
tearDown
(
self
):
to_initialize
=
getattr
(
Products
,
'_packages_to_initialize'
,
None
)
cleanup
.
cleanUp
()
if
to_initialize
is
not
None
:
zcml
.
_initialized
=
False
Products
.
_packages_to_initialize
=
[(
m
,
f
)
for
(
m
,
f
)
in
to_initialize
if
m
.
__name__
!=
'testpackage'
]
def
test_suite
():
def
test_suite
():
return
TestSuite
((
if
ZopeLite
.
active
:
# Must use functional because installPackage commits
return
TestSuite
((
FunctionalDocTestSuite
(
setUp
=
setUp
,
tearDown
=
tearDown
),
ZopeDocTestSuite
(
test_class
=
TestClass
),
))
))
else
:
return
TestSuite
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
framework
()
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