Merge pull request #1144 from adamcik/feature/one-of-validation
core: Add "one-of" validation for number of kwargs
This commit is contained in:
commit
9c812bf367
@ -189,13 +189,8 @@ class LibraryController(object):
|
||||
.. deprecated:: 1.0
|
||||
The ``uri`` argument. Use ``uris`` instead.
|
||||
"""
|
||||
none_set = uri is None and uris is None
|
||||
both_set = uri is not None and uris is not None
|
||||
|
||||
if none_set or both_set:
|
||||
raise ValueError("One of 'uri' or 'uris' must be set")
|
||||
|
||||
# TODO: validation.one_of(*args)?
|
||||
if sum(o is not None for o in [uri, uris]) != 1:
|
||||
raise ValueError('Exactly one of "uri" or "uris" must be set')
|
||||
|
||||
uris is None or validation.check_uris(uris)
|
||||
uri is None or validation.check_uri(uri)
|
||||
|
||||
@ -277,9 +277,12 @@ class PlaybackController(object):
|
||||
:param tlid: TLID of the track to play
|
||||
:type tlid: :class:`int` or :class:`None`
|
||||
"""
|
||||
if sum(o is not None for o in [tl_track, tlid]) > 1:
|
||||
raise ValueError('At most one of "tl_track" and "tlid" may be set')
|
||||
|
||||
tl_track is None or validation.check_instance(tl_track, models.TlTrack)
|
||||
tlid is None or validation.check_integer(tlid, min=0)
|
||||
# TODO: check one of or none for args
|
||||
|
||||
if tl_track:
|
||||
deprecation.warn('core.playback.play:tl_track_kwarg', pending=True)
|
||||
|
||||
|
||||
@ -406,10 +406,9 @@ class TracklistController(object):
|
||||
.. deprecated:: 1.0
|
||||
The ``tracks`` and ``uri`` arguments. Use ``uris``.
|
||||
"""
|
||||
assert tracks is not None or uri is not None or uris is not None, \
|
||||
'tracks, uri or uris must be provided'
|
||||
# TODO: check that only one of tracks uri and uris is set...
|
||||
# TODO: can at_position be negative?
|
||||
if sum(o is not None for o in [tracks, uri, uris]) != 1:
|
||||
raise ValueError(
|
||||
'Exactly one of "tracks", "uri" or "uris" must be set')
|
||||
|
||||
tracks is None or validation.check_instances(tracks, Track)
|
||||
uri is None or validation.check_uri(uri)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user