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
56b2f844
Commit
56b2f844
authored
Apr 05, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish coverage for App.Extensions.getObject.
parent
cb2ecaca
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
6 deletions
+96
-6
src/App/tests/test_Extensions.py
src/App/tests/test_Extensions.py
+96
-6
No files found.
src/App/tests/test_Extensions.py
View file @
56b2f844
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
"""
"""
import
unittest
import
unittest
class
FuncCodeTests
(
unittest
.
TestCase
):
class
FuncCodeTests
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
def
_getTargetClass
(
self
):
...
@@ -81,7 +82,8 @@ class FuncCodeTests(unittest.TestCase):
...
@@ -81,7 +82,8 @@ class FuncCodeTests(unittest.TestCase):
fc2
=
self
.
_makeOne
(
g
,
im
=
1
)
fc2
=
self
.
_makeOne
(
g
,
im
=
1
)
self
.
failUnless
(
cmp
(
fc
,
fc2
)
<
0
)
self
.
failUnless
(
cmp
(
fc
,
fc2
)
<
0
)
class
Test_getPath
(
unittest
.
TestCase
):
class
_TempdirBase
:
_old_Products___path__
=
None
_old_Products___path__
=
None
_tmpdirs
=
()
_tmpdirs
=
()
...
@@ -102,10 +104,6 @@ class Test_getPath(unittest.TestCase):
...
@@ -102,10 +104,6 @@ class Test_getPath(unittest.TestCase):
if
getattr
(
v
,
'__file__'
,
''
).
startswith
(
self
.
_added_path
):
if
getattr
(
v
,
'__file__'
,
''
).
startswith
(
self
.
_added_path
):
del
sys
.
modules
[
k
]
del
sys
.
modules
[
k
]
def
_callFUT
(
self
,
prefix
,
name
,
checkProduct
=
1
,
suffixes
=
(
''
,),
cfg
=
None
):
from
App.Extensions
import
getPath
return
getPath
(
prefix
,
name
,
checkProduct
,
suffixes
,
cfg
)
def
_makeTempdir
(
self
):
def
_makeTempdir
(
self
):
import
tempfile
import
tempfile
tmp
=
tempfile
.
mkdtemp
()
tmp
=
tempfile
.
mkdtemp
()
...
@@ -147,6 +145,13 @@ class Test_getPath(unittest.TestCase):
...
@@ -147,6 +145,13 @@ class Test_getPath(unittest.TestCase):
f
.
close
()
f
.
close
()
return
fqn
return
fqn
class
Test_getPath
(
_TempdirBase
,
unittest
.
TestCase
):
def
_callFUT
(
self
,
prefix
,
name
,
checkProduct
=
1
,
suffixes
=
(
''
,),
cfg
=
None
):
from
App.Extensions
import
getPath
return
getPath
(
prefix
,
name
,
checkProduct
,
suffixes
,
cfg
)
def
_makeConfig
(
self
,
**
kw
):
def
_makeConfig
(
self
,
**
kw
):
class
DummyConfig
:
class
DummyConfig
:
def
__init__
(
self
,
**
kw
):
def
__init__
(
self
,
**
kw
):
...
@@ -253,8 +258,93 @@ class Test_getPath(unittest.TestCase):
...
@@ -253,8 +258,93 @@ class Test_getPath(unittest.TestCase):
suffixes
=
(
'py'
,),
cfg
=
cfg
)
suffixes
=
(
'py'
,),
cfg
=
cfg
)
self
.
assertEqual
(
path
,
subpkgfqn
)
self
.
assertEqual
(
path
,
subpkgfqn
)
class
Test_getObject
(
_TempdirBase
,
unittest
.
TestCase
):
def
_callFUT
(
self
,
module
,
name
,
reload
=
0
,
modules
=
None
):
from
App.Extensions
import
getObject
if
modules
is
not
None
:
return
getObject
(
module
,
name
,
reload
,
modules
)
return
getObject
(
module
,
name
,
reload
)
def
test_cache_miss
(
self
):
from
zExceptions
import
NotFound
MODULES
=
{
'somemodule'
:
{}}
self
.
assertRaises
(
NotFound
,
self
.
_callFUT
,
'somemodule'
,
'name'
,
modules
=
MODULES
)
def
test_cache_hit
(
self
):
obj
=
object
()
MODULES
=
{
'somemodule'
:
{
'name'
:
obj
}}
found
=
self
.
_callFUT
(
'somemodule'
,
'name'
,
modules
=
MODULES
)
self
.
failUnless
(
found
is
obj
)
def
test_no_such_module
(
self
):
from
zExceptions
import
NotFound
MODULES
=
{}
self
.
assertRaises
(
NotFound
,
self
.
_callFUT
,
'nonesuch'
,
'name'
,
modules
=
MODULES
)
self
.
failIf
(
'nonesuch'
in
MODULES
)
def
test_not_found_in_module
(
self
):
from
zExceptions
import
NotFound
MODULES
=
{}
extdir
=
self
.
_makeTempProduct
()
ext
=
self
.
_makeFile
(
extdir
,
'extension.py'
)
self
.
assertRaises
(
NotFound
,
self
.
_callFUT
,
'foo.extension'
,
'name'
,
modules
=
MODULES
)
self
.
failUnless
(
'foo.extension'
in
MODULES
)
self
.
failIf
(
'named'
in
MODULES
[
'foo.extension'
])
def
test_found_in_module
(
self
):
MODULES
=
{}
extdir
=
self
.
_makeTempProduct
()
ext
=
self
.
_makeFile
(
extdir
,
'extension.py'
,
EXTENSION_PY
)
found
=
self
.
_callFUT
(
'foo.extension'
,
'named'
,
modules
=
MODULES
)
self
.
assertEqual
(
found
,
'NAMED'
)
self
.
failUnless
(
'foo.extension'
in
MODULES
)
self
.
assertEqual
(
MODULES
[
'foo.extension'
][
'named'
],
'NAMED'
)
def
test_found_in_module_pyc
(
self
):
from
compileall
import
compile_dir
import
os
MODULES
=
{}
extdir
=
self
.
_makeTempProduct
()
ext
=
self
.
_makeFile
(
extdir
,
'extension.py'
,
EXTENSION_PY
)
compile_dir
(
extdir
)
os
.
remove
(
ext
)
found
=
self
.
_callFUT
(
'foo.extension'
,
'named'
,
modules
=
MODULES
)
self
.
assertEqual
(
found
,
'NAMED'
)
self
.
failUnless
(
'foo.extension'
in
MODULES
)
self
.
assertEqual
(
MODULES
[
'foo.extension'
][
'named'
],
'NAMED'
)
def
test_found_in_module_after_cache_miss
(
self
):
cached
=
{}
MODULES
=
{
'foo.extension'
:
cached
}
extdir
=
self
.
_makeTempProduct
()
ext
=
self
.
_makeFile
(
extdir
,
'extension.py'
,
EXTENSION_PY
)
found
=
self
.
_callFUT
(
'foo.extension'
,
'named'
,
modules
=
MODULES
)
self
.
assertEqual
(
found
,
'NAMED'
)
self
.
assertEqual
(
cached
[
'named'
],
'NAMED'
)
def
test_found_in_module_after_cache_hit_but_reload
(
self
):
cached
=
{
'named'
:
'BEFORE'
}
MODULES
=
{
'foo.extension'
:
cached
}
extdir
=
self
.
_makeTempProduct
()
ext
=
self
.
_makeFile
(
extdir
,
'extension.py'
,
EXTENSION_PY
)
found
=
self
.
_callFUT
(
'foo.extension'
,
'named'
,
reload
=
1
,
modules
=
MODULES
)
self
.
assertEqual
(
found
,
'NAMED'
)
self
.
assertEqual
(
cached
[
'named'
],
'NAMED'
)
EXTENSION_PY
=
"""
\
named = 'NAMED'
"""
def
test_suite
():
def
test_suite
():
return
unittest
.
TestSuite
((
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
FuncCodeTests
),
unittest
.
makeSuite
(
FuncCodeTests
),
unittest
.
makeSuite
(
Test_getPath
),
unittest
.
makeSuite
(
Test_getPath
),
unittest
.
makeSuite
(
Test_getObject
),
))
))
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