curds: Add basic album class

We'll eventually pull out all the fields we need from a Mutagen
FileInfo class, but that has a dictionary-like interface so we can
easily fake one up for testing.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-01-24 16:27:25 -05:00
parent eecc32359f
commit 3b42ca233e
4 changed files with 55 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*__pycache__*

7
Makefile Normal file
View File

@ -0,0 +1,7 @@
# Copyright 2019 (c) Anna Schumaker.
clean:
rm -rv $(find -name __pycache__ -type d)
tests:
python -m unittest discover curds/

11
curds/album.py Normal file
View File

@ -0,0 +1,11 @@
# Copyright 2019 (c) Anna Schumaker.
class Album:
def __init__(self, fileinfo):
self.album = fileinfo.get("album", [ "Unknown Album" ])[0]
self.genre = fileinfo.get("genre", [ "Unknown" ])[0]
self.date = int(fileinfo.get("date", [ 0 ])[0])
self.tracktotal = int(fileinfo.get("tracktotal", [ 0 ])[0])
self.albumartist = fileinfo.get("albumartist",
fileinfo.get("album artist",
fileinfo.get("artist", [ "Unknown Artist" ])))[0]

36
curds/test_album.py Normal file
View File

@ -0,0 +1,36 @@
# Copyright 2019 (c) Anna Schumaker
import unittest
import album
album_info = {"album" : [ "Test Album" ], "albumartist" : [ "Test Artist" ],
"date" : [ "2019" ], "genre" : [ "Test" ], "tracktotal" : [ "1" ]}
class TestAlbumClass(unittest.TestCase):
def test_init_basic(self):
a = album.Album(album_info)
self.assertEqual(a.album, "Test Album")
self.assertEqual(a.genre, "Test")
self.assertEqual(a.date, 2019)
self.assertEqual(a.albumartist, "Test Artist")
self.assertEqual(a.tracktotal, 1)
def test_init_empty(self):
a = album.Album({})
self.assertEqual(a.album, "Unknown Album")
self.assertEqual(a.genre, "Unknown")
self.assertEqual(a.date, 0)
self.assertEqual(a.albumartist, "Unknown Artist")
self.assertEqual(a.tracktotal, 0)
def test_init_artist_fallback(self):
test_info = {"albumartist" : [ "1" ], "album artist" : [ "2" ], "artist" : [ "3" ]}
self.assertEqual(album.Album(test_info).albumartist, "1")
test_info.pop("albumartist")
self.assertEqual(album.Album(test_info).albumartist, "2")
test_info.pop("album artist")
self.assertEqual(album.Album(test_info).albumartist, "3")
test_info.pop("artist")
self.assertEqual(album.Album(test_info).albumartist, "Unknown Artist")
if __name__ == '__main__':
unittest.main()