Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Note reversed #150

Merged
merged 6 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion j5/components/piezo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import abstractmethod
from datetime import timedelta
from enum import IntEnum
from typing import Type, Union
from typing import Generator, Type, Union

from j5.boards import Board
from j5.components import Component, Interface
Expand Down Expand Up @@ -31,6 +31,12 @@ class Note(IntEnum):
A7 = 3520
B7 = 3951

def __reverse__(self) -> Generator['Note', None, None]:
# Type is ignored because of an open bug within mypy
# https://github.com/python/typeshed/issues/1590
# https://github.com/python/typeshed/issues/1595
yield from reversed(self.__members__.items()) # type: ignore


Pitch = Union[int, Note]

Expand Down
5 changes: 5 additions & 0 deletions tests/components/test_piezo.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ def test_piezo_buzz_invalid_value():
piezo.buzz(MockPiezoBoard, 0, 0, -42)
with pytest.raises(TypeError):
piezo.buzz(MockPiezoBoard, 0, 0, "j5")


def test_note_reversed():
"""Test Note reversed dunder method."""
assert list(reversed(list(Note))) == list(reversed(Note))