Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
a286b938
Commit
a286b938
authored
9 years ago
by
Raphael Collet
Browse files
Options
Downloads
Patches
Plain Diff
[ADD] ormcache: add a unit test
parent
ede43047
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
openerp/addons/base/tests/__init__.py
+1
-0
1 addition, 0 deletions
openerp/addons/base/tests/__init__.py
openerp/addons/base/tests/test_ormcache.py
+36
-0
36 additions, 0 deletions
openerp/addons/base/tests/test_ormcache.py
openerp/tools/cache.py
+9
-0
9 additions, 0 deletions
openerp/tools/cache.py
with
46 additions
and
0 deletions
openerp/addons/base/tests/__init__.py
+
1
−
0
View file @
a286b938
...
...
@@ -14,6 +14,7 @@ import test_ir_values
import
test_mail
import
test_menu
import
test_orm
import
test_ormcache
import
test_osv
import
test_qweb
import
test_res_config
...
...
This diff is collapsed.
Click to expand it.
openerp/addons/base/tests/test_ormcache.py
0 → 100644
+
36
−
0
View file @
a286b938
from
openerp.tests
import
common
from
openerp.tools
import
get_cache_key_counter
class
TestOrmcache
(
common
.
TransactionCase
):
def
test_ormcache
(
self
):
"""
Test the effectiveness of the ormcache() decorator.
"""
IMD
=
self
.
env
[
'
ir.model.data
'
]
XMLID
=
'
base.group_no_one
'
# retrieve the cache, its key and stat counter
cache
,
key
,
counter
=
get_cache_key_counter
(
IMD
.
xmlid_lookup
,
self
.
cr
,
self
.
uid
,
XMLID
)
hit
=
counter
.
hit
miss
=
counter
.
miss
# clear the cache of ir.model.data.xmlid_lookup, retrieve its key and
IMD
.
xmlid_lookup
.
clear_cache
(
IMD
)
self
.
assertNotIn
(
key
,
cache
)
# lookup some reference
self
.
env
.
ref
(
XMLID
)
self
.
assertEqual
(
counter
.
hit
,
hit
)
self
.
assertEqual
(
counter
.
miss
,
miss
+
1
)
self
.
assertIn
(
key
,
cache
)
# lookup again
self
.
env
.
ref
(
XMLID
)
self
.
assertEqual
(
counter
.
hit
,
hit
+
1
)
self
.
assertEqual
(
counter
.
miss
,
miss
+
1
)
self
.
assertIn
(
key
,
cache
)
# lookup again
self
.
env
.
ref
(
XMLID
)
self
.
assertEqual
(
counter
.
hit
,
hit
+
2
)
self
.
assertEqual
(
counter
.
miss
,
miss
+
1
)
self
.
assertIn
(
key
,
cache
)
This diff is collapsed.
Click to expand it.
openerp/tools/cache.py
+
9
−
0
View file @
a286b938
...
...
@@ -234,5 +234,14 @@ def log_ormcache_stats(sig=None, frame=None):
me
.
dbname
=
me_dbname
def
get_cache_key_counter
(
bound_method
,
*
args
,
**
kwargs
):
"""
Return the cache, key and stat counter for the given call.
"""
model
=
bound_method
.
im_self
ormcache
=
bound_method
.
clear_cache
.
im_self
cache
,
key0
,
counter
=
ormcache
.
lru
(
model
)
key
=
key0
+
ormcache
.
key
(
model
,
*
args
,
**
kwargs
)
return
cache
,
key
,
counter
# For backward compatibility
cache
=
ormcache
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment