class test_Song(unittest.TestCase): def setUp(self): self.my_song = Song( title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") def test_init(self): self.assertTrue(self.my_song.title == "Odin") self.assertTrue(self.my_song.artist == "Manowar") self.assertTrue(self.my_song.album == "The Sons of Odin") self.assertTrue(self.my_song.len == "3:44") self.assertTrue(isinstance(self.my_song, Song)) def test_length(self): self.assertTrue(self.my_song.length() == "3:44") def test_length_minutes(self): self.assertTrue(self.my_song.length(minutes=True) == "3") def test_length_hours(self): self.assertTrue(self.my_song.length(hours=True) == "") def test_length_seconds(self): self.assertTrue(self.my_song.length(seconds=True) == "44") def test_str(self): answer = "{} - {} from {} - {}".format(self.my_song.artist, self.my_song.title, self.my_song.album, self.my_song.len) self.assertEqual(str(self.my_song), answer)
def test_starred_song(self): app = MusicApp(True) for k in range(5): app.add_song(Song()) only_song_starred = Song(starred = True) app.add_song(only_song_starred) self.assertEqual(app.get_starred_songs()[0], only_song_starred)
class SongTests(unittest.TestCase): def setUp(self): self.one = Song("bbbbb", "nnnnn", "aaaaa", "1:20:3") self.two = Song("bbbbb", "nnnnn", "aaaaa", "1:20:3") self.three = Song("aaaaa", "nnnnn", "bbbbb", "1:20") def test_type_error_init_song(self): with self.subTest("test title"): with self.assertRaises(TypeError): Song(title=13, artist="", album="", length="") with self.subTest("test artist"): with self.assertRaises(TypeError): Song(title="", artist=13, album="", length="") with self.subTest("test album"): with self.assertRaises(TypeError): Song(title="", artist="", album=13, length="") with self.subTest("test length"): with self.assertRaises(TypeError): Song(title="", artist="", album="", length=13) def test_song_str_representation(self): expected = "bbbbb - nnnnn from aaaaa - 1:20:3" self.assertEqual(str(self.one), expected) def test_songs_equal_or_not(self): with self.subTest("one and two are equal"): self.assertTrue(self.one == self.two) with self.subTest("one and three are not equal"): self.assertFalse(self.one == self.three) def test_songs_hash_equal_or_not(self): with self.subTest("one and two are equal"): self.assertTrue(hash(self.one) == hash(self.two)) with self.subTest("one and three are not equal"): self.assertFalse(hash(self.one) == hash(self.three)) def test_songs_length(self): with self.subTest("without parameters"): self.assertEqual(self.one.length(), "1:20:3") with self.subTest("seconds"): self.assertEqual(self.one.length(seconds=True), 4803) with self.subTest("minutes"): self.assertEqual(self.one.length(minutes=True), 80) with self.subTest("hours"): self.assertEqual(self.one.length(hours=True), 1)
def song_search(self, song): song_list = [] counter = 1 print("SONG: " + song) print("~~~~~~ RESULTS ~~~~~~") search_result = self.g_music.search(song, max_results=5) search_result_songs = search_result['song_hits'] for track in search_result_songs: track_info = track['track'] current_track = Song(track_info) current_track.link = self.g_music.get_stream_url(track_info['storeId'], device_id=None, quality=u'hi') song_list.append(current_track) print(str(counter) + ': ' + current_track.description()) counter = counter + 1 return song_list
def test_type_error_init_song(self): with self.subTest("test title"): with self.assertRaises(TypeError): Song(title=13, artist="", album="", length="") with self.subTest("test artist"): with self.assertRaises(TypeError): Song(title="", artist=13, album="", length="") with self.subTest("test album"): with self.assertRaises(TypeError): Song(title="", artist="", album=13, length="") with self.subTest("test length"): with self.assertRaises(TypeError): Song(title="", artist="", album="", length=13)
def main(): loop = asyncio.get_event_loop() queue = asyncio.Queue(maxsize=8) song = Song('dr_chaos') loop.create_task(queue_put(queue, song)) pulse = Note() max_concurrent = 8 for _ in range(max_concurrent): loop.create_task(consume(queue, pulse.pulse)) fire_anim = Fire(num_leds=10) loop.create_task(loop_stuff(fire_anim)) touch_pins = [1, 2, 3] touch = Touch(touch_pins) timer = Timer(0) timer.init(period=100, mode=Timer.PERIODIC, callback=touch.cb) loop.create_task(report_touch(touch)) # import esp # esp.neopixel_write(pin, grb_buf, is800khz) # rtc = RTC() # rtc.datetime() loop.run_forever()
def test_number_starred_song(self): app = MusicApp(True) for k in range(20): app.add_song(Song(starred = not k % 2)) self.assertEqual(len(app.get_starred_songs()), 10)
def test_add_song_free(self): app = MusicApp() for _ in range(20): app.add_song(Song()) self.assertEqual(len(app.get_sorted()), 5)
def test_add_song_premium(self): app = MusicApp(True) for _ in range(20): app.add_song(Song()) self.assertEqual(len(app.get_sorted()), 20)
def test_validate_song_length_input_works(self): with self.subTest("Length input is just a number"): with self.assertRaises(ValueError): s_to_change = Song( title='Odin', artist='Manowar', album='The Sons of Odin', length='23' ) with self.subTest("Length input contains non-ints"): with self.assertRaises(TypeError): s_to_change = Song( title='Odin', artist='Manowar', album='The Sons of Odin', length='qba:qba' )
def test_time_string(self): song = Song( title="Bullet with Butterfly Wings", artist="Smashing Pumpkins" ) self.assertEqual( str(song), "Bullet with Butterfly Wings by Smashing Pumpkins" )
def setUp(self): self.song1 = Song( title="Bullet with Butterfly Wings", artist="Smashing Pumpkins", time='00:04:17' ) self.song2 = Song( title="Song 2", artist="Blur", time="00:02:01" ) self.song3 = Song( title="Creep", artist="Radiohead", time="00:03:58" ) self.playlist = Playlist( [self.song1, self.song2, self.song3] )
def test_sorted_songs(self): app = MusicApp(True) for k in range(10): app.add_song(Song(duration = (10 - k))) self.assertEqual( [m.duration for m in app.get_sorted()], [k + 1 for k in range(10)] )
def main(): p = Playlist(name='za ceniteli') p.add_songs([ Song(title='Domination', artist='Pantera', album='Cowboys From Hell', length='05:04'), Song(title='This Love', artist='Pantera', album='Vulgar display of power', length='04:54'), Song(title='Walk', artist='Pantera', album='Vulgar display of power', length='03:54'), Song(title='Momicheto', artist='Hipodil', album='Nadurveni vuglishta', length='03:09') ]) p.pprint_playlist() p.save() print('*' * 50) p = Playlist.load('za-ceniteli.json') p.add_songs([ Song(title='Vurtianalen SEX', artist='Hipodil', album='Nadurveni vuglishta', length='04:04'), Song(title='Kolio Piqndeto', artist='Obraten Efekt', album='Efekten Obrat', length='03:31'), Song(title='Polet', artist='Obraten Efekt', album='Vervaite ni', length='03:50'), Song(title='Choki', artist='Obraten Efekt', album='Vervaite ni', length='04:09') ]) p.pprint_playlist() p.save()
def get_all_albums(): """ Takes information from the designated csv files and initializes Album and Song class objects using that data. :return: a list of Album objects, each of which include a Song object """ album_content = [] song_content = [] album_song_ids = [] complete_albums = [] album_filename = "deadmau5_albums.csv" song_filename = "deadmau5_tracks.csv" with open(song_filename, 'r') as t_file: csv_t_object = csv.reader(t_file) for row in csv_t_object: song_content.append(row) with open(album_filename, 'r') as a_file: csv_object = csv.reader(a_file) for row in csv_object: album_content.append(row) album_content.remove(album_content[0]) song_content.remove(song_content[0]) for row in album_content: album_song_ids.append(row[1]) for element in album_content: song_list = [] joiner = "/" date_list = element[2].split("-") new_date_list = joiner.join(date_list) date_object2 = datetime.strptime(new_date_list, '%Y/%m/%d') album_date = date.fromisoformat(element[2]) fixed_date = album_date.strftime("%B %d,%Y") for i in range(0, len(song_content)): if element[1] == song_content[i][2]: a = Song(song_content[i][0], song_content[i][2], element[0], date_object2) song_list.append(a) b = Album(element[0], element[1], fixed_date, song_list) complete_albums.append(b) return complete_albums
def forming_a_song_library(self, args=None): unique_files, duplicates = self.find_unique_files() music_list = [] for unique_hash in unique_files.keys(): song_rate, song_channels = \ self.read(file_name=unique_files[unique_hash]) id3_tags = FileReader.id_tags(file=unique_files[unique_hash]) music_list.append( Song(unique_files[unique_hash], song_rate, song_channels, unique_hash, id3_tags)) sorted(music_list, key=lambda song: song.name) return music_list
def setUp(self): self.one = Song("bbb", "aaa", "ccc", "3:36") self.two = Song("ddd", "aaa", "eee", "4:20") self.three = Song("eee", "aaa", "ccc", "12:28") self.four = Song("nnn", "mmm", "ooo", "6:32") self.five = Song("sss", "ppp", "rrr", "1:20:03") self.six = Song("yyy", "xxx", "zzz", "2:32:15") self.playlist_one = Playlist(name="First") self.playlist_two = Playlist(name="First", repeat=True) self.playlist_three = Playlist(name="First", shuffle=True) self.playlist_four = Playlist(name="First", repeat=True, shuffle=True) self.list_of_songs = [ self.one, self.two, self.three, self.four, self.five, self.six ]
# actual_clock.py from time import sleep from os import system from setup_alarm import setup_alarm from datetime import datetime from music import Song from nice_loading import Loading load = Loading() s = Song() song_choice = s.choose_song() class Clock(object): """A class for showing the current time and setting up the alarm""" def __str__(self): return "Showing the time" def __repr__(self): return "Digital clock" def clear(self): system("clear") def get_alarm(self): """Getting the hour and minute when you want to wake up""" self.hour, self.minute = setup_alarm() return self.hour, self.minute def set_time(self):
def generate_song(full_path): audio = MP3(full_path) return Song(title=audio['TIT2'], artist=audio['TPE1'], album=audio['TALB'], length=int(audio.info.length))
def test_song_with_invalid_gender(self): self.assertEqual(Song(gender='rock').gender, Gender.none)
def test_song_with_valid_gender(self): self.assertEqual(Song(gender=Gender.pop).gender, Gender.pop)
def test_time_format_too_short(self): with self.assertRaises(ValueError): Song(time='00:00')
def review_music_file(self, path_file): frame_rate, channels = self.read(file_name=path_file) song_hash = FileReader.hash_file_static(path=path_file) probable_tags = FileReader.id_tags(file=path_file) return Song(path_file, frame_rate, channels, song_hash, probable_tags)
import unittest from music import Song from music import PlayList s = Song( title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44" ) s1 = Song( title='In the end', artist='Linkin Park', album='Hybrid Theory', length='1:4:13' ) s2 = Song( title='Numb', artist='Linkin Park', album='Meteora', length='4:7' ) class SongTests(unittest.TestCase): def test_length_works(self): print(s.__dict__) with self.subTest('with seconds'): self.assertEqual(s.l(seconds=True), 224) self.assertEqual(s1.l(seconds=True), 3853)
def test_time_update(self): song1 = Song(time='00:00:10') self.assertEqual(song1.total_seconds, 10) song1.total_seconds = '00:00:30' self.assertEqual(song1.total_seconds, 30)
def test_time_add(self): song1 = Song(time='00:00:10') song2 = Song(time='00:01:00') print(song1.total_seconds) self.assertEqual(song1+song2, 70)
def setUp(self): self.one = Song("bbbbb", "nnnnn", "aaaaa", "1:20:3") self.two = Song("bbbbb", "nnnnn", "aaaaa", "1:20:3") self.three = Song("aaaaa", "nnnnn", "bbbbb", "1:20")
self.__alert_to_finish = threading.Thread(target=self.__alert, args=(song, )) self.__alert_to_finish.start() return song class ShowInfoPlugin(MusicAppComponent): def __init__(self, music_app): self.__music_app = music_app def play_song(self, name): song = self.__music_app.play_song(name) if song == None: return None print( f"Nombre: {song.name}\nDuración: {str(song.duration)} s\nGénero: {str(song.gender)}\n" ) if __name__ == "__main__": music_app = MusicApp() music_app.add_song(Song(name="Tengo miedo", duration=2)) plugin_app = ShowInfoPlugin(AlertFinishSongPlugin(music_app)) plugin_app.play_song("Saludos") plugin_app.play_song("Tengo miedo")
def setUp(self): self.my_song = Song( title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
def test_time_int(self): song = Song(time='00:00:10') self.assertEqual(int(song), 10)
def test_time_math(self): song = Song(time='00:03:30') self.assertEqual(song.total_seconds, 210)
def test_convert_song_to_mp3(self): self.assertEqual(Song(duration=100).to_mp3().duration, 60)