<commit_before>import random
import time

from mopidy.models import Playlist, Track

def populate_playlist(func):
    def wrapper(self):
        for track in self.tracks:
            self.backend.current_playlist.add(track)
        return func(self)

    wrapper.__name__ = func.__name__
    wrapper.__doc__ = func.__doc__
    return wrapper

class BaseCurrentPlaylistControllerTest(object):
    tracks = []
    backend_class = None

    def setUp(self):
        self.backend = self.backend_class()
        self.controller = self.backend.current_playlist
        self.playback = self.backend.playback

        assert len(self.tracks) >= 3, 'Need at least three tracks to run tests.'

    def tearDown(self):
        self.backend.playback.destroy()

    def test_add(self):
        for track in self.tracks:
            self.controller.add(track)
            self.assertEqual(track, self.controller.playlist.tracks[-1])

    def test_add_at_position(self):
        for track in self.tracks[:-1]:
            self.controller.add(track, 0)
            self.assertEqual(track, self.controller.playlist.tracks[0])

    @populate_playlist
    def test_add_at_position_outside_of_playlist(self):
        self.controller.add(self.tracks[0], len(self.tracks)+2)
        self.assertEqual(self.tracks[0], self.controller.playlist.tracks[-1])

    @populate_playlist
    def test_add_sets_id_property(self):
        for track in self.controller.playlist.tracks:
            self.assertNotEqual(None, track.id)

    @populate_playlist
    def test_get_by_id(self):
        track = self.controller.playlist.tracks[1]
        self.assertEqual(track, self.controller.get_by_id(track.id))

    @populate_playlist
    def test_get_by_id_raises_error_for_invalid_id(self):
        self.assertRaises(KeyError, lambda: self.controller.get_by_id(1337))

    @populate_playlist
    def test_get_by_url(self):
        track = self.controller.playlist.tracks[1]
        self.assertEqual(track, self.controller.get_by_url(track.uri))

    @populate_playlist
    def test_get_by_url_raises_error_for_invalid_id(self):
        self.assertRaises(KeyError, lambda: self.controller.get_by_url('foobar'))

    @populate_playlist
    def test_clear(self):
        self.controller.clear()
        self.assertEqual(len(self.controller.playlist.tracks), 0)

    def test_clear_empty_playlist(self):
        self.controller.clear()

    @populate_playlist
    def test_clear_when_playing(self):
        self.playback.play()
        self.assertEqual(self.playback.state, self.playback.PLAYING)
        self.controller.clear()
        self.assertEqual(self.playback.state, self.playback.STOPPED)

    def test_load(self):
        new_playlist = Playlist()
        self.assertNotEqual(new_playlist, self.controller.playlist)
        self.controller.load(new_playlist)
        self.assertEqual(new_playlist, self.controller.playlist)

    def test_load_does_not_reset_version(self):
        version = self.controller.version<commit_msg>Update get_ tests to match new API<commit_after>import random
import time

from mopidy.models import Playlist, Track

def populate_playlist(func):
    def wrapper(self):
        for track in self.tracks:
            self.backend.current_playlist.add(track)
        return func(self)

    wrapper.__name__ = func.__name__
    wrapper.__doc__ = func.__doc__
    return wrapper

class BaseCurrentPlaylistControllerTest(object):
    tracks = []
    backend_class = None

    def setUp(self):
        self.backend = self.backend_class()
        self.controller = self.backend.current_playlist
        self.playback = self.backend.playback

        assert len(self.tracks) >= 3, 'Need at least three tracks to run tests.'

    def tearDown(self):
        self.backend.playback.destroy()

    def test_add(self):
        for track in self.tracks:
            self.controller.add(track)
            self.assertEqual(track, self.controller.playlist.tracks[-1])

    def test_add_at_position(self):
        for track in self.tracks[:-1]:
            self.controller.add(track, 0)
            self.assertEqual(track, self.controller.playlist.tracks[0])

    @populate_playlist
    def test_add_at_position_outside_of_playlist(self):
        self.controller.add(self.tracks[0], len(self.tracks)+2)
        self.assertEqual(self.tracks[0], self.controller.playlist.tracks[-1])

    @populate_playlist
    def test_add_sets_id_property(self):
        for track in self.controller.playlist.tracks:
            self.assertNotEqual(None, track.id)

    @populate_playlist
    def test_get_by_id(self):
        track = self.controller.playlist.tracks[1]
        self.assertEqual(track, self.controller.get(id=track.id))

    @populate_playlist
    def test_get_by_id_raises_error_for_invalid_id(self):
        self.assertRaises(LookupError, lambda: self.controller.get(id=1337))

    @populate_playlist
    def test_get_by_uri(self):
        track = self.controller.playlist.tracks[1]
        self.assertEqual(track, self.controller.get(uri=track.uri))

    @populate_playlist
    def test_get_by_uri_raises_error_for_invalid_id(self):
        self.assertRaises(LookupError, lambda: self.controller.get(uri='foobar'))

    @populate_playlist
    def test_clear(self):
        self.controller.clear()
        self.assertEqual(len(self.controller.playlist.tracks), 0)

    def test_clear_empty_playlist(self):
        self.controller.clear()

    @populate_playlist
    def test_clear_when_playing(self):
        self.playback.play()
        self.assertEqual(self.playback.state, self.playback.PLAYING)
        self.controller.clear()
        self.assertEqual(self.playback.state, self.playback.STOPPED)

    def test_load(self):
        new_playlist = Playlist()
        self.assertNotEqual(new_playlist, self.controller.playlist)
        self.controller.load(new_playlist)
        self.assertEqual(new_playlist, self.controller.playlist)

    def test_load_does_not_reset_version(self):
        version = self.controller.version
{'fraction_non_alphanumeric': 0.09925062447960033, 'fraction_numerical': 0.005328892589508743, 'mean_word_length': 3.2088297126839525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4910147', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1825, 'n_words': 295}