<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 <NAME> <<EMAIL>>
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html

"""
Automated tests for checking the WikiCorpus
"""


import os
import sys
import types
import unittest

from gensim.corpora.wikicorpus import WikiCorpus


module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder
datapath = lambda fname: os.path.join(module_path, 'test_data', fname)
FILENAME = 'enwiki-latest-pages-articles1.xml-p000000010p000030302-shortened.bz2'


class TestWikiCorpus(unittest.TestCase):

    def setUp(self):
        self.wc = WikiCorpus(datapath(FILENAME))


    def test_get_texts_returns_generator_of_lists(self):
        if sys.version_info < (2, 7, 0):
            return
        l = self.wc.get_texts()
        self.assertEqual(type(l), types.GeneratorType)
        first = next(l)
        self.assertEqual(type(first), list)
        self.assertTrue(isinstance(first[0], bytes) or isinstance(first[0], str))

    def test_first_element(self):
        """
        First two articles in this sample are
        1) anarchism
        2) autism

        """
        if sys.version_info < (2, 7, 0):
            return
        l = self.wc.get_texts()
        self.assertTrue(b"anarchism" in next(l))
        self.assertTrue(b"autism" in next(l))<commit_msg>fixing python 2.7 wikidump test hang (#738)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 <NAME> <<EMAIL>>
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html

"""
Automated tests for checking the WikiCorpus
"""


import os
import sys
import types
import unittest

from gensim.corpora.wikicorpus import WikiCorpus


module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder
datapath = lambda fname: os.path.join(module_path, 'test_data', fname)
FILENAME = 'enwiki-latest-pages-articles1.xml-p000000010p000030302-shortened.bz2'


class TestWikiCorpus(unittest.TestCase):

    def setUp(self):
        wc = WikiCorpus(datapath(FILENAME))


    def test_get_texts_returns_generator_of_lists(self):
        if sys.version_info < (2, 7, 0):
            return
        wc = WikiCorpus(datapath(FILENAME))
        l = wc.get_texts()
        self.assertEqual(type(l), types.GeneratorType)
        first = next(l)
        self.assertEqual(type(first), list)
        self.assertTrue(isinstance(first[0], bytes) or isinstance(first[0], str))

    def test_first_element(self):
        """
        First two articles in this sample are
        1) anarchism
        2) autism

        """
        if sys.version_info < (2, 7, 0):
            return
        wc = WikiCorpus(datapath(FILENAME))

        l = wc.get_texts()
        self.assertTrue(b"anarchism" in next(l))
        self.assertTrue(b"autism" in next(l))
{'fraction_non_alphanumeric': 0.1177076183939602, 'fraction_numerical': 0.027110501029512696, 'mean_word_length': 3.004120879120879, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5875371', 'n_tokens_mistral': 1035, 'n_tokens_neox': 948, 'n_words': 227}