File: test_frozen.py

package info (click to toggle)
python-mido 1.3.3-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 920 kB
  • sloc: python: 4,006; makefile: 127; sh: 4
file content (60 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download
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
# SPDX-FileCopyrightText: 2017 Ole Martin Bjorndalen <ombdalen@gmail.com>
#
# SPDX-License-Identifier: MIT

from mido.frozen import (
    FrozenMessage,
    FrozenMetaMessage,
    FrozenUnknownMetaMessage,
    freeze_message,
    is_frozen,
    thaw_message,
)
from mido.messages import Message
from mido.midifiles.meta import UnknownMetaMessage


def test_hashability():
    """Test that messages are hashable."""
    hash(FrozenMessage('note_on'))
    # List is converted to tuple.
    hash(FrozenMessage('sysex', data=[1, 2, 3]))
    hash(FrozenMetaMessage('track_name', name='Some track'))
    hash(FrozenUnknownMetaMessage(123, [1, 2, 3]))


def test_freeze_and_thaw():
    """Test that messages are hashable."""
    assert not is_frozen(thaw_message(freeze_message(Message('note_on'))))


def test_thawed_message_is_copy():
    frozen_msg = FrozenMessage('note_on')
    thawed_msg = Message('note_on')
    assert thaw_message(frozen_msg) == thawed_msg


def test_is_frozen():
    assert is_frozen(FrozenMessage('note_on'))
    assert not is_frozen(Message('note_on'))


def test_frozen_repr():
    msg = FrozenMessage('note_on', channel=1, note=2, time=3)
    msg_eval = eval(repr(msg))  # noqa: S307
    assert isinstance(msg_eval, FrozenMessage)
    assert msg == msg_eval


def test_frozen_meta_repr():
    msg = FrozenMetaMessage('end_of_track', time=10)
    msg_eval = eval(repr(msg))  # noqa: S307
    assert isinstance(msg_eval, FrozenMetaMessage)
    assert msg == msg_eval


def test_frozen_unknown_meta_repr():
    msg = FrozenUnknownMetaMessage(type_byte=99, data=[1, 2], time=10)
    msg_eval = eval(repr(msg))  # noqa: S307
    assert isinstance(msg_eval, UnknownMetaMessage)
    assert msg == msg_eval