From 3b42ca233e72925afd7b35ced83976a7334f1a33 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 24 Jan 2019 16:27:25 -0500 Subject: [PATCH] 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 --- .gitignore | 1 + Makefile | 7 +++++++ curds/album.py | 11 +++++++++++ curds/test_album.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 curds/album.py create mode 100644 curds/test_album.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd4c22c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*__pycache__* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e881626 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +# Copyright 2019 (c) Anna Schumaker. + +clean: + rm -rv $(find -name __pycache__ -type d) + +tests: + python -m unittest discover curds/ diff --git a/curds/album.py b/curds/album.py new file mode 100644 index 0000000..0f248bd --- /dev/null +++ b/curds/album.py @@ -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] diff --git a/curds/test_album.py b/curds/test_album.py new file mode 100644 index 0000000..d699083 --- /dev/null +++ b/curds/test_album.py @@ -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()