Permalink
Browse files

Fixed addtrack 'play now' flag, with tests.

It was *always* being triggered, regardless of what argument you passed
in.

Closes #4.
  • Loading branch information...
1 parent 53d8387 commit 84fc16b1c6240b5f0858bf7ddf40501cb7eb7852 @mackstann committed Nov 17, 2011
Showing with 44 additions and 4 deletions.
  1. +7 −3 mpris-remote
  2. +37 −1 tests.py
View
@@ -372,19 +372,23 @@ class MPRISRemote(object):
@explain_argtype(0, is_valid_uri)
@explain_argtype(1, is_boolean, optional=True)
def addtrack(self, uri, playnow='false'):
+ playnow = playnow == 'true'
if uri == '-':
for i, line in enumerate(sys.stdin):
-
path = line.rstrip('\r\n')
+
+ if not path.strip():
+ continue
+
if not (os.path.isfile(path) or os.path.isdir(path)):
raise BadUserInput('not a file or directory: %s' % path)
- if bool(playnow) and i == 0:
+ if playnow and i == 0:
self.tracklist.AddTrack(path, True)
else:
self.tracklist.AddTrack(path, False)
else:
- self.tracklist.AddTrack(uri, bool(playnow))
+ self.tracklist.AddTrack(uri, playnow)
@explain_numargs(0)
def tracknum(self):
View
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import sys, os, unittest
+import sys, os, unittest, StringIO
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'mock'))
# the mprisremote.py in mock/ is just a symlink to mpris-remote. this is so we
@@ -135,6 +135,42 @@ def test_trackinfo_with_track_number(self):
r.find_player('foo')
self.assertEquals(expected_output, ''.join(r.trackinfo('8')))
+ def test_addtrack_playnow_flag_single_file(self):
+ dummy_filename = __file__ # arg must be a real filename that exists
+ self.assertCallDbusActivity('addtrack', [dummy_filename, 'true' ], ('/TrackList', 'AddTrack', dummy_filename, True))
+ self.assertCallDbusActivity('addtrack', [dummy_filename, 'false'], ('/TrackList', 'AddTrack', dummy_filename, False))
+ self.assertCallDbusActivity('addtrack', [dummy_filename ], ('/TrackList', 'AddTrack', dummy_filename, False))
+
+ def test_addtrack_playnow_flag_multiple_files(self):
+ # file args must be real paths that exist.
+ dummy_filename = __file__
+ dummy_filename2 = os.getcwd()
+
+ stdin = sys.stdin
+
+ sys.stdin = StringIO.StringIO()
+ sys.stdin.write(dummy_filename + "\n" + dummy_filename2 + "\n")
+ sys.stdin.seek(0)
+ self.assertCallDbusActivity('addtrack', ['-', 'true' ],
+ ('/TrackList', 'AddTrack', dummy_filename, True),
+ ('/TrackList', 'AddTrack', dummy_filename2, False))
+
+ sys.stdin = StringIO.StringIO()
+ sys.stdin.write(dummy_filename + "\n" + dummy_filename2 + "\n")
+ sys.stdin.seek(0)
+ self.assertCallDbusActivity('addtrack', ['-', 'false'],
+ ('/TrackList', 'AddTrack', dummy_filename, False),
+ ('/TrackList', 'AddTrack', dummy_filename2, False))
+
+ sys.stdin = StringIO.StringIO()
+ sys.stdin.write(dummy_filename + "\n" + dummy_filename2 + "\n")
+ sys.stdin.seek(0)
+ self.assertCallDbusActivity('addtrack', ['-' ],
+ ('/TrackList', 'AddTrack', dummy_filename, False),
+ ('/TrackList', 'AddTrack', dummy_filename2, False))
+
+ sys.stdin = stdin
+
def test_random_get_true(self):
dbus.mock_method('/Player', 'GetStatus', lambda: [0, 1, 0, 0])
r = mprisremote.MPRISRemote()

0 comments on commit 84fc16b

Please sign in to comment.