示例#1
0
 def test_fetches_lyrics_for_multiple_songs(self):
     repository = Mock(wraps=FakeRepository(songs=[
         "Brown Sugar",
         "Jumpin Jack Flash",
         "Gimme Shelter",
         "Sympathy for the Devil",
     ]))
     average_words("The Rolling Stones", repository=repository)
     assert repository.find_lyrics.call_count == 4
示例#2
0
    def test_returns_average_number_of_words(self):
        lyrics = iter([
            "one",
            "two two",
            "three three three",
            "four four four four",
            "five five five five five",
        ])

        class ExtendedFakeRepository:
            async def all_songs_by(self, artist):
                yield "one"
                yield "two"
                yield "three"
                yield "four"

            async def find_lyrics(self, song, artist):
                return next(lyrics)

        repository = Mock(wraps=ExtendedFakeRepository())
        assert average_words("Example", repository=repository) == 2.5
示例#3
0
 def test_fails_if_there_are_no_songs(self):
     repository = Mock(wraps=FakeRepository(songs=[]))
     with self.assertRaises(RuntimeError):
         average_words("this is not a real artist", repository=repository)
示例#4
0
 def test_fetches_lyrics_for_the_correct_song(self):
     repository = Mock(wraps=FakeRepository(songs=["Eleanor Rigby"]))
     average_words("The Beatles", repository=repository)
     repository.find_lyrics.assert_called_once_with("The Beatles",
                                                    "Eleanor Rigby")
示例#5
0
 def test_counts_the_lyrics(self):
     repository = Mock(wraps=FakeRepository(
         lyrics="Living in a material world, I am a material girl."))
     assert average_words("Madonna", repository=repository) == 10
示例#6
0
 def test_gets_words_for_an_artist(self):
     artist = "Daft Punk"
     result = async_controller.average_words(artist=artist)
     assert float(result) > 0
示例#7
0
 def test_fails_gracefully_for_unrecognised_artist(self):
     nonsense = "dikfhuadghuisadfiusdfikgskdiygvfdy"
     with self.assertRaises(ValueError):
         async_controller.average_words(nonsense)
示例#8
0
 def test_rapper_has_more_words_than_punk(self):
     rap_words = async_controller.average_words("Jay-Z")
     punk_words = async_controller.average_words("Sex Pistols")
     assert float(rap_words) > float(punk_words)