-
Notifications
You must be signed in to change notification settings - Fork 113
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
is_not + greater_than passes for non-comparable types #215
Comments
I'm not sure I agree. It is true that "a" is not greater than 1 - it's not comparable to it. And introducing ternary logic feels like it would be a huge can of worms. |
There are two expectations this violates.
In addition, by using Another way to resolve your original problem without introducing ternary logic is to be more explicit about what you actually meant. assert_that(['a',4], contains_inanyorder(all_of(instance_of(int), greater_than(0)), 'a')) |
Trying to handle a ternary case in an inverting binary matcher is something I don't believe we should do in Hamcrest; I think the consequences in terms of complexity will be far worse. |
@offbyone The two statements I listed above are perfectly reasonable expectations. You are choosing the worse interpretation that will lead to bugs being silently ignored. To me, that is not an acceptable stance for a testing framework. |
You are making a small, but critical, category error: Hamcrest is a matching framework, often useful in testing. The two statements you make are reasonable expectations when applied to numerical operators, or when both entities being compared are numerical, but those assumptions don't hold when the types are incompatible. |
I'll take your thumbs up to mean you disagree, but this is not a bug in hamcrest as it is intended, and I'm going to close this issue. |
Darn. Okay! |
The fix for #185 made it so that
OrderingComparison
returnsFalse
rather than throwing aTypeError
when the two types in question are not comparable (e.g.,str
andint
). However, this new behavior is rather unexpected, as it causesis_not
to returnTrue
. For example:In reality, PyHamcrest needs to incorporate ternary logic in order for such comparisons to be treated in a consistent manner.
In the meantime, I suggest that #199 be reverted.
The text was updated successfully, but these errors were encountered: