<commit_before>import pathlib
import shutil
import tempfile
import unittest

import mock

import pykka

import mopidy
from mopidy.audio import PlaybackState
from mopidy.core import Core, CoreListener
from mopidy.internal import models, storage, versioning
from mopidy.models import Track

from tests import dummy_mixer


class CoreActorTest(unittest.TestCase):
    def setUp(self):  # noqa: N802
        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ["dummy1"]
        self.backend1.actor_ref.actor_class.__name__ = "B1"

        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ["dummy2"]
        self.backend2.actor_ref.actor_class.__name__ = "B2"

        self.core = Core(mixer=None, backends=[self.backend1, self.backend2])

    def tearDown(self):  # noqa: N802
        pykka.ActorRegistry.stop_all()

    def test_uri_schemes_has_uris_from_all_backends(self):
        result = self.core.get_uri_schemes()

        self.assertIn("dummy1", result)
        self.assertIn("dummy2", result)

    def test_backends_with_colliding_uri_schemes_fails(self):
        self.backend2.uri_schemes.get.return_value = ["dummy1", "dummy2"]

        self.assertRaisesRegexp(
            AssertionError,
            'Cannot add URI scheme "dummy1" for B2, '
            "it is already handled by B1",
            Core,
            mixer=None,
            backends=[self.backend1, self.backend2],
        )

    def test_version(self):
        self.assertEqual(self.core.get_version(), versioning.get_version())

    @mock.patch("mopidy.core.playback.listener.CoreListener", spec=CoreListener)
    def test_state_changed(self, listener_mock):
        self.core.state_changed(None, PlaybackState.PAUSED, None)

        assert listener_mock.send.mock_calls == [
            mock.call(
                "playback_state_changed",<commit_msg>core: Fix use of deprecated assertion<commit_after>import pathlib
import shutil
import tempfile
import unittest

import mock

import pykka

import mopidy
from mopidy.audio import PlaybackState
from mopidy.core import Core, CoreListener
from mopidy.internal import models, storage, versioning
from mopidy.models import Track

from tests import dummy_mixer


class CoreActorTest(unittest.TestCase):
    def setUp(self):  # noqa: N802
        self.backend1 = mock.Mock()
        self.backend1.uri_schemes.get.return_value = ["dummy1"]
        self.backend1.actor_ref.actor_class.__name__ = "B1"

        self.backend2 = mock.Mock()
        self.backend2.uri_schemes.get.return_value = ["dummy2"]
        self.backend2.actor_ref.actor_class.__name__ = "B2"

        self.core = Core(mixer=None, backends=[self.backend1, self.backend2])

    def tearDown(self):  # noqa: N802
        pykka.ActorRegistry.stop_all()

    def test_uri_schemes_has_uris_from_all_backends(self):
        result = self.core.get_uri_schemes()

        self.assertIn("dummy1", result)
        self.assertIn("dummy2", result)

    def test_backends_with_colliding_uri_schemes_fails(self):
        self.backend2.uri_schemes.get.return_value = ["dummy1", "dummy2"]

        self.assertRaisesRegex(
            AssertionError,
            'Cannot add URI scheme "dummy1" for B2, '
            "it is already handled by B1",
            Core,
            mixer=None,
            backends=[self.backend1, self.backend2],
        )

    def test_version(self):
        self.assertEqual(self.core.get_version(), versioning.get_version())

    @mock.patch("mopidy.core.playback.listener.CoreListener", spec=CoreListener)
    def test_state_changed(self, listener_mock):
        self.core.state_changed(None, PlaybackState.PAUSED, None)

        assert listener_mock.send.mock_calls == [
            mock.call(
                "playback_state_changed",
{'fraction_non_alphanumeric': 0.09808046279253221, 'fraction_numerical': 0.014725216933999474, 'mean_word_length': 3.0728051391862956, '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': '4706097', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1189, 'n_words': 230}