mirror of
https://github.com/beetbox/beets.git
synced 2025-12-09 18:12:19 +01:00
cleanup docstrings and add tests
This commit is contained in:
parent
1e7e456f21
commit
509af59d4e
2 changed files with 16 additions and 9 deletions
|
|
@ -20,7 +20,6 @@ import logging
|
|||
import re
|
||||
import string
|
||||
from beets import plugins
|
||||
# from beets import config
|
||||
|
||||
log = logging.getLogger('beets')
|
||||
|
||||
|
|
@ -58,7 +57,6 @@ class BucketPlugin(plugins.BeetsPlugin):
|
|||
def setup(self):
|
||||
"""Setup plugin from config options
|
||||
"""
|
||||
|
||||
yearranges = extract_years(self.config['bucket_year'].get())
|
||||
self.yearbounds = sorted([y for ys in yearranges for y in ys])
|
||||
self.yearranges = [self.make_year_range(b) for b in yearranges]
|
||||
|
|
@ -66,9 +64,10 @@ class BucketPlugin(plugins.BeetsPlugin):
|
|||
self.config['bucket_alpha'].get()]
|
||||
|
||||
def make_year_range(self, ys):
|
||||
"""Express year-span as a list of years [from...to].
|
||||
If input year-span only contain the from year, the to is defined
|
||||
as the from year of the next year-span minus one.
|
||||
"""Express year-range as a list of years [from...to].
|
||||
If input year-range only contains the 'from' year, the 'to' is
|
||||
defined as the 'from' year of the next year-range minus one or is
|
||||
set to current year if there is no next year-range.
|
||||
"""
|
||||
if len(ys) == 1: # miss upper bound
|
||||
lb_idx = self.yearbounds.index(ys[0])
|
||||
|
|
@ -79,7 +78,8 @@ class BucketPlugin(plugins.BeetsPlugin):
|
|||
return range(ys[0], ys[-1] + 1)
|
||||
|
||||
def make_alpha_range(self, s):
|
||||
"""Express chars range as a list of chars [from...to]
|
||||
"""Extract alphanumerics from string and return sorted list of chars
|
||||
[from...to]
|
||||
"""
|
||||
bucket = sorted([x for x in s.lower() if x.isalnum()])
|
||||
beginIdx = string.ascii_lowercase.index(bucket[0])
|
||||
|
|
@ -87,9 +87,8 @@ class BucketPlugin(plugins.BeetsPlugin):
|
|||
return string.ascii_lowercase[beginIdx:endIdx + 1]
|
||||
|
||||
def find_bucket_timerange(self, date):
|
||||
"""Find folder whose range contains date
|
||||
1960-1970
|
||||
60s-70s
|
||||
"""Return year-range bucket that matches given date or return the date
|
||||
if no matching bucket.
|
||||
"""
|
||||
for (i, r) in enumerate(self.yearranges):
|
||||
if int(date) in r:
|
||||
|
|
@ -97,6 +96,9 @@ class BucketPlugin(plugins.BeetsPlugin):
|
|||
return date
|
||||
|
||||
def find_bucket_alpha(self, s):
|
||||
"""Return alpha-range bucket that matches given string or return the
|
||||
string initial if no matching bucket.
|
||||
"""
|
||||
for (i, r) in enumerate(self.alpharanges):
|
||||
if s.lower()[0] in r:
|
||||
return self.config['bucket_alpha'].get()[i]
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ class BucketPluginTest(unittest.TestCase, TestHelper):
|
|||
"""If no range match, return the year"""
|
||||
self._setup_config(bucket_year=['50-59', '1960-69'])
|
||||
self.assertEqual(self.plugin._tmpl_bucket('1974'), '1974')
|
||||
self._setup_config(bucket_year=[])
|
||||
self.assertEqual(self.plugin._tmpl_bucket('1974'), '1974')
|
||||
|
||||
def test_alpha_all_chars(self):
|
||||
self._setup_config(bucket_alpha=['ABCD', 'FGH', 'IJKL'])
|
||||
|
|
@ -72,6 +74,9 @@ class BucketPluginTest(unittest.TestCase, TestHelper):
|
|||
|
||||
def test_alpha_out_of_range(self):
|
||||
"""If no range match, return the initial"""
|
||||
self._setup_config(bucket_alpha=['ABCD', 'FGH', 'IJKL'])
|
||||
self.assertEqual(self.plugin._tmpl_bucket('errol'), 'E')
|
||||
self._setup_config(bucket_alpha=[])
|
||||
self.assertEqual(self.plugin._tmpl_bucket('errol'), 'E')
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue