wordsn returns n 19 words even if n is negative self assertequal words5 lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut def testsameorlesscommonwordsself wordsn starts with the 19 standard lorem ipsum words for n 19 self asserttrue words25 startswith lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua def testmorewordsthancommonself wordsn has n words when n is greater than lenwords self assertequallenwords500 split 500 mock patchdjango utils loremipsum random sample def testnotcommonwordsself mocksample a sentence starts with a capital letter self asserttruesentence0 isupper mock patchdjango utils loremipsum random sample mock patchdjango utils loremipsum random choice mock patchdjango utils loremipsum random randint def testsentenceself mockrandint mockchoice mocksample mockrandint returnvalue 2 use two phrases mocksample returnvalue exercitationem perferendis mockchoice returnvalue value sentence self assertequalmockrandint callcount 3 self assertequalmocksample callcount 2 self assertequalmockchoice callcount 1 self assertequal value exercitationem perferendis exercitationem perferendis mock patchdjango utils loremipsum random choice def testsentenceendingself mockchoice paragraph generates a single paragraph make creating 2 sentences use 2 phrases mockparagraphrandint returnvalue 2 mocksample returnvalue exercitationem perferendis mockchoice returnvalue value paragraph self assertequalmockparagraphrandint callcount 7 self assertequal value exercitationem perferendis exercitationem perferendis exercitationem perferendis exercitationem perferendis mock patchdjango utils loremipsum random sample mock patchdjango utils loremipsum random choice mock patchdjango utils loremipsum random randint def testparagraphsnotcommonself mockrandint mockchoice mocksample make creating 2 sentences use 2 phrases mockrandint returnvalue 2 mocksample returnvalue exercitationem perferendis mockchoice returnvalue self assertequal paragraphs1 commonfalse exercitationem perferendis exercitationem perferendis exercitationem perferendis exercitationem perferendis self assertequalmockrandint callcount 7 def testparagraphsself words n returns n 19 words even if n is negative words n for n 19 words n starts with the 19 standard lorem ipsum words for n 19 words n returns n words for n 19 words n has n words when n is greater than len words words n common false returns random words a sentence starts with a capital letter sentences are built using some number of phrases and a set of words use two phrases sentences end with a question mark or a period paragraph generates a single paragraph make creating 2 sentences use 2 phrases paragraphs 1 common false generating one paragraph that s not the common_p paragraph make creating 2 sentences use 2 phrases paragraphs 1 uses the common_p paragraph
import unittest
from unittest import mock

from django.utils.lorem_ipsum import paragraph, paragraphs, sentence, words


class LoremIpsumTests(unittest.TestCase):
    def test_negative_words(self):
        
        self.assertEqual(
            words(-5),
            "lorem ipsum dolor sit amet consectetur adipisicing elit sed do "
            "eiusmod tempor incididunt ut",
        )

    def test_same_or_less_common_words(self):
        
        self.assertEqual(words(7), "lorem ipsum dolor sit amet consectetur adipisicing")

    def test_common_words_in_string(self):
        
        self.assertTrue(
            words(25).startswith(
                "lorem ipsum dolor sit amet consectetur adipisicing elit sed "
                "do eiusmod tempor incididunt ut labore et dolore magna aliqua"
            )
        )

    def test_more_words_than_common(self):
        
        self.assertEqual(len(words(25).split()), 25)

    def test_common_large_number_of_words(self):
        
        self.assertEqual(len(words(500).split()), 500)

    @mock.patch("django.utils.lorem_ipsum.random.sample")
    def test_not_common_words(self, mock_sample):
        
        mock_sample.return_value = ["exercitationem", "perferendis"]
        self.assertEqual(words(2, common=False), "exercitationem perferendis")

    def test_sentence_starts_with_capital(self):
        
        self.assertTrue(sentence()[0].isupper())

    @mock.patch("django.utils.lorem_ipsum.random.sample")
    @mock.patch("django.utils.lorem_ipsum.random.choice")
    @mock.patch("django.utils.lorem_ipsum.random.randint")
    def test_sentence(self, mock_randint, mock_choice, mock_sample):
        
        mock_randint.return_value = 2  
        mock_sample.return_value = ["exercitationem", "perferendis"]
        mock_choice.return_value = "?"
        value = sentence()
        self.assertEqual(mock_randint.call_count, 3)
        self.assertEqual(mock_sample.call_count, 2)
        self.assertEqual(mock_choice.call_count, 1)
        self.assertEqual(
            value, "Exercitationem perferendis, exercitationem perferendis?"
        )

    @mock.patch("django.utils.lorem_ipsum.random.choice")
    def test_sentence_ending(self, mock_choice):
        
        mock_choice.return_value = "?"
        self.assertIn(sentence()[-1], "?")
        mock_choice.return_value = "."
        self.assertIn(sentence()[-1], ".")

    @mock.patch("django.utils.lorem_ipsum.random.sample")
    @mock.patch("django.utils.lorem_ipsum.random.choice")
    @mock.patch("django.utils.lorem_ipsum.random.randint")
    def test_paragraph(self, mock_paragraph_randint, mock_choice, mock_sample):
        
        
        mock_paragraph_randint.return_value = 2
        mock_sample.return_value = ["exercitationem", "perferendis"]
        mock_choice.return_value = "."
        value = paragraph()
        self.assertEqual(mock_paragraph_randint.call_count, 7)
        self.assertEqual(
            value,
            (
                "Exercitationem perferendis, exercitationem perferendis. "
                "Exercitationem perferendis, exercitationem perferendis."
            ),
        )

    @mock.patch("django.utils.lorem_ipsum.random.sample")
    @mock.patch("django.utils.lorem_ipsum.random.choice")
    @mock.patch("django.utils.lorem_ipsum.random.randint")
    def test_paragraphs_not_common(self, mock_randint, mock_choice, mock_sample):
        
        
        mock_randint.return_value = 2
        mock_sample.return_value = ["exercitationem", "perferendis"]
        mock_choice.return_value = "."
        self.assertEqual(
            paragraphs(1, common=False),
            [
                "Exercitationem perferendis, exercitationem perferendis. "
                "Exercitationem perferendis, exercitationem perferendis."
            ],
        )
        self.assertEqual(mock_randint.call_count, 7)

    def test_paragraphs(self):
        
        self.assertEqual(
            paragraphs(1),
            [
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, "
                "sed do eiusmod tempor incididunt ut labore et dolore magna "
                "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
                "ullamco laboris nisi ut aliquip ex ea commodo consequat. "
                "Duis aute irure dolor in reprehenderit in voluptate velit "
                "esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
                "occaecat cupidatat non proident, sunt in culpa qui officia "
                "deserunt mollit anim id est laborum."
            ],
        )