Comments (4)
Hi, I am appreciated for your debug for this alpha stage library. I am not sure when will I be available to fix this. This will take time to change some current design. I can put some current design here first.
-
The relation: base <- spy <- stub
-
args is a property function of spy, it uses a structure called
args_list
to store args of every calls. -
getCall is a classmethod of base, spy/stub can use getCall to get the call from a private variable
_queue
.
From above, we know that _queue
is a base for all Spies/Stubs. Each Stub/Spy will have one args_list
.
Thus while you create the stub, it will in the _queue
, then while you call .args
, either for stub or stub.getCall(0) will return args_list. We need some way to that the return of getCall(0) know that it should filter other call's args.
If you have time, I am willing to receive PR from your contribution. I hope my code is easy to follow, feel free to ask me anything.
from sinon.
I'll take a look and see if I can help.
from sinon.
Hi Kir,
I see the following potential solution:
- Add a new property to Base called
call_number
that defaults toNone
- In
getCall
, fill the propertycall_number
with the inputted indexn
- In
args
, usecall_number
to only return the correct item from theargs_list
. Ifcall_number
isNone
thenargs
will return the wholeargs_list
.
It's a bit of a kludge... but it would (probably) work. Possibly, other properties/functions could benefit from call_number
as well
--Jonathan
from sinon.
Hi Jonathan,
The idea sounds achievable and good. Letting each inspector has its own call_number
is easy to know when it was called and judge the order of calls. And it amazingly won't impact original design.
Just note that while a base
call .restore()
, the _queue
will also remove itself. You can find the code here. And the getCall API will still use the old way to get other base
in _queue
.
I am appreciated for this solution! Hope you can finish this nice idea.
About the implementation, at first glance, for adding call_number
to base, you might only need to modify __new__
of class SinonBase
in base.py
, check the call_number
of newest base in the _queue
and assign that number+1 to the new base. (I might not consider completely in some parts. But anyway, if it can pass the testing, it shouldn't impact original features.)
Regards
from sinon.
Related Issues (20)
- Chained onCall and withArgs doesn't work HOT 4
- Immediately creating Stub replacement is deprecated HOT 4
- onCall(...).withArgs(...) not allowed HOT 1
- Combined withArgs and onCall not working correctly
- Conditions should not persist across lines
- Precedence of onCall vs withArgs vs returns not correct HOT 1
- call count reset when using returns or throws HOT 2
- FSM Table
- Code duplication
- Get rid of target "dirty hack" HOT 2
- Cannot chain throws HOT 4
- Class-based method stub cannot execute HOT 2
- Class-based method stub cannot chain throws
- Module-based stub cannot chain throws
- Should not be able to restore an anonymous (pure) stub HOT 3
- base.py exposes protected attributes
- Calling stub.reset() makes stub no longer override return value HOT 1
- Cannot stub logging with open stream HOT 1
- Nice-to-have: stubbing constructors
- Deprecation warning due to invalid escape sequences
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sinon.