GithubHelp home page GithubHelp logo

Comments (4)

note35 avatar note35 commented on June 16, 2024

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.

  1. The relation: base <- spy <- stub

  2. args is a property function of spy, it uses a structure called args_list to store args of every calls.

  3. getCall is a classmethod of base, spy/stub can use getCall to get the call from a private variable _queue.

  4. __add_spy will wrap the target to add the args_list

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.

jonathan-benn avatar jonathan-benn commented on June 16, 2024

I'll take a look and see if I can help.

from sinon.

jonathan-benn avatar jonathan-benn commented on June 16, 2024

Hi Kir,

I see the following potential solution:

  1. Add a new property to Base called call_number that defaults to None
  2. In getCall, fill the property call_number with the inputted index n
  3. In args, use call_number to only return the correct item from the args_list. If call_number is None then args will return the whole args_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.

note35 avatar note35 commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.