models: Make all fields default to None or empty collection

This commit is contained in:
Stein Magnus Jodal 2014-09-22 22:25:42 +02:00
parent bdd1fb983b
commit abed15b9e4
4 changed files with 13 additions and 15 deletions

View File

@ -51,6 +51,10 @@ v0.20.0 (UNRELEASED)
and in the other case explicitly set to the default value, but with otherwise
equal fields. (Fixes: :issue:`837`)
- Changed the default value of :attr:`mopidy.models.Album.num_tracks`,
:attr:`mopidy.models.Track.track_no`, and
:attr:`mopidy.models.Track.last_modified` from ``0`` to :class:`None`.
v0.19.4 (2014-09-01)
====================

View File

@ -241,7 +241,7 @@ class Album(ImmutableObject):
:param artists: album artists
:type artists: list of :class:`Artist`
:param num_tracks: number of tracks in album
:type num_tracks: integer
:type num_tracks: integer or :class:`None` if unknown
:param num_discs: number of discs in album
:type num_discs: integer or :class:`None` if unknown
:param date: album release date (YYYY or YYYY-MM-DD)
@ -262,7 +262,7 @@ class Album(ImmutableObject):
artists = frozenset()
#: The number of tracks in the album. Read-only.
num_tracks = 0
num_tracks = None
#: The number of discs in the album. Read-only.
num_discs = None
@ -302,7 +302,7 @@ class Track(ImmutableObject):
:param genre: track genre
:type genre: string
:param track_no: track number in album
:type track_no: integer
:type track_no: integer or :class:`None` if unknown
:param disc_no: disc number in album
:type disc_no: integer or :class:`None` if unknown
:param date: track release date (YYYY or YYYY-MM-DD)
@ -316,7 +316,7 @@ class Track(ImmutableObject):
:param musicbrainz_id: MusicBrainz ID
:type musicbrainz_id: string
:param last_modified: Represents last modification time
:type last_modified: integer
:type last_modified: integer or :class:`None` if unknown
"""
#: The track URI. Read-only.
@ -341,7 +341,7 @@ class Track(ImmutableObject):
genre = None
#: The track number in the album. Read-only.
track_no = 0
track_no = None
#: The disc number in the album. Read-only.
disc_no = None
@ -364,7 +364,7 @@ class Track(ImmutableObject):
#: Integer representing when the track was last modified, exact meaning
#: depends on source of track. For local files this is the mtime, for other
#: backends it could be a timestamp or simply a version counter.
last_modified = 0
last_modified = None
def __init__(self, *args, **kwargs):
get = lambda key: frozenset(kwargs.pop(key, None) or [])

View File

@ -44,11 +44,11 @@ def track_to_mpd_format(track, position=None):
if track.date:
result.append(('Date', track.date))
if track.album is not None and track.album.num_tracks != 0:
if track.album is not None and track.album.num_tracks is not None:
result.append(('Track', '%d/%d' % (
track.track_no, track.album.num_tracks)))
track.track_no or 0, track.album.num_tracks)))
else:
result.append(('Track', track.track_no))
result.append(('Track', track.track_no or 0))
if position is not None and tlid is not None:
result.append(('Pos', position))
result.append(('Id', tlid))

View File

@ -741,12 +741,6 @@ class TrackTest(unittest.TestCase):
self.assertEqual(track1, track2)
self.assertEqual(hash(track1), hash(track2))
def test_ignores_values_with_default_value_zero(self):
track1 = Track(name='name1')
track2 = Track(name='name1', track_no=0)
self.assertEqual(track1, track2)
self.assertEqual(hash(track1), hash(track2))
def test_copy_can_reset_to_default_value(self):
track1 = Track(name='name1')
track2 = Track(name='name1', album=Album()).copy(album=None)