~ubuntu-branches/ubuntu/lucid/amarok/lucid-backports

« back to all changes in this revision

Viewing changes to tests/mpristest.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2011-03-03 10:27:39 UTC
  • mfrom: (114.1.20 natty)
  • Revision ID: james.westby@ubuntu.com-20110303102739-ar67wpa6mllo59n2
Tags: 2:2.4.0-0ubuntu4~lucid1
* Source backport to lucid (LP: #728447)
  - Drop version requirement on libindicate-qt-dev build-dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import subprocess
 
2
import time
 
3
import unittest
 
4
 
 
5
import dbus
 
6
 
 
7
APPNAME = "amarok"
 
8
MPRIS_OBJECT_PATH = "/org/mpris/MediaPlayer2"
 
9
MPRIS_PREFIX = "org.mpris.MediaPlayer2"
 
10
 
 
11
ROOT_IFACE = MPRIS_PREFIX
 
12
PLAYER_IFACE = MPRIS_PREFIX + ".Player"
 
13
 
 
14
def get_mpris_object():
 
15
    bus = dbus.SessionBus()
 
16
    return bus.get_object(MPRIS_PREFIX + "." + APPNAME, MPRIS_OBJECT_PATH)
 
17
 
 
18
def start_player():
 
19
    devnull = file("/dev/null", "a")
 
20
    player = subprocess.Popen(["amarok", "--nofork"], stderr=devnull, stdout=devnull)
 
21
    time.sleep(10)
 
22
    return player
 
23
 
 
24
def stop_player(player):
 
25
    player.terminate()
 
26
    player.wait()
 
27
 
 
28
class TestMediaPlayer2(unittest.TestCase):
 
29
    def check_property(self, props, key, expected_value):
 
30
        value = props[key]
 
31
        self.assertEquals(value, expected_value)
 
32
        del props[key]
 
33
 
 
34
    def check_has_property(self, props, key):
 
35
        self.assert_(key in props)
 
36
        del props[key]
 
37
 
 
38
    def test_properties(self):
 
39
        player = start_player()
 
40
        try:
 
41
            mpris = get_mpris_object()
 
42
            props = mpris.GetAll(ROOT_IFACE)
 
43
            self.check_property(props, "CanQuit", True)
 
44
            self.check_property(props, "CanRaise", True)
 
45
            self.check_property(props, "HasTrackList", False)
 
46
            self.check_property(props, "Identity", "Amarok")
 
47
            self.check_property(props, "DesktopEntry", "amarok")
 
48
            self.check_has_property(props, "SupportedUriSchemes")
 
49
            self.check_has_property(props, "SupportedMimeTypes")
 
50
            self.assertEquals(len(props), 0)
 
51
        finally:
 
52
            stop_player(player)
 
53
 
 
54
    def test_quit(self):
 
55
        player = start_player()
 
56
        mpris = get_mpris_object()
 
57
        mpris.Quit()
 
58
        start = time.time()
 
59
        while time.time() < start + 60 * 5 and player.poll() is None:
 
60
            time.sleep(.5)
 
61
        if player.poll() is None:
 
62
            stop_player(player)
 
63
            self.fail("Player not stopped")
 
64
 
 
65
unittest.main()