Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Weblate
gajim
Commits
3d559033
Commit
3d559033
authored
15 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
fix Mock class: child of object class and fix realClass usage
parent
a0d0a9b5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/lib/mock.py
+7
-5
7 additions, 5 deletions
test/lib/mock.py
with
7 additions
and
5 deletions
test/lib/mock.py
+
7
−
5
View file @
3d559033
...
...
@@ -11,6 +11,7 @@
#
#
# Copyright (c) 2005, Dave Kirby
# Copyright (c) 2009, Yann Leboulanger
#
# All rights reserved.
#
...
...
@@ -60,7 +61,7 @@ import re
class
MockInterfaceError
(
Exception
):
pass
class
Mock
:
class
Mock
(
object
)
:
"""
The Mock class emulates any other class for testing purposes.
All method calls are stored for later examination.
...
...
@@ -83,6 +84,7 @@ class Mock:
self
.
mockAllCalledMethods
=
[]
self
.
mockReturnValues
=
returnValues
or
{}
self
.
mockExpectations
=
{}
self
.
realClass
=
realClass
self
.
realClassMethods
=
None
if
realClass
:
self
.
realClassMethods
=
dict
(
inspect
.
getmembers
(
realClass
,
inspect
.
isroutine
))
...
...
@@ -92,7 +94,7 @@ class Mock:
self
.
_setupSubclassMethodInterceptors
()
def
_setupSubclassMethodInterceptors
(
self
):
methods
=
inspect
.
getmembers
(
self
.
__c
lass
__
,
inspect
.
isroutine
)
methods
=
inspect
.
getmembers
(
self
.
realC
lass
,
inspect
.
isroutine
)
baseMethods
=
dict
(
inspect
.
getmembers
(
Mock
,
inspect
.
ismethod
))
for
m
in
methods
:
name
=
m
[
0
]
...
...
@@ -119,7 +121,7 @@ class Mock:
if
self
.
realClassMethods
is
None
:
return
if
name
not
in
self
.
realClassMethods
:
r
aise
MockInterfaceError
(
"
Calling mock method
'
%s
'
that was not found in the original class
"
%
name
)
r
eturn
func
=
self
.
realClassMethods
[
name
]
try
:
...
...
@@ -268,7 +270,7 @@ class MockCallable:
def
makeCall
(
self
,
params
,
kwparams
):
if
self
.
handcrafted
:
allPosParams
=
(
self
.
mock
,)
+
params
func
=
_findFunc
(
self
.
mock
.
__c
lass
__
,
self
.
name
)
func
=
_findFunc
(
self
.
mock
.
realC
lass
,
self
.
name
)
if
not
func
:
raise
NotImplementedError
return
func
(
*
allPosParams
,
**
kwparams
)
...
...
@@ -463,4 +465,4 @@ CALLABLE = callable
# vim: se ts=3:
\ No newline at end of file
# vim: se ts=3:
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