Exemplo n.º 1
0
    def test_wc_extractor_file_end_to_end_integration(self):

        openMock = MagicMock()
        openMock.return_value.__enter__.return_value = [
            TEST_SENTENCE, TEST_SENTENCE_2
        ]
        extractor = WCExtractor(file_opener=openMock, filter_words=[])

        result_dw = {}
        expected_dw = {
            TEST_WORD: {
                "word_count": TEST_WORD_COUNT,
                "files": {
                    TEST_FILE: [TEST_SENTENCE, TEST_SENTENCE_2]
                }
            },
            TEST_WORD_2: {
                "word_count": TEST_WORD_COUNT_2,
                "files": {
                    TEST_FILE: [TEST_SENTENCE, TEST_SENTENCE_2]
                }
            },
            TEST_WORD_3: {
                "word_count": TEST_WORD_COUNT_3,
                "files": {
                    TEST_FILE: [TEST_SENTENCE_2]
                }
            }
        }

        extractor.extract_wc_from_file(TEST_FILE, result_dw)

        self.assertEqual(result_dw, expected_dw)
Exemplo n.º 2
0
    def test_extract(self):

        openMock = MagicMock()
        openMock.return_value.__enter__.return_value = [
            TEST_SENTENCE, TEST_SENTENCE_2
        ]
        extractor = WCExtractor(file_opener=openMock, filter_words=[])

        add_word_mock = MagicMock()
        extractor._add_word = add_word_mock

        split_line_mock = MagicMock(return_value=TEST_SENTENCE)
        extractor._split_line = split_line_mock

        result_dw = {}
        extractor.extract_wc_from_file(TEST_FILE, result_dw)

        expected_line_calls = [call(TEST_SENTENCE), call(TEST_SENTENCE_2)]

        openMock.assert_called_once_with(TEST_FILE)
        split_line_mock.assert_has_calls(expected_line_calls)
Exemplo n.º 3
0
    def test_wc_extractor_file_end_to_end_with_files(self):

        extractor = WCExtractor()
        result_wc = {}
        extractor.extract_wc_from_file(ACTUAL_FILE, result_wc)

        # Make sure result is not empty
        self.assertTrue(result_wc)

        for o_words in result_wc:

            word_count = result_wc[o_words]["word_count"]
            total_sentences = 0

            o_words_f = result_wc[o_words]["files"]
            for file in o_words_f:
                total_sentences += len(o_words_f[file])

            # Make sure that all the word counts are equal or greater
            # than the number of sentences
            self.assertGreaterEqual(word_count, total_sentences)
Exemplo n.º 4
0
    def test_wc_extractor_file_integration_filters(self):

        filter_words = [TEST_WORD]

        openMock = MagicMock()
        openMock.return_value.__enter__.return_value = [
            TEST_SENTENCE, TEST_SENTENCE_2
        ]
        extractor = WCExtractor(file_opener=openMock,
                                filter_words=filter_words)

        result_d_words = {}
        expected_d_words = {
            TEST_WORD: {
                "word_count": 2,
                "files": {
                    TEST_FILE: [TEST_SENTENCE, TEST_SENTENCE_2]
                }
            }
        }

        extractor.extract_wc_from_file(TEST_FILE, result_d_words)
        self.assertEqual(result_d_words, expected_d_words)