Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[f] to.be.callable #32

Merged
merged 3 commits into from
Mar 20, 2017
Merged

[f] to.be.callable #32

merged 3 commits into from
Mar 20, 2017

Conversation

catriuspham
Copy link

Issue: #20

We will add this expectation to our code base:

expect(object).to.be.callable()

@catriuspham
Copy link
Author

@NhanHo @hieueastagile Please take a look.

@coveralls
Copy link

coveralls commented Mar 15, 2017

Coverage Status

Coverage increased (+0.009%) to 99.701% when pulling 908e702 on feature/callable into 2caf3a5 on master.

"""

def matches(self):
return hasattr(self.actual, '__call__')
Copy link

@hieueastagile hieueastagile Mar 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing some quick googling and it looks like this is not all the cases. They are still checking for another condition to make sure it's callable. And I found out that we might be able to use callable builtin function, just need to re-check careful how this function is support among python versions. Wdyt?

My ref:
http://stackoverflow.com/questions/111234/what-is-a-callable-in-python
https://docs.python.org/2/library/functions.html#callable

expect(Callable(a).matches()) == True

def test_failure_message(self):
callable = Callable("a")
Copy link

@hieueastagile hieueastagile Mar 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And according to my above explaination, callable is a builtin function, so it's better that we choose another name for our variable.

@NhanHo
Copy link

NhanHo commented Mar 15, 2017

@hieueastagile : which python do we plan to support? Is anyone using python 3.0 or 3.1?

In python 3.x hasattr(self.actual, '__call__') is the recommended way to check for callable after callable is removed in 3.0 (https://docs.python.org/3.1/whatsnew/3.0.html#builtins). It will work with all 3.x code, but it has a bug in the case of python 2.x when the class is an old-style class (does not inherit object).

However, python 3.2 added callable function back, so the only case where using it does not work is in python 3.0 and 3.1

It seems like using callable is the best way, and if we want to support 3.0 or 3.1, there is the isinstance(foo, collections.Callable.

@hieueastagile
Copy link

@NhanHo Thanks for the very details information. I think we only support for python 2.6, 2.7, 3.4, 3.5, 3.6 (see the tox.ini for more information if you like to). So regarding your reference, I think that we should use callable instead.

@coveralls
Copy link

coveralls commented Mar 16, 2017

Coverage Status

Coverage increased (+0.009%) to 99.701% when pulling e3140b1 on feature/callable into 2caf3a5 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants