<commit_before>#!/usr/bin/env python
# -*- coding:utf-8 -*-

import argparse
import random
import unittest
import wptools


lang = ['de', 'es', 'fr', 'hi', 'it', 'ja', 'nl', 'ru', 'sv', 'vi', 'zh']


class WPToolsBadTest(unittest.TestCase):
    """
    BAD API REQUEST TESTS
    """

    def test_redirect(self):
        """
        Get redirected
        """
        b = wptools.page('<NAME>').get_query(False)
        self.assertEqual(b.title, 'Benjamin_Franklin')

    def test_missing(self):
        """
        Get missing title
        """
        b = wptools.page('_____').get_query(False)
        self.assertTrue(b.pageid is None)

    def test_unknown_lang(self):
        """
        Mediawiki site function not supported
        """
        # "jp" Wikinews (unknown language code)
        b = wptools.page(wiki='jp.wikinews.org')
        self.assertTrue(b.fatal)


class WPToolsPickTest(unittest.TestCase):
    """
    SELECTED (cherry-picked) TESTS
    """

    def test_selected(self):
        """
        Get selected title
        """
        t = wptools.test.title()
        p = wptools.page(t['title'], lang=t['lang']).get_query(False)
        self.assertTrue(p.pageid is not None)

    def test_wikibase(self):
        """
        Get everything wikibase only
        """
        p = wptools.page(wikibase='Q43303').get_wikidata(False, False)
        self.assertEqual(p.title, 'Malcolm_X')

    def test_wikidata_title(self):
        """
        Get wikidata from title only
        """
        w = wptools.page('Les Misérables').get_wikidata(False, False)
        self.assertTrue(w.wikibase is not None)

    def test_wikidata_claims(self):
        p = wptools.page('Paris').get_wikidata(False)
        self.assertTrue(p.wikidata['coordinates'] is not None)
        self.assertEqual(p.wikidata['continent'], 'Europe')
        self.assertEqual(p.wikidata['country'], 'France')

    def test_mixed_lang(self):
        """
        Get mixed language
        """
        p = wptools.page('<NAME>', lang='zh').get_query(False)
        self.assertEqual(p.wikibase, 'Q91')

    def test_complex_infobox(self):
        """
        Successfully populate complex infobox dict
        """
        p = wptools.page('Aung San Suu Kyi').get_parse(False)
        self.assertGreaterEqual(len(p.infobox), 32)

    def test_thumbnail(self):
        """
        Get a thumbnail image URL
        """
        p = wptools.page('<NAME>').get_rest(False)
        self.assertTrue(p.thumbnail.startswith('http'))


class WPToolsRandomTest(unittest.TestCase):
    """
    RANDOM TESTS
    """

    def test_random(self):
        """
        Get a random title
        """
        r = wptools.page()
        self.assertTrue(r.pageid is not None)
<commit_msg>check for errors in test_complex_infobox<commit_after>#!/usr/bin/env python
# -*- coding:utf-8 -*-

import argparse
import random
import unittest
import wptools


lang = ['de', 'es', 'fr', 'hi', 'it', 'ja', 'nl', 'ru', 'sv', 'vi', 'zh']


class WPToolsBadTest(unittest.TestCase):
    """
    BAD API REQUEST TESTS
    """

    def test_redirect(self):
        """
        Get redirected
        """
        b = wptools.page('<NAME>').get_query(False)
        self.assertEqual(b.title, 'Benjamin_Franklin')

    def test_missing(self):
        """
        Get missing title
        """
        b = wptools.page('_____').get_query(False)
        self.assertTrue(b.pageid is None)

    def test_unknown_lang(self):
        """
        Mediawiki site function not supported
        """
        # "jp" Wikinews (unknown language code)
        b = wptools.page(wiki='jp.wikinews.org')
        self.assertTrue(b.fatal)


class WPToolsPickTest(unittest.TestCase):
    """
    SELECTED (cherry-picked) TESTS
    """

    def test_selected(self):
        """
        Get selected title
        """
        t = wptools.test.title()
        p = wptools.page(t['title'], lang=t['lang']).get_query(False)
        self.assertTrue(p.pageid is not None)

    def test_wikibase(self):
        """
        Get everything wikibase only
        """
        p = wptools.page(wikibase='Q43303').get_wikidata(False, False)
        self.assertEqual(p.title, 'Malcolm_X')

    def test_wikidata_title(self):
        """
        Get wikidata from title only
        """
        w = wptools.page('Les Misérables').get_wikidata(False, False)
        self.assertTrue(w.wikibase is not None)

    def test_wikidata_claims(self):
        p = wptools.page('Paris').get_wikidata(False)
        self.assertTrue(p.wikidata['coordinates'] is not None)
        self.assertEqual(p.wikidata['continent'], 'Europe')
        self.assertEqual(p.wikidata['country'], 'France')

    def test_mixed_lang(self):
        """
        Get mixed language
        """
        p = wptools.page('Abraham Lincoln', lang='zh').get_query(False)
        self.assertEqual(p.wikibase, 'Q91')

    def test_complex_infobox(self):
        """
        Successfully populate complex infobox dict
        """
        p = wptools.page('Aung San Suu Kyi').get_parse(False)
        self.assertGreaterEqual(len(p.infobox), 32)
        self.assertTrue('errors' not in p.infobox)

    def test_thumbnail(self):
        """
        Get a thumbnail image URL
        """
        p = wptools.page('Frida Kahlo').get_rest(False)
        self.assertTrue(p.thumbnail.startswith('http'))


class WPToolsRandomTest(unittest.TestCase):
    """
    RANDOM TESTS
    """

    def test_random(self):
        """
        Get a random title
        """
        r = wptools.page()
        self.assertTrue(r.pageid is not None)

{'fraction_non_alphanumeric': 0.13989266547406082, 'fraction_numerical': 0.0035778175313059034, 'mean_word_length': 2.3539292141571684, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '2322514', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1792, 'n_words': 348}