File: test_exceptions.py

package info (click to toggle)
mopidy-mpd 3.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 680 kB
  • sloc: python: 7,641; makefile: 3
file content (65 lines) | stat: -rw-r--r-- 1,987 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import unittest

from mopidy_mpd.exceptions import (
    MpdAckError,
    MpdNoCommand,
    MpdNoExistError,
    MpdNotImplemented,
    MpdPermissionError,
    MpdSystemError,
    MpdUnknownCommand,
)


class MpdExceptionsTest(unittest.TestCase):
    def test_mpd_not_implemented_is_a_mpd_ack_error(self):
        try:
            raise MpdNotImplemented
        except MpdAckError as exc:
            assert (
                exc.message  # noqa: B306: Our own exception
                == "Not implemented"
            )

    def test_get_mpd_ack_with_default_values(self):
        e = MpdAckError("A description")
        assert e.get_mpd_ack() == "ACK [0@0] {None} A description"

    def test_get_mpd_ack_with_values(self):
        try:
            raise MpdAckError("A description", index=7, command="foo")
        except MpdAckError as e:
            assert e.get_mpd_ack() == "ACK [0@7] {foo} A description"

    def test_mpd_unknown_command(self):
        try:
            raise MpdUnknownCommand(command="play")
        except MpdAckError as e:
            assert e.get_mpd_ack() == 'ACK [5@0] {} unknown command "play"'

    def test_mpd_no_command(self):
        try:
            raise MpdNoCommand
        except MpdAckError as e:
            assert e.get_mpd_ack() == "ACK [5@0] {} No command given"

    def test_mpd_system_error(self):
        try:
            raise MpdSystemError("foo")
        except MpdSystemError as e:
            assert e.get_mpd_ack() == "ACK [52@0] {None} foo"

    def test_mpd_permission_error(self):
        try:
            raise MpdPermissionError(command="foo")
        except MpdPermissionError as e:
            assert (
                e.get_mpd_ack()
                == 'ACK [4@0] {foo} you don\'t have permission for "foo"'
            )

    def test_mpd_noexist_error(self):
        try:
            raise MpdNoExistError(command="foo")
        except MpdNoExistError as e:
            assert e.get_mpd_ack() == "ACK [50@0] {foo} "