예제 #1
0
    def test_add_single_word(self):

        extractor = WCExtractor(TEST_FILE, filter_words=[])

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

        extractor._add_word(TEST_WORD, TEST_SENTENCE, TEST_FILE,
                            result_d_words)

        self.assertEqual(result_d_words, expected_d_words)
예제 #2
0
    def test_extract_line(self):

        extractor = WCExtractor(TEST_FILE, 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 = {}

        lines = [TEST_SENTENCE, TEST_SENTENCE_2]

        for line in lines:
            extractor.extract_wc_from_line(line, result_dw)

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

        split_line_mock.assert_has_calls(expected_line_calls)
예제 #3
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)
예제 #4
0
    def test_add_multiple_words(self):

        extractor = WCExtractor(TEST_FILE, filter_words=[])

        result_d_words = {}
        # Testing that adding multiple of the same words
        expected_d_words = {
            TEST_WORD: {
                "word_count": 3,
                "files": {
                    TEST_FILE: [TEST_SENTENCE, TEST_SENTENCE_2, TEST_SENTENCE]
                }
            }
        }

        extractor._add_word(TEST_WORD, TEST_SENTENCE, TEST_FILE,
                            result_d_words)
        extractor._add_word(TEST_WORD, TEST_SENTENCE_2, TEST_FILE,
                            result_d_words)
        extractor._add_word(TEST_WORD, TEST_SENTENCE, TEST_FILE,
                            result_d_words)

        self.assertEqual(result_d_words, expected_d_words)