Comments (4)
The one I followed previously is not the newest version.
I have not checked other missing function precisely, but I am pretty sure the newest Sinon.js
changed and added lots APIs. Since I contributed part of new version's SinonJS document.
Feel free to list those new features you think can benefit this library, I am willing to extend current library :)
from sinon.
- spyCall.calledOn # Returns true if obj was this for this call.
During the time I implement Sinon.py, I didn't implement any function related to scope this
, because the concept of scope between Javascript is totally different from Python. (JavaScript is a functional programming language, however, Python is a OOP language.)
For example:
In JavaScript, there is closure concept => without bind(this)
:
Obj = {
foo: function() {console.log("foo")},
bar: function(runThisFunc) {runThisFunc()},
baz: function() {
this.bar(function() {
this.foo()
})
}
}
{foo: ƒ, bar: ƒ, baz: ƒ}
Obj.baz()
You will got this error.
Uncaught TypeError: this.foo is not a function
However, in Python
class Obj:
def foo(self):
print("foo")
def baz(self):
def func(): self.foo()
self.bar(func)
def bar(self, run_this_func):
run_this_func()
o = Obj()
o.baz()
It won't give any error.
Thus based on the difference between Python and JS, I didn't implement this feature.
from sinon.
Thus based on the difference between Python and JS, I didn't implement this feature.
That's a good point. Conversely, it makes sense to add some things to Sinon.PY, like kwargs
. I will update the issue.
from sinon.
You are right, kwargs
is a tricky thing in Python.
There are some part of my code need to be refactored about kwargs
and args
.
Because, for any function call
of object
, while it called by args
, the first arguments will be object
itself, later the arguments. On the other side, while it called by kwargs
, the first arguments will be called argument.
For example:
class Obj(object):
def func(a=0, b=0, c=0):
pass
o = Obj()
o.func(1,2,3)
# args is (Obj, 1, 2, 3)
o.func(a=1, b=2, c=3)
# args is (Obj), kwargs is {'a': 1, 'b': 2, 'c': 3}
But, the above might meet some exception in some edge cases based on current implementation
I think there is a way to split args
into 2 part, one for module/class
, the other for pure args
.
Also, this needs big efforts too, it impacts several places.
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.