Skip to content

Commit

Permalink
Fix for str enums, ref #37
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Feb 27, 2023
1 parent f76dada commit e2dbc19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions odmpy/libby.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class LibbyFormats(str, Enum):
EBookOverdrive = "ebook-overdrive"
MagazineOverDrive = "magazine-overdrive"

def __str__(self):
return str(self.value)


class LibbyMediaTypes(str, Enum):
"""
Expand All @@ -92,6 +95,9 @@ class LibbyMediaTypes(str, Enum):
EBook = "ebook"
Magazine = "magazine"

def __str__(self):
return str(self.value)


FILE_PART_RE = re.compile(
r"(?P<part_name>{[A-F0-9\-]{36}}[^#]+)(#(?P<second_stamp>\d+(\.\d+)?))?$"
Expand Down
5 changes: 5 additions & 0 deletions tests/libby_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
merge_toc,
ChapterMarker,
parse_part_path,
LibbyFormats,
)

test_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -398,3 +399,7 @@ def test_alt_authed_libby_client(self):
client.save_settings({"identity": token})
finally:
client.libby_session.close() # avoid ResourceWarning

def test_string_enum(self):
self.assertEqual(f"{LibbyFormats.AudioBookMP3}", "audiobook-mp3")
self.assertEqual(str(LibbyFormats.AudioBookMP3), "audiobook-mp3")

0 comments on commit e2dbc19

Please sign in to comment.