class TestJukebox(unittest.TestCase): def setUp(self): self.songs = { "Sunday Morning": { "artist": "No Doubt", "path": "songs/path", "jukebox_id": 1 }, "Give it Away": { "artist": "Red Hot Chilli Peppers", "path": "songs/path", "jukebox_id": 2 }, "Santeria": { "artist": "Sublime", "path": "songs/path", "jukebox_id": 3 } } self.jukebox = Jukebox() #this allows us to test the output to the terminal, stdout self.held, sys.stdout = sys.stdout, StringIO() def tearDown(self): sys.stdout = self.held def test_help(self): """It prints a list of commands""" self.jukebox.help() self.assertEqual( sys.stdout.getvalue(), "I accept the following commands:\n" + "- help : displays this help message\n" "- list : displays a list of songs you can play\n" "- play : lets you choose a song to play\n" + "- exit : exits this program\n") def test_list(self): """It lists the songs by jukebox_id, name and artist""" self.jukebox.list(self.songs) self.assertEqual( sys.stdout.getvalue(), "1. Sunday Morning - No Doubt\n" + "2. Give it Away - Red Hot Chilli Peppers\n" + "3. Santeria - Sublime\n") def test_play_1(self): """It plays Sunday Morning when `1` is entered by the user""" with mockRawInput('1'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(), "Now Playing: Sunday Morning\n") def test_play_11(self): """It prints an error message when `11` is entered by the user""" with mockRawInput('11'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(), "Invalid input, please try again\n") def test_play_Santeria(self): """It plays Santeria when `Santeria` is entered by the user""" with mockRawInput('Santeria'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(), "Now Playing: Santeria\n") def test_play_Bye_Bye_Bye(self): """It prints an error message when `Bye Bye Bye` is entered by the user""" with mockRawInput('Bye Bye Bye'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(), "Invalid input, please try again\n") def test_exit_jukebox(self): """It prints 'Goodbye'""" self.jukebox.exit_jukebox() self.assertEqual(sys.stdout.getvalue(), "Goodbye\n") def test_run(self): """It will ask for a new command after listing the songs""" with mockRawInput('exit'): self.jukebox.run(self.songs) self.assertEqual( sys.stdout.getvalue(), "I accept the following commands:\n" + "- help : displays this help message\n" + "- list : displays a list of songs you can play\n" + "- play : lets you choose a song to play\n" "- exit : exits this program\n" + "Goodbye\n")
Bitcoind.getblockchaininfo()['bestblockhash']) # start periodic timers pu = PeriodicUpdates(sui) r.callLater(0.5, pu.run) sr = SystemResources(r, sui, args.blockchain_dir, args.blockchain_device) sr.run() ni = NodeInfo(r, sui) ni.run() lni = LnNodeInfo(r, sui, args.lightning_rpc) lni.run() j = Jukebox(r, sui, args.audio_dir, args.lightning_rpc) j.run() if args.websocket: from serve_web import ServeWeb from serve_websocket import ServeWebsocket from web_eink_ui import WebEinkUI weui = WebEinkUI() sw = ServeWeb(r) sw.run() sws = ServeWebsocket(r, sui, weui, j) sws.run() else: from physical_ui import PhysicalUI pui = PhysicalUI(r, sui, j) pui.run()
class TestJukebox(unittest.TestCase): def setUp(self): self.songs={"Sunday Morning" : {"artist" : "No Doubt", "path": "songs/path", "jukebox_id": 1}, "Give it Away" : {"artist" : "Red Hot Chilli Peppers", "path": "songs/path", "jukebox_id": 2}, "Santeria" : {"artist" : "Sublime", "path": "songs/path", "jukebox_id": 3}} self.jukebox=Jukebox() #this allows us to test the output to the terminal, stdout self.held, sys.stdout = sys.stdout, StringIO() def tearDown(self): sys.stdout = self.held def test_help(self): """It prints a list of commands""" self.jukebox.help() self.assertEqual(sys.stdout.getvalue(), "I accept the following commands:\n"+ "- help : displays this help message\n" "- list : displays a list of songs you can play\n" "- play : lets you choose a song to play\n"+ "- exit : exits this program\n") def test_list(self): """It lists the songs by jukebox_id, name and artist""" self.jukebox.list(self.songs) self.assertEqual(sys.stdout.getvalue(),"1. Sunday Morning - No Doubt\n"+ "2. Give it Away - Red Hot Chilli Peppers\n"+ "3. Santeria - Sublime\n") def test_play_1(self): """It plays Sunday Morning when `1` is entered by the user""" with mockRawInput('1'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(),"Now Playing: Sunday Morning\n") def test_play_11(self): """It prints an error message when `11` is entered by the user""" with mockRawInput('11'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(),"Invalid input, please try again\n") def test_play_Santeria(self): """It plays Santeria when `Santeria` is entered by the user""" with mockRawInput('Santeria'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(),"Now Playing: Santeria\n") def test_play_Bye_Bye_Bye(self): """It prints an error message when `Bye Bye Bye` is entered by the user""" with mockRawInput('Bye Bye Bye'): self.jukebox.play(self.songs) self.assertEqual(sys.stdout.getvalue(),"Invalid input, please try again\n") def test_exit_jukebox(self): """It prints 'Goodbye'""" self.jukebox.exit_jukebox() self.assertEqual(sys.stdout.getvalue(),"Goodbye\n") def test_run(self): """It will ask for a new command after listing the songs""" with mockRawInput('exit'): self.jukebox.run(self.songs) self.assertEqual(sys.stdout.getvalue(),"I accept the following commands:\n"+ "- help : displays this help message\n"+ "- list : displays a list of songs you can play\n"+ "- play : lets you choose a song to play\n" "- exit : exits this program\n"+ "Goodbye\n")