<commit_before>import threading
import unittest

from pykka.actor import ThreadingActor
from pykka.registry import ActorRegistry

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

class BackendEventsTest(unittest.TestCase):
    def setUp(self):
        self.events = {
            'track_playback_paused': threading.Event(),
            'track_playback_resumed': threading.Event(),
            'track_playback_started': threading.Event(),
            'track_playback_ended': threading.Event(),
        }
        self.backend = DummyBackend.start().proxy()
        self.listener = DummyBackendListener.start(self.events).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()
        self.backend.playback.pause()
        self.events['track_playback_paused'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_paused'].is_set())

    def test_resume_sends_track_playback_resumed(self):
        self.backend.current_playlist.add([Track(uri='a')])
        self.backend.playback.play()
        self.backend.playback.pause()
        self.backend.playback.resume()
        self.events['track_playback_resumed'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_resumed'].is_set())

    def test_play_sends_track_playback_started_event(self):
        self.backend.current_playlist.add([Track(uri='a')])
        self.backend.playback.play()
        self.events['track_playback_started'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_started'].is_set())

    def test_stop_sends_track_playback_ended_event(self):
        self.backend.current_playlist.add([Track(uri='a')])
        self.backend.playback.play()
        self.backend.playback.stop()
        self.events['track_playback_ended'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_ended'].is_set())


class DummyBackendListener(ThreadingActor, BackendListener):
    def __init__(self, events):
        self.events = events

    def track_playback_paused(self, track, time_position):
        self.events['track_playback_paused'].set()

    def track_playback_resumed(self, track, time_position):
        self.events['track_playback_resumed'].set()

    def track_playback_started(self, track):
        self.events['track_playback_started'].set()

    def track_playback_ended(self, track, time_position):
        self.events['track_playback_ended'].set()<commit_msg>Test that seek() emits seeked event<commit_after>import threading
import unittest

from pykka.actor import ThreadingActor
from pykka.registry import ActorRegistry

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

class BackendEventsTest(unittest.TestCase):
    def setUp(self):
        self.events = {
            'track_playback_paused': threading.Event(),
            'track_playback_resumed': threading.Event(),
            'track_playback_started': threading.Event(),
            'track_playback_ended': threading.Event(),
            'seeked': threading.Event(),
        }
        self.backend = DummyBackend.start().proxy()
        self.listener = DummyBackendListener.start(self.events).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()
        self.backend.playback.pause()
        self.events['track_playback_paused'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_paused'].is_set())

    def test_resume_sends_track_playback_resumed(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.backend.playback.play()
        self.backend.playback.pause()
        self.backend.playback.resume()
        self.events['track_playback_resumed'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_resumed'].is_set())

    def test_play_sends_track_playback_started_event(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.backend.playback.play()
        self.events['track_playback_started'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_started'].is_set())

    def test_stop_sends_track_playback_ended_event(self):
        self.backend.current_playlist.add(Track(uri='a'))
        self.backend.playback.play()
        self.backend.playback.stop()
        self.events['track_playback_ended'].wait(timeout=1)
        self.assertTrue(self.events['track_playback_ended'].is_set())

    def test_seek_sends_seeked_event(self):
        self.backend.current_playlist.add(Track(uri='a', length=40000))
        self.backend.playback.play()
        self.backend.playback.seek(1000)
        self.events['seeked'].wait(timeout=1)
        self.assertTrue(self.events['seeked'].is_set())


class DummyBackendListener(ThreadingActor, BackendListener):
    def __init__(self, events):
        self.events = events

    def track_playback_paused(self, track, time_position):
        self.events['track_playback_paused'].set()

    def track_playback_resumed(self, track, time_position):
        self.events['track_playback_resumed'].set()

    def track_playback_started(self, track):
        self.events['track_playback_started'].set()

    def track_playback_ended(self, track, time_position):
        self.events['track_playback_ended'].set()

    def seeked(self):
        self.events['seeked'].set()
{'fraction_non_alphanumeric': 0.11987326174969196, 'fraction_numerical': 0.0031684562577011088, 'mean_word_length': 3.8316326530612246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5191158', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1747, 'n_words': 215}