Fix #3516 - Erroneous @classmethod on NoneQuery.match#3517
Fix #3516 - Erroneous @classmethod on NoneQuery.match#3517sampsyo merged 14 commits intobeetbox:masterfrom
Conversation
|
The NoneQuery class is now 100% covered. I added a missing value_match abstract method which later I removed because I was unable to reach/test it. I am not sure how it works but I think in the case of the NoneQuery this method can not be reached. Or am I wrong? |
|
Great; thanks!! The Looks like there's also a test failure related to the Python 3 behavior of Would you mind also adding a quick changelog entry describing the fix? Thanks again for addressing this! |
test/test_query.py
Outdated
| def test_query_repr(self): | ||
| fld = u'rg_track_gain' | ||
| if sys.version_info <= (3, 0): | ||
| self.assertEquals("NoneQuery(u'{}', True)".format(fld), | ||
| str(NoneQuery(fld))) | ||
| self.assertEquals("NoneQuery(u'{}', True)".format(fld), | ||
| str(NoneQuery(fld, fast=True))) | ||
| self.assertEquals("NoneQuery(u'{}', False)".format(fld), | ||
| str(NoneQuery(fld, fast=False))) | ||
| else: | ||
| self.assertEquals("NoneQuery('{}', True)".format(fld), | ||
| str(NoneQuery(fld))) | ||
| self.assertEquals("NoneQuery('{}', True)".format(fld), | ||
| str(NoneQuery(fld, fast=True))) | ||
| self.assertEquals("NoneQuery('{}', False)".format(fld), | ||
| str(NoneQuery(fld, fast=False))) | ||
|
|
There was a problem hiding this comment.
I am too n00b to Python to understand what is the story with unicode there. This is not really part of the issue but I though with this we have all methods of the class covered. Can you pls have a look?
There was a problem hiding this comment.
TBH I think we can just remove the tests for repr… the problem is that Python 2 string literals used syntax like u'foo' while on Python 3 they are just 'foo'. Fortunately, repr formatting is so standard that IMO testing it is sort of overkill.
beets/dbcore/query.py
Outdated
| def value_match(self, pattern, value): | ||
| return value is pattern |
There was a problem hiding this comment.
I think this is ok. Also becuause the call from the match method also uses the self.patern initiated in the init.
Again, I am to new to Python to tell. Something like this in Php (i.e. not implementing an abstract method) would fail at compile time... but then again this is not php. So your call: should I remove it?
There was a problem hiding this comment.
Let's just remove it. It should never be called, so I think it would just be misleading to have code here that looks like it should be meaningful (even though it's not). The earlier version you had, where match itself used get and compared to None, seems right to me.
beets/dbcore/query.py
Outdated
| def value_match(self, pattern, value): | ||
| return value is pattern |
There was a problem hiding this comment.
Let's just remove it. It should never be called, so I think it would just be misleading to have code here that looks like it should be meaningful (even though it's not). The earlier version you had, where match itself used get and compared to None, seems right to me.
test/test_query.py
Outdated
| def test_query_repr(self): | ||
| fld = u'rg_track_gain' | ||
| if sys.version_info <= (3, 0): | ||
| self.assertEquals("NoneQuery(u'{}', True)".format(fld), | ||
| str(NoneQuery(fld))) | ||
| self.assertEquals("NoneQuery(u'{}', True)".format(fld), | ||
| str(NoneQuery(fld, fast=True))) | ||
| self.assertEquals("NoneQuery(u'{}', False)".format(fld), | ||
| str(NoneQuery(fld, fast=False))) | ||
| else: | ||
| self.assertEquals("NoneQuery('{}', True)".format(fld), | ||
| str(NoneQuery(fld))) | ||
| self.assertEquals("NoneQuery('{}', True)".format(fld), | ||
| str(NoneQuery(fld, fast=True))) | ||
| self.assertEquals("NoneQuery('{}', False)".format(fld), | ||
| str(NoneQuery(fld, fast=False))) | ||
|
|
There was a problem hiding this comment.
TBH I think we can just remove the tests for repr… the problem is that Python 2 string literals used syntax like u'foo' while on Python 3 they are just 'foo'. Fortunately, repr formatting is so standard that IMO testing it is sort of overkill.
Co-Authored-By: Adrian Sampson <adrian@radbox.org>
|
@sampsyo - she is ready to go ;) |
|
Looks excellent; thanks!! ✨ |
It seems like tests are not hitting this method...
Checklist