def test_remove_album_working(self): band = Band("Death") album = Album("The Sound of Perseverance") band.add_album(album) message = band.remove_album("The Sound of Perseverance") expected = "Album The Sound of Perseverance has been removed." self.assertEqual(message, expected)
def test_add_album_already_added(self): band = Band("Death") album = Album("The Sound of Perseverance") band.add_album(album) message = band.add_album(album) expected = "Band Death already has The Sound of Perseverance in their library." self.assertEqual(message, expected)
def test_remove_album_published(self): band = Band("Death") album = Album("The Sound of Perseverance") album.publish() band.add_album(album) message = band.remove_album("The Sound of Perseverance") expected = "Album has been published. It cannot be removed." self.assertEqual(message, expected)
def get_featured(self): if self.ft_type == "Artist": artist = Artist() artist.load(self.ft_id) return artist elif self.ft_type == "Band": band = Band() band.load(self.ft_id) return band else: return "No"
def get_artist(self): if self.artist_type == "Artist": artist = Artist() artist.load(self.artist_id) return artist elif self.artist_type == "Band": band = Band() band.load(self.artist_id) return band else: return "unknown"
def get(self): band = Band() band.randomize() band.put() band.fix_encoding() self.generate('index.html', template_values={'page_title': 'Band Generator - Generate a band!', 'band' : band, })
def setup(self): self.sax = Instrument("Saxophone") self.guitar = Instrument("Guitar") self.drums = Instrument("Drums") self.m1 = Musician("Evan Parker", self.sax ) self.m2 = Musician("Derek Bailey", self.guitar ) self.m3 = Musician("Han Bennink", self.drums ) self.lungs_band = Band("Lungs Band", [self.m1, self.m2, self.m3])
def get(self, band_id): try: band_id = int(band_id) except ValueError: self.generate('index.html', template_values={'page_title': '404 - Band Generator - Generate a band!', 'band' : {'name': '404'}, }) return band = Band.get_by_id(band_id) band.fix_encoding() band_name = band.name if band and band.name else "" self.generate('index.html', template_values={'page_title': band_name + 'Band Generator - Generate a band!', 'band' : band, 'disqus': True, })
for member in band: if member not in counts: counts[member] = 1 else: counts[member] += 1 for member in counts: print(member, counts[member]) #3: if {}: print('hi') #Not true, so it doesn't give a value d = {"maggie": "uk", "ronnie": "usa"} print(dir(d)) print(d.items()) print(d.keys()) print(d.values()) #help(d.get) print(d.get("maggie")) print(d.get("Someone")) print(d.get("Anybody", "Nowhere")) #Exercise 11: Object Oriented Programming (OOP) #2: from band import Band ws = Band("The White Stripes") ws.employ("Meg", 100) ws.employ("Jack", 100) ws.write_annual_report() #3:
import discord import asyncio from band import Band from discord.ext import tasks client = discord.Client() channel = None discord_token = open('id.txt', 'r').read() band = Band() @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') slow_count.start() @client.event async def on_message(message): global channel if message.content.startswith('!start'): channel = message.channel await channel.send('Start!') @tasks.loop(seconds=3600.0) async def slow_count(): if channel != None:
def test_add_album_working(self): band = Band("Death") album = Album("The Sound of Perseverance") message = band.add_album(album) expected = "Band Death has added their newest album The Sound of Perseverance." self.assertEqual(message, expected)
def test_init(self): band = Band("Death") message = f"{band.name} - {len(band.albums)}" expected = "Death - 0" self.assertEqual(message, expected)
def test_details1(self): band = Band("Death") message = band.details().strip() expected = "Band Death" self.assertEqual(message, expected)
from band import Band from singer import Singer from song import Song from library import Library # Rush band and songs rush = Band('Rush') rush_songs = [ Song('Tom Sawyer', rush, 'https://www.youtube.com/watch?v=auLBLk4ibAk'), Song('YYZ', rush, 'https://www.youtube.com/watch?v=LdpMpfp-J_I') ] rush.songs = rush_songs # Transatlantic band and songs transatlantic = Band('Transatlantic') transatlantic_songs = [ Song('Duel With The Devil', transatlantic, 'https://www.youtube.com/watch?v=Phl57XmsPQ8'), ] transatlantic.songs = transatlantic_songs # Andrea Bocelli singer and songs bocelli = Singer('Andrea Bocelli') bocelli_songs = [ Song('Con Te Partirò', bocelli, 'https://www.youtube.com/watch?v=TdWEhMOrRpQ'), Song('Vivo Per Lei', bocelli, 'https://www.youtube.com/watch?v=ciawICBvQoE'), Song('Il Mare Calmo Della Sera', bocelli, 'https://www.youtube.com/watch?v=Xjl156IBVGY'), ]
print("---------- Exercise 11 script ----------") print("Question 1:") from band import Band print("Question 2:") ws = Band("The White Stripes") ws.employ("Meg", 100) ws.employ("Jack", 100) ws.write_annual_report() print("Question 3:") hs = Band("Hearsay") members = ["Suzanne", "Danny", "Kym", "Myleene", "Noel"] print(f"members: {members}") for member in members: hs.employ(member, 10) hs.write_annual_report() hs.sack("Danny") print("Danny has not been performing...") print(f"Members: {hs.get_members()}") print("Trying to employ Madonna: ") hs.employ("Madonna", 1000000)
from band import Band, Musician, Guitarist, Bassist, Drummer import pytest band_one = Band('Python Band', [Bassist('Curly Noproblem')]) band_two = Band('Typescript Band', [Drummer('Stricto Mcgee')]) band_three = Band('Javasciptt Band', [Guitarist('Loosey Whatever')]) jon = Guitarist('Jon Snow') cersei = Bassist('Cersei') little_finger = Drummer('Little Finger') def test_band_instance_string_attr(): """ A Band instance should have a name attribute which is a string """ expected = 'Python Band' actual = band_one.name assert expected == actual def test_members_attribute_from_band(): """ A Band instance should have a members attribute which is a list of instances that inherit from Musician base (or super) class. """ # expected = ['Drummer: Stricto Mcgee'] # actual = band_two.members # assert expected == actual pass def test_play_solos_method(): """ A Band instance should have a play_solos method that asks each member musician to play a solo, in the order they were added to band.
from band import Band ws = Band("The White Stripes") ws.employ("Meg", 100) ws.employ("Jack", 100) ws.employ("Mary", 100) ws.write_annual_report() ws.get_members() ws.sack("Mary") ws.get_members() ws.promote("Meg", 120) ws.write_annual_report()
def test_create_Band_from_data(): data = Band = Band.create_from_data(data)
def get_band(self, band_id): return Band(self, band_id)
from album import Album from band import Band class Song: def __init__(self, name, length, single): self.name = name self.length = length self.single = single def get_info(self): return f'{self.name} - {self.length}' song = Song("Running in the 90s", 3.45, False) print(song.get_info()) album = Album("Initial D", song) second_song = Song("Around the World", 2.34, False) print(album.add_song(second_song)) print(album.details()) print(album.publish()) band = Band("Manuel") print(band.add_album(album)) print(band.remove_album("Initial D")) print(band.details())
from band import Band hs = Band("Hearsay") new = ["Suzanne", "Danny", "Kym", "Myleene", "Noel"] for name in new: hs.employ(name, 10) print(hs.write_annual_report()) hs.sack("Danny") hs.get_members() #hs.employ("Madonna", 10000000)
def test_remove_album_not_found(self): band = Band("Death") album = Album("The Sound of Perseverance") message = band.remove_album("The Sound of Perseverance") expected = "Album The Sound of Perseverance is not found." self.assertEqual(message, expected)
def test_play_solo(): assert 'all for one, one for all' == Band.get_play_solo()
phish_11_28_03 = Show(date=phirst_show) ph_1995 = date(1995, 12, 31) phish_12_31_95 = Show(date=ph_1995) cornell_77 = date(1977, 5, 8) dead_5_8_77 = Show(date=cornell_77) sunshine_daydream = date(1972, 8, 27) dead_venetta = Show(date=sunshine_daydream) dead_msg = date(1979, 1, 7) dead_1_7_79 = Show(date=dead_msg) # Bands phish = Band(name='Phish') dead = Band(name="Grateful Dead") my_hs_garage_band = Band(name="My Band From High School") phish.shows.extend([phish_12_31_95, phish_11_28_03]) dead.shows.extend([dead_5_8_77, dead_venetta, dead_1_7_79]) person1.shows.extend([dead_5_8_77, phish_12_31_95, phish_11_28_03]) person2.shows.extend([dead_venetta, dead_5_8_77]) person3.shows.append(dead_venetta) # Cities uniondale = City(name="Uniondale, NY") veneta = City(name="Veneta, OR") nyc = City(name="New York, NY") ithaca = City(name="Ithaca, NY")