-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
LocalBearTestHelper: Add assertObjectsEqual
#4310
Conversation
status/blocked on |
CC @Makman2 |
Note that the tests will fail because we still don't have the |
@@ -185,10 +201,11 @@ def check_results(self, | |||
create_tempfile=create_tempfile, | |||
tempfile_kwargs=tempfile_kwargs, | |||
settings=settings) | |||
self.addTypeEqualityFunc(list, self.assertObjectsEqual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This should be run somewhere in the beginning of a base test class or so, otherwise it takes effect only in
check_validity
list
doesn't usegenerate_eq
orgenerate_repr
, so this is not really working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we're basically comparing list of Result
objects, so whenever we pass lists to the assertEqual(...)
for comparison, it will call the assertObjectsEqual(...)
method IIUC. What I had initially done was put Result
object instead of list
since we wanna call that method whenever we're comparing Result
objects, see below :
Snippet: self.addTypeEqualityFunc(list, self.assertObjectsEqual)
Output:
E AssertionError: 'mixed spaces and tabs' != 'mixed spaces and tab'
E - mixed spaces and tabs
E ? -
E + mixed spaces and tab
E : message_base mismatch
Snippet: self.addTypeEqualityFunc(Result, self.assertObjectsEqual)
Output:
E AssertionError: Lists differ: [<Result object(id=0xf33dc5cf898c48b4b7114cffd86e8172, origin='[490 chars]438>] != [<Result object(id=0xf211aef4abb24ecb8cc36beebbd848a8, origin='[489 chars]d30>]
E
E First differing element 0:
E <Result object(id=0xf33dc5cf898c48b4b7114cffd86e8172, origin='[489 chars]a438>
E <Result object(id=0xf211aef4abb24ecb8cc36beebbd848a8, origin='[488 chars]2d30>
E
E Diff is 2240 characters long. Set self.maxDiff to None to see it.
CC @Makman2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I create an __init__
method inside our LocalBearTestHelper
class and put addTypeEqualityFunc(..)
there ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative that I've found is we pass the Result
object to assertEqual
which is something like(Error handling of empty lists, and so on will be done..) :
if not check_order:
self.assertEqual(sorted(bear_output)[0], sorted(results)[0])
else:
self.assertEqual(bear_output[0], results[0])
Then self.addTypeEqualityFunc(Result, self.assertObjectsEqual)
snippet is justified IIUC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch haven't thought about that we pass results with lists... here we could just iterate over all passed results and compare them one by one with assertEqual
. And we still register addTypeEqualityFunc
with Result
globally (or an ABC-type of classes using generate_eq
and generate_ordering
which would be the ideal solution).
Hm this is better than nothing, but ideally we would be able to have nicer outputs for collections... don't know something yet, maybe you also get some ideas how to make self.assertObjectsEqual
working automatically everywhere in our tests, even those ones not testing only bears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch haven't thought about that we pass results with lists... here we could just iterate over all passed results and compare them one by one with assertEqual. And we still register addTypeEqualityFunc with Result globally (or an ABC-type of classes using generate_eq and generate_ordering which would be the ideal solution).
Aren't we doing this already in #4310 (comment) ?
Hm this is better than nothing, but ideally we would be able to have nicer outputs for collections... don't know something yet, maybe you also get some ideas how to make self.assertObjectsEqual working automatically everywhere in our tests, even those ones not testing only bears
Our main concern ATM is the not so useful output of bears so IMO we should get this basic functionality merged and those not testing only bears can be looked after later on ? What say ?
Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again! |
@@ -185,10 +201,11 @@ def check_results(self, | |||
create_tempfile=create_tempfile, | |||
tempfile_kwargs=tempfile_kwargs, | |||
settings=settings) | |||
self.addTypeEqualityFunc(list, self.assertObjectsEqual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could actually use Iterable
instead of only list
, so we support any kind of iterable 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe for this case we should explicitly use assertObjectsEqual
instead of registering it for tests. Makes it easier to understand^^
else: | ||
self.assertEqual(bear_output, results, msg=msg) | ||
self.assertEqual(bear_output, results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we delete the msg
variable above as we don't seem to use it any more?
Will fix things suggested by the review comments in the next iteration and iterate over the list containing more than multiple results. |
a0bd8c0
to
18eac8f
Compare
assertObjectsEqual
assertObjectsEqual
18eac8f
to
8490074
Compare
Updated @Makman2 |
coalib/results/Result.py
Outdated
@@ -25,7 +26,7 @@ | |||
'aspect', | |||
'additional_info', | |||
'debug_msg') | |||
class Result: | |||
class Result(Comparables): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to register Result
to be a deriving type of Comparables
inside the generate_eq
/generate_ordering
decorators, not here 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just got to know the difference between the 2 ways of subclassing, the real one and the virtual one. I had actually referred to https://pymotw.com/3/abc/ which doesn't explicitly state the difference. My bad . :)
8490074
to
49ef411
Compare
38dbea6
to
07bd68d
Compare
b994c82
to
122dffa
Compare
How does this look ? @Makman2 |
@Makman2 Ready for merge ? |
Sorry @yash-nisar, you do not have the necessary permission levels to perform the action. |
ack 14642d8 |
@gitmate-bot rebase |
Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently |
Add ``assertObjectsEqual(..)`` method that compares individual fields of the Result object and yields better, easy to understand messages in case of an attribute mismatch. Closes coala#4302
Automated rebase with GitMate.io was successful! 🎉 |
14642d8
to
31ad864
Compare
@gitmate-bot ff |
Hey! I'm GitMate.io! This pull request is being fastforwarded automatically. Please DO NOT push while fastforward is in progress or your changes would be lost permanently |
Automated fastforward with GitMate.io was successful! 🎉 |
Add
assertObjectsEqual(..)
method that compares individualfields of the Result object and yields better, easy to understand
messages in case of an attribute mismatch.
Closes #4302
For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!
Checklist
them.
individually. It is not sufficient to have "fixup commits" on your PR,
our bot will still report the issues for the previous commit.) You will
likely receive a lot of bot comments and build failures if coala does not
pass on every single commit!
After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.
Please consider helping us by reviewing other peoples pull requests as well:
cobot mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!