def test_playlist_next_song_works_as_expected_with_repeat_and_shuffle( self): f = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") s = Song(title="Empty", artist="Metric", album="Live It Out", length="5:55") q = Song(title="Superman", artist="Eminem", album="The Eminem Show", length="5:50") code_songs = Playlist(name="Code", repeat=True, shuffle=True) test = Playlist(name="Code2", repeat=True, shuffle=True) code_songs.add_song(f) code_songs.add_song(s) code_songs.add_song(q) test.add_song(code_songs.next_song()) test.add_song(code_songs.next_song()) test.add_song(code_songs.next_song()) code_songs.next_song() assert code_songs.next_song() in getattr(test, 'songs')
def test_song_len_correctly_returns_seconds_when_called_with_seconds(self): test = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") self.assertEqual(test.length(seconds=True), '224')
class TestSong(unittest.TestCase): def setUp(self): self.s = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") def test_initialisation(self): self.assertTrue(isinstance(self.s, Song)) def test_str_cast(self): expected = "Manowar - Odin from The Sons of Odin - 3:44" self.assertEqual(expected, self.s.__str__()) def test_equal(self): r = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") p = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:40") self.assertTrue(self.s.__eq__(r)) self.assertFalse(self.s.__eq__(p)) def test_hash(self): self.assertTrue(isinstance(self.s.__hash__(), int)) def test_lenght_func(self): r = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="12:03:44") self.assertEqual(r.length_func(minutes=True), '03') self.assertEqual(r.length_func(seconds=True), '44') self.assertEqual(r.length_func(hours=True), '12') self.assertEqual(r.length_func(), r.length)
def test_lenght_func(self): r = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="12:03:44") self.assertEqual(r.length_func(minutes=True), '03') self.assertEqual(r.length_func(seconds=True), '44') self.assertEqual(r.length_func(hours=True), '12') self.assertEqual(r.length_func(), r.length)
def setUp(self): self.my_song = Song("Solder Of Frortune", "Deep Purple", "Stormbringer", "3:14") self.second_song = Song("I Stand Alone", "Godsmack", "Awake", "4:30") self.rock = Playlist("Rock songs", True) self.songs = [self.my_song, self.second_song] self.rock.add_songs(self.songs)
def test_adding_ongs_to_the_playlist_return_a_divtionary_with_artists_and_count_of_songs_they_have_in_the_playlist( self): song1 = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44") song3 = Song(title="7 Rings", artist="Ariana Grande", album="Thank U, Next", length="4:44") song4 = Song(title="Tank U, Next", artist="Ariana Grande", album="Thank U, Next", length="4:44") play_list = PlayList(name="My New PlayList", repeat=True, shuffle=True) play_list.add_song(song1) play_list.add_song(song2) play_list.add_song(song3) play_list.add_song(song4) dic = play_list.artists() self.assertEqual(dic, { 'Manowar1': 1, 'Manowar2': 1, 'Ariana Grande': 2 })
class TestSong(unittest.TestCase): def setUp(self): self.title = "nana" self.artist = "Viki" self.album = "Na" self._length = "3:00" self.song = Song(self.title, self.artist, self.album, self._length) self.song2 = Song("lq", "Viktoria", "lqlq", "4:30") self.song3 = Song(self.title, self.artist, self.album, self._length) def test_init(self): self.assertEqual(self.title, self.song.title) def test_hash(self): self.assertEqual(hash((self.title, self.artist, self.album, self._length)), hash(self.song)) def test_eq(self): self.assertTrue(self.song == self.song3) self.assertFalse(self.song == self.song2) def test_lenght_to_seconds(self): self.assertEqual(180, self.song.lenght_to_seconds("3:00")) self.assertEqual(11456, self.song.lenght_to_seconds("3:10:56")) def test_lenght_seconds(self): self.assertEqual(180, self.song.length(seconds=True)) def test_lenght_minutes(self): pass def test_lenght_hour(self): pass def test_lenght_empty(self): pass
def test_playlist_next_song_works_as_expected_with_no_repeat_and_no_shuffle( self): f = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") s = Song(title="Empty", artist="Metric", album="Live It Out", length="5:55") q = Song(title="Superman", artist="Eminem", album="The Eminem Show", length="5:50") code_songs = Playlist(name="Code", repeat=False, shuffle=False) code_songs.add_song(f) code_songs.add_song(s) code_songs.add_song(q) code_songs.next_song() code_songs.next_song() self.assertEqual(code_songs.next_song(), 'There are no more songs in your playlist.')
class TestingSongClass(unittest.TestCase): def setUp(self): self.s = Song("Odin", "Manowar", "The Sons of Odin", "3:44") self.other = Song("Odin", "Manowar", "The Sons of Odin", "3:44") self.other2 = Song("Odinkata", "Manowar", "The Sons of Odin", "3:4:40") def test_init(self): self.assertEqual(self.s.title, "Odin") self.assertEqual(self.s.artist, "Manowar") self.assertEqual(self.s.album, "The Sons of Odin") self.assertEqual(self.s.length, "3:44") def test_eq(self): self.assertEqual(self.s, self.other) self.assertFalse(self.s == self.other2) def test_hash(self): pass def test_str_dunder(self): self.assertEqual("Manowar - Odin from The Sons of Odin - 3:44", self.s.__str__()) def test_lengths(self): self.assertEqual(self.s.get_length(seconds=True), 224) self.assertEqual(self.other2.get_length(minutes=True), 184) self.assertEqual(self.other2.get_length(hours=True), 3) self.assertEqual(self.other.get_length(), "3:44")
def test_song_len_correctly_returns_str_representation_when_called_without_arguments( self): test = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") self.assertEqual(test.length(), '3:44')
def test_the_function_artists_of_a_playlist_then_return_dictionary_where_keys_are_the_artists_and_values_are_the_numbers_of_the_songs(self): song = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44") song3 = Song(title="Odin", artist="Manowar3", album="The Sons of Odin", length="3:44") playlist = Playlist(name="Code", repeat=True, shuffle=True) playlist.add_songs([song, song2, song3]) expected_result = {'Manowar1': 1, 'Manowar2': 1, 'Manowar3': 1} self.assertEqual(playlist.artists(), expected_result)
def test_string_representation_of_length(self): song = Song('title', 'artist', 'album', '02:55') result = song.length1() expected = '02:55' self.assertEqual(result, expected)
def test_add_list_of_songs_to_an_empty_playlist_then_return_the_total_length_of_the_songs(self): song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") song3 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") playlist = Playlist(name="Code", repeat=True, shuffle=True) playlist.add_songs([song, song2, song3]) expected_result = '0:11:12' self.assertEqual(playlist.total_length(), expected_result)
def test_returning_playlist_next_song_when_reach_the_last_song_and_shuffle_and_no_repeat_then_return_a_song(self): song = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44") song3 = Song(title="Odin", artist="Manowar3", album="The Sons of Odin", length="3:44") playlist = Playlist(name="Code", repeat=False, shuffle=True) playlist.add_songs([song, song2, song3]) expected_result = song self.assertEqual(type(playlist.next_song(song3)), type(expected_result))
def setUp(self): self.pl = Playlist("ssss") self.pl.add_song( Song(title="Odin", artist="Manowar", album="The Sons of Odin", time="3:44")) self.pl.add_song( Song(title="Odin", artist="Manowar", album="Odin", time="6:26"))
def setUp(self): self.song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", time="3:44") self.song1 = Song(title="Odin", artist="Manowar", album="Odin", time="6:26")
def test_if_there_are_no_arguments_returns_the_string_representation_of_the_length( self): song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="1:30:44") res = song.song_length() self.assertEqual(res, "1:30:44")
def test_if_argument_hours_is_true_returns_the_length_in_hours_and_the_length_has_hours( self): song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="1:30:44") res = song.song_length(hours=True) self.assertEqual(res, 1)
def test_if_two_song_are_equal_after_equalization(self): song1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") self.assertEqual(song1, song2)
def test_song_validate_argument_raises_exception_if_argument_type_not_str( self): test = 5 exc = None try: Song.validate_argument(test) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), 'All arguments must be of "str" type.')
def test_song_validate_argument_raises_exception_if_argument_is_empty_string( self): test = '' exc = None try: Song.validate_argument(test) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), 'Empty string cannot be an argument.')
def main(): song1 = Song(title="Odin", artist="Manowar1", album="The Sons of Odin", length="3:44") song2 = Song(title="Odin", artist="Manowar2", album="The Sons of Odin", length="3:44") song3 = Song(title="7 Rings", artist="Ariana Grande", album="Thank U, Next", length="4:44") song4 = Song(title="Tank U, Next", artist="Ariana Grande", album="Thank U, Next", length="4:44") playlist = PlayList(name="My New PlayList", repeat=True, shuffle=True) playlist.add_songs([song1, song2, song3, song4]) playlist.save() playlist2 = PlayList.load("My-New-PlayList.json") print(playlist2.name == "My New PlayList")
def test_song_len_raises_exception_when_called_with_wrong_arguments(self): test = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") exc = None try: self.assertEqual(test.length(seconds=False), '') except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), 'Argument mismatch in function call.')
def test_playlist_total_length_is_calculated_correctly_with_songs_sum_over_hour( self): my_playlist = Playlist(name="Code", repeat=True, shuffle=True) test1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="55:44") test2 = Song(title="Empty", artist="Metric", album="Live It Out", length="5:16") my_playlist.add_song(test1) my_playlist.add_song(test2) self.assertEqual(my_playlist.total_length(), '1:01:00')
def test_song_eq_dunder_correctly_compares_objects(self): test1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") test2 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") test3 = Song(title="Metric", artist="Empty", album="Live It Out", length="5:55") self.assertEqual(test1, test2) self.assertNotEqual(test2, test3)
def test_playlist_total_length_is_calculated_correctly_with_songs_under_a_minute( self): my_playlist = Playlist(name="Code", repeat=True, shuffle=True) test1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="0:44") test2 = Song(title="Empty", artist="Metric", album="Live It Out", length="0:10") my_playlist.add_song(test1) my_playlist.add_song(test2) self.assertEqual(my_playlist.total_length(), '0:54')
def test_length_in_hours(self): song1 = Song('title', 'artist', 'album', '02:55') song2 = Song('title2', 'artist2', 'album2', '02:03:55') song3 = Song('title3', 'artist3', 'album3', '00:58') hours1 = song1.length1(hours=True) hours2 = song2.length1(hours=True) hours3 = song3.length1(hours=True) self.assertEqual(hours1, 0) self.assertEqual(hours2, 2) self.assertEqual(hours3, 0)
def test_length_in_seconds(self): song1 = Song('title', 'artist', 'album', '02:55') song2 = Song('title2', 'artist2', 'album2', '02:03:55') song3 = Song('title3', 'artist3', 'album3', '00:58') secs1 = song1.length1(seconds=True) secs2 = song2.length1(seconds=True) secs3 = song3.length1(seconds=True) self.assertEqual(secs1, 175) self.assertEqual(secs2, 955) self.assertEqual(secs3, 58)
def test_length_in_minutes(self): song1 = Song('title', 'artist', 'album', '2:55') song2 = Song('title2', 'artist2', 'album2', '02:03:55') song3 = Song('title3', 'artist3', 'album3', '00:58') mins1 = song1.length1(minutes=True) mins2 = song2.length1(minutes=True) mins3 = song3.length1(minutes=True) self.assertEqual(mins1, 2) self.assertEqual(mins2, 123) self.assertEqual(mins3, 0)
def test_printing_the_song(self): song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") self.assertEqual(str(song), "Manowar - Odin from The Sons of Odin - 3:44")
def test_song_str_dunder_representation_is_as_expected(self): test = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") self.assertEqual(str(test), 'Manowar - Odin from The Sons of Odin - 3:44')
def test_string_representation(self): song = Song('title', 'artist', 'album', '02:55') result = str(song) expected = 'title - artist from album - 02:55' self.assertEqual(result, expected)
def setUp(self): self.title = "nana" self.artist = "Viki" self.album = "Na" self._length = "3:00" self.song = Song(self.title, self.artist, self.album, self._length) self.song2 = Song("lq", "Viktoria", "lqlq", "4:30") self.song3 = Song(self.title, self.artist, self.album, self._length)
def setUp(self, **kwargs): self.song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") self.title = "Odin" self.artist = "Manowar" self.album = "The Sons of Odin" self.length = "3:44"
def test_shuffle(self): self.rock.change_shuffle(True) bard = Song("The Bard's Song", "Blind Guardian", "Somwhere Far Beyond", "3:28") self.rock.add_song(bard) a = self.rock.next_song() b = self.rock.next_song() c = self.rock.next_song() self.assertTrue(a != b and c != a and c != b)
def test_Song_length(self): s = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="90") self.assertEqual(s.length(seconds=True), "0:01:30") s = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="180") self.assertEqual(s.length(seconds=True), "0:03:00") s = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3600") self.assertEqual(s.length(seconds=True), "1:00:00")
def setUp(self): self.s = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
def setUp(self): self.s = Song("Odin", "Manowar", "The Sons of Odin", "3:44") self.other = Song("Odin", "Manowar", "The Sons of Odin", "3:44") self.other2 = Song("Odinkata", "Manowar", "The Sons of Odin", "3:4:40")
class Tests(unittest.TestCase): def setUp(self): self.song1 = Song( artist="Metalica", album="metalica", length=385, song_name="nothing else matters") def testlength(self): self.assertTrue(self.song1.length_rpr(minutes=True) == "06:25") self.assertTrue(self.song1.length_rpr(seconds=True) == "25") self.assertTrue(self.song1.length_rpr(hours=True) == "0:06:25") def test_class_Playlist_method_artist(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=385, song_name="The Unforgiven") song4 = Song(artist="Iron Maiden", album="Power Slave", length=385, song_name="Fear of the dark") song5 = Song( artist="Iron Maiden", album="Power Slave", length=385, song_name="Acces High") song6 = Song(artist="Qvkata DLG", album="Човека който се смее", length=385, song_name="Екстра а ти ?") songs = [song2, song3, song4, song5, song6] pl = Playlist("rado") pl.add_songs(songs) self.assertTrue(pl.artists()["Metalica"] == 2) self.assertTrue(pl.artists()["Iron Maiden"] == 2) self.assertTrue(pl.artists()["Qvkata DLG"] == 1) def test_class_Playlist_method_add_song(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") pl = Playlist("rado") pl.add_song(song2) self.assertTrue(song2 in pl.song_lst) def test_class_Playlist_method_remove_song(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") pl = Playlist("rado") pl.add_song(song2) pl.remove_song(song2) self.assertTrue(len(pl.song_lst) == 0) def test_class_Playlist_method_total_length(self): # 86400 seconds = 1 day song2 = Song(artist="Metalica", album="metalica", length=86400, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=385, song_name="The Unforgiven") song4 = Song(artist="Iron Maiden", album="Power Slave", length=385, song_name="Fear of the dark") song5 = Song( artist="Iron Maiden", album="Power Slave", length=385, song_name="Acces High") song6 = Song(artist="Qvkata DLG", album="Човекът който се смее", length=385, song_name="Екстра а ти ?") songs = [song2, song3, song4, song5, song6] pl = Playlist("rado") pl.add_songs(songs) self.assertTrue(str(pl.total_length()) == "1 day, 0:25:40") pl.remove_song(song2) self.assertTrue(str(pl.total_length()) == "0:25:40") def test_class_Playlist_method_current_song(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=385, song_name="The Unforgiven") song4 = Song(artist="Iron Maiden", album="Power Slave", length=385, song_name="Fear of the dark") song5 = Song( artist="Iron Maiden", album="Power Slave", length=385, song_name="Acces High") song6 = Song(artist="Qvkata DLG", album="Човекът който се смее", length=385, song_name="Екстра а ти ?") songs = [song2, song3, song4, song5, song6] pl = Playlist("rado", repeat=True) pl.add_songs(songs) self.assertTrue(str(pl.current_song(10)) == "Metalica - Nothing else matters from metalica - 385") self.assertTrue(str(pl.current_song(2)) == "Iron Maiden - Fear of the dark from Power Slave - 385") pl2 = Playlist("rado") # repeat is False pl2.add_songs(songs) self.assertTrue(str(pl2.current_song( 10)) == "Qvkata DLG - Екстра а ти ? from Човекът който се смее - 385") def test_class_Playlist_method_current_song(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=385, song_name="The Unforgiven") song4 = Song(artist="Iron Maiden", album="Power Slave", length=385, song_name="Fear of the dark") song5 = Song( artist="Iron Maiden", album="Power Slave", length=385, song_name="Acces High") song6 = Song(artist="Qvkata DLG", album="Човекът който се смее", length=385, song_name="Екстра а ти ?") songs = [song2, song3, song4, song5, song6] pl = Playlist("rado", repeat=True) pl.add_songs(songs) self.assertTrue( str(pl.next_song()) == "Metalica - The Unforgiven from metalica - 385") self.assertTrue( str(pl.next_song()) == "Iron Maiden - Fear of the dark from Power Slave - 385") self.assertTrue( str(pl.next_song()) == "Iron Maiden - Acces High from Power Slave - 385") pl2 = Playlist("rado2", shuffle=True) pl2.add_songs(songs) #print("Shuffle test :" , pl2.next_song()) # print(pl.ppprint_playlist()) def test_class_Playlist_method_ppprint(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=7200, song_name="The Unforgiven") song4 = Song(artist="Iron Maiden", album="Power Slave", length=385, song_name="Fear of the dark") song5 = Song( artist="Iron Maiden", album="Power Slave", length=86400, song_name="Acces High") song6 = Song(artist="Qvkata DLG", album="Човекът който се смее", length=896385, song_name="Екстра а ти ?") songs = [song2, song3, song4, song5, song6] pl = Playlist("rado", shuffle=True) pl.add_songs(songs) pl.next_song() # pl.ppprint_playlist() def test_class_Playlist_method_save_and_load(self): song2 = Song(artist="Metalica", album="metalica", length=385, song_name="Nothing else matters") song3 = Song( artist="Metalica", album="metalica", length=7200, song_name="The Unforgiven") pl = Playlist("default") pl.add_song(song2) pl.add_song(song3) pl.save() pl.load()
def setUp(self): self.song1 = Song( artist="Metalica", album="metalica", length=385, song_name="nothing else matters")