format None values as the empty string

Fix due to @pscn. Includes test. Closes #108.
This commit is contained in:
Adrian Sampson 2013-02-28 10:00:26 -08:00
parent c31eabe95c
commit d71737114a
3 changed files with 8 additions and 0 deletions

View file

@ -218,6 +218,8 @@ def format_for_path(value, key=None, pathmod=None):
elif key == 'samplerate':
# Sample rate formatted as kHz.
value = u'%ikHz' % ((value or 0) // 1000)
elif value is None:
value = u''
else:
value = unicode(value)

View file

@ -24,6 +24,8 @@ Other stuff:
* When the importer encounters an error (insufficient permissions, for
example) when walking a directory tree, it now logs an error instead of
crashing.
* In path formats, null database values now expand to the empty string instead
of the string "None".
* Add "System Volume Information" (an internal directory found on some
Windows filesystems) to the default ignore list.
* Fix a crash when ReplayGain values were set to null.

View file

@ -362,6 +362,10 @@ class DestinationTest(unittest.TestCase):
val = beets.library.format_for_path(12345, 'samplerate', posixpath)
self.assertEqual(val, u'12kHz')
def test_component_sanitize_none(self):
val = beets.library.format_for_path(None, 'foo', posixpath)
self.assertEqual(val, u'')
def test_artist_falls_back_to_albumartist(self):
self.i.artist = ''
self.i.albumartist = 'something'