import mock
import unittest

from pykka.registry import ActorRegistry

from mopidy import listeners
from mopidy.backends.dummy import DummyBackend
from mopidy.models import Track

class BackendEventsTest(unittest.TestCase):
    def setUp(self):
        self.listener_send = mock.Mock()
        listeners.BackendListener.send = self.listener_send
        self.backend = DummyBackend.start().proxy()

    def tearDown(self):
        ActorRegistry.stop_all()

    def test_pause_sends_track_playback_paused_event(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.backend.playback.play().get()
        self.listener_send.reset_mock()
        self.backend.playback.pause().get()
        self.assertEqual(self.listener_send.call_args[0][0],
            'track_playback_paused')

    def test_resume_sends_track_playback_resumed(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.backend.playback.play()
        self.backend.playback.pause().get()
        self.listener_send.reset_mock()
        self.backend.playback.resume().get()
        self.assertEqual(self.listener_send.call_args[0][0],
            'track_playback_resumed')

    def test_play_sends_track_playback_started_event(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.listener_send.reset_mock()
        self.backend.playback.play().get()
        self.assertEqual(self.listener_send.call_args[0][0],
            'track_playback_started')

    def test_stop_sends_track_playback_ended_event(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.backend.playback.play().get()
        self.listener_send.reset_mock()
        self.backend.playback.stop().get()
        self.assertEqual(self.listener_send.call_args_list[0][0][0],
            'track_playback_ended')

    def test_seek_sends_seeked_event(self):
        self.backend.current_playlist.add(Track(uri='a', length=40000))
        self.backend.playback.play().get()
        self.listener_send.reset_mock()
        self.backend.playback.seek(1000).get()
        self.assertEqual(self.listener_send.call_args[0][0], 'seeked')

@@ -79,60 +79,73 @@
 pidy
- import listeners%0Afrom mopidy.backends.dummy
+.backends.dummy import DummyBackend%0Afrom mopidy.listeners
  import 
 Dumm
@@ -136,36 +136,39 @@
 ners import 
-Dummy
 Backend
+Listener
 %0Afrom mopidy
@@ -189,16 +189,60 @@
  Track%0A%0A
+@mock.patch.object(BackendListener, 'send')%0A
 class Ba
@@ -302,109 +302,8 @@
 f):%0A
-        self.listener_send = mock.Mock()%0A        listeners.BackendListener.send = self.listener_send%0A
     
@@ -458,32 +458,38 @@
 aused_event(self
+, send
 ):%0A        self.
@@ -580,38 +580,24 @@
 t()%0A        
-self.listener_
 send.reset_m
@@ -667,38 +667,24 @@
 assertEqual(
-self.listener_
 send.call_ar
@@ -688,36 +688,24 @@
 _args%5B0%5D%5B0%5D,
-%0A           
  'track_play
@@ -768,24 +768,30 @@
 resumed(self
+, send
 ):%0A        s
@@ -924,38 +924,24 @@
 t()%0A        
-self.listener_
 send.reset_m
@@ -1012,38 +1012,24 @@
 assertEqual(
-self.listener_
 send.call_ar
@@ -1033,36 +1033,24 @@
 _args%5B0%5D%5B0%5D,
-%0A           
  'track_play
@@ -1114,32 +1114,38 @@
 arted_event(self
+, send
 ):%0A        self.
@@ -1193,38 +1193,24 @@
 '))%0A        
-self.listener_
 send.reset_m
@@ -1279,38 +1279,24 @@
 assertEqual(
-self.listener_
 send.call_ar
@@ -1300,36 +1300,24 @@
 _args%5B0%5D%5B0%5D,
-%0A           
  'track_play
@@ -1379,32 +1379,38 @@
 ended_event(self
+, send
 ):%0A        self.
@@ -1501,38 +1501,24 @@
 t()%0A        
-self.listener_
 send.reset_m
@@ -1587,38 +1587,24 @@
 assertEqual(
-self.listener_
 send.call_ar
@@ -1624,20 +1624,8 @@
 %5B0%5D,
-%0A           
  'tr
@@ -1683,24 +1683,30 @@
 d_event(self
+, send
 ):%0A        s
@@ -1819,30 +1819,16 @@
         
-self.listener_
 send.res
@@ -1913,22 +1913,8 @@
 ual(
-self.listener_
 send

Use mock.patch instead of assigning a mock to the imported module