Skip to content

Fix #3516 - Erroneous @classmethod on NoneQuery.match#3517

Merged
sampsyo merged 14 commits intobeetbox:masterfrom
adamjakab:none_query_match
Mar 16, 2020
Merged

Fix #3516 - Erroneous @classmethod on NoneQuery.match#3517
sampsyo merged 14 commits intobeetbox:masterfrom
adamjakab:none_query_match

Conversation

@adamjakab
Copy link
Copy Markdown
Contributor

@adamjakab adamjakab commented Mar 15, 2020

It seems like tests are not hitting this method...

Checklist

  • Fix
  • Test
  • Changelog

@adamjakab
Copy link
Copy Markdown
Contributor Author

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?

@sampsyo
Copy link
Copy Markdown
Member

sampsyo commented Mar 15, 2020

Great; thanks!!

The value_match method is indeed unreachable; I think we should leave it off here. It is only used by the base implementation of match for cases where the behavior is best defined in terms of the pattern and value. Although the docstring says "Subclasses must provide a value_match class method," it should probably instead say that they should either provide value_match or just override match itself.

Looks like there's also a test failure related to the Python 3 behavior of repr on strings:
https://travis-ci.org/github/beetbox/beets/jobs/662725636#L912

Would you mind also adding a quick changelog entry describing the fix?

Thanks again for addressing this!

Comment on lines +790 to +806
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)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +164 to +165
def value_match(self, pattern, value):
return value is pattern
Copy link
Copy Markdown
Contributor Author

@adamjakab adamjakab Mar 15, 2020

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +164 to +165
def value_match(self, pattern, value):
return value is pattern
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +790 to +806
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)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

adamjakab and others added 2 commits March 16, 2020 10:12
@adamjakab
Copy link
Copy Markdown
Contributor Author

@sampsyo - she is ready to go ;)

@sampsyo
Copy link
Copy Markdown
Member

sampsyo commented Mar 16, 2020

Looks excellent; thanks!! ✨

@sampsyo sampsyo merged commit 5d39d02 into beetbox:master Mar 16, 2020
sampsyo added a commit that referenced this pull request Mar 16, 2020
@adamjakab adamjakab deleted the none_query_match branch March 26, 2020 08:48
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.

2 participants