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 test_song_len_correctly_returns_hours_when_called_with_hours(self): test1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44") test2 = Song(title="TEST", artist="TEST", album="TEST", length="2:43:44") self.assertEqual(test1.length(hours=True), '0') self.assertEqual(test2.length(hours=True), '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_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')
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')
class SongTest(unittest.TestCase): 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") def test_song_constructor(self): self.assertTrue(isinstance(self.my_song, Song)) self.assertEqual(self.my_song.title(), "Solder Of Frortune") self.assertEqual(self.my_song.artist(), "Deep Purple") self.assertEqual(self.my_song.album(), "Stormbringer") self.assertEqual(self.my_song.length(), "3:14") def test_time_error(self): with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "3:65") with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "63:45") with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "45:63") with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "1:63:45") with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "1:43:65") with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "1:4:253") with self.assertRaises(ValueError): other_song = Song("Knocking on your back door", "Deep Purple", "IDK", "1:433:15") def test_str_cast(self): self.assertEqual( str(self.my_song), "Solder Of Frortune - Deep Purple from Stormbringer - 3:14") def test_eq(self): self.assertTrue(self.my_song != self.second_song) self.assertTrue(self.my_song == self.my_song) def test_hash_cast(self): self.assertIsNotNone(hash(self.my_song)) def test_duration(self): self.assertEqual(self.my_song.duration(seconds=True), 194) self.assertEqual(self.my_song.duration(minutes=True), 3) self.assertEqual(self.my_song.duration(hours=True), 0) self.assertEqual(self.my_song.duration(), "3:14")
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.')
class testMusic(unittest.TestCase): 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_str(self): self.assertEqual(self.song.__str__(), "Odin - Manowar from The Sons of Odin - 3:44") def test_eq(self): self.assertTrue(self.song.__eq__(self.song, self.song1)) def test_length(self): self.assertEqual(self.song1.length(minutes=True), 6)
def test_length_of_the_song_and_return_the_minutes(self): song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="03:44") expected_result = '3' self.assertEqual(song.length(minutes = True), expected_result)
def test_length_of_the_song_and_return_it_in_seconds(self): song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:59") expected_result = '239' self.assertEqual(song.length(seconds = True), expected_result)