<commit_before># -*- coding: utf-8 -*-
"""Tests for archivebot scripts."""
#
# (C) Pywikibot team, 2016
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals

__version__ = '$Id$'

from datetime import datetime, timedelta

import pywikibot
import pywikibot.page

from pywikibot.textlib import TimeStripper
from pywikibot.tools import StringTypes as basestring

from scripts import archivebot

from tests.aspects import unittest, TestCase

THREADS = {
    'als': 4, 'ar': 1, 'bar': 0, 'bg': 0, 'bjn': 1, 'bs': 0, 'ca': 5, 'ckb': 2,
    'cs': 0, 'de': 1, 'en': 25, 'eo': 2, 'es': 13, 'fa': 2, 'fr': 25, 'frr': 2,
    'hi': 0, 'hr': 2, 'hu': 5, 'id': 3, 'it': 25, 'ja': 4, 'la': 0, 'lt': 1,
    'nl': 9, 'nn': 0, 'no': 0, 'pdc': 25, 'pfl': 3, 'pl': 8, 'pt': 0, 'ro': 1,
    'ru': 20, 'scn': 2, 'simple': 1, 'sr': 0, 'sv': 5, 'th': 1, 'tr': 7,
    'ug': 0, 'uk': 1, 'uz': 1, 'vi': 1, 'zh': 4, 'zh-yue': 2,
}

THREADS_WITH_UPDATED_FORMAT = {
    'eo': 1, 'pdc': 1,
}


class TestArchiveBotFunctionsWithSites(TestCase):

    """Test functions dependent to sites in archivebot."""

    sites = {
        'enwiki': {
            'family': 'wikipedia',
            'code': 'en',
        },
        'frwikt': {
            'family': 'wiktionary',
            'code': 'fr',
        },
        'jawiki': {
            'family': 'wikipedia',
            'code': 'ja',
        }
    }

    def test_str2localized_duraction_English(self):
        """Test English localizations of duration."""
        site = self.get_site('enwiki')
        self.assertEqual(
            archivebot.str2localized_duration(site, '0s'), '0 seconds')
        self.assertEqual(
            archivebot.str2localized_duration(site, '1d'), '1 day')
        self.assertEqual(
            archivebot.str2localized_duration(site, '10h'), '10 hours')

    def test_str2localized_duraction_French(self):
        """Test French localizations of duration."""
        site = self.get_site('frwikt')
        self.assertEqual(
            archivebot.str2localized_duration(site, '10d'), '10 jours')
        self.assertEqual(
            archivebot.str2localized_duration(site, '1y'), '1 an')

    def test_str2localized_duraction_Japanese(self):
        """Test Japanese localizations of duration."""
        site = self.get_site('jawiki')
        self.assertEqual(
            archivebot.str2localized_duration(site, '4000s'), '4000 秒')


class TestArchiveBotFunctions(TestCase):

    """Test functions in archivebot."""

    net = False

    def test_str2time(self):
        """Test for parsing the shorthand notation of durations."""
        date = datetime(2017, 1, 1)  # non leap year
        self.assertEqual(archivebot.str2time('0d'), timedelta(0))
        self.assertEqual(archivebot.str2time('4000s'), timedelta(seconds=4000))
        self.assertEqual(archivebot.str2time('4000h'), timedelta(hours=4000))
        self.assertEqual(archivebot.str2time('7d'), archivebot.str2time('1w'))
        self.assertEqual(archivebot.str2time('3y'), timedelta(1096))
        self.assertEqual(archivebot.str2time('3y', date), timedelta(1095))
        self.assertRaises(archivebot.MalformedConfigError, archivebot.str2time, '4000@')
        self.assertRaises(archivebot.MalformedConfigError, archivebot.str2time, '$1')<commit_msg>archivebot_tests: fix spelling of tested function<commit_after># -*- coding: utf-8 -*-
"""Tests for archivebot scripts."""
#
# (C) Pywikibot team, 2016
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals

__version__ = '$Id$'

from datetime import datetime, timedelta

import pywikibot
import pywikibot.page

from pywikibot.textlib import TimeStripper
from pywikibot.tools import StringTypes as basestring

from scripts import archivebot

from tests.aspects import unittest, TestCase

THREADS = {
    'als': 4, 'ar': 1, 'bar': 0, 'bg': 0, 'bjn': 1, 'bs': 0, 'ca': 5, 'ckb': 2,
    'cs': 0, 'de': 1, 'en': 25, 'eo': 2, 'es': 13, 'fa': 2, 'fr': 25, 'frr': 2,
    'hi': 0, 'hr': 2, 'hu': 5, 'id': 3, 'it': 25, 'ja': 4, 'la': 0, 'lt': 1,
    'nl': 9, 'nn': 0, 'no': 0, 'pdc': 25, 'pfl': 3, 'pl': 8, 'pt': 0, 'ro': 1,
    'ru': 20, 'scn': 2, 'simple': 1, 'sr': 0, 'sv': 5, 'th': 1, 'tr': 7,
    'ug': 0, 'uk': 1, 'uz': 1, 'vi': 1, 'zh': 4, 'zh-yue': 2,
}

THREADS_WITH_UPDATED_FORMAT = {
    'eo': 1, 'pdc': 1,
}


class TestArchiveBotFunctionsWithSites(TestCase):

    """Test functions dependent to sites in archivebot."""

    sites = {
        'enwiki': {
            'family': 'wikipedia',
            'code': 'en',
        },
        'frwikt': {
            'family': 'wiktionary',
            'code': 'fr',
        },
        'jawiki': {
            'family': 'wikipedia',
            'code': 'ja',
        }
    }

    def test_str2localized_duration_English(self):
        """Test English localizations of duration."""
        site = self.get_site('enwiki')
        self.assertEqual(
            archivebot.str2localized_duration(site, '0s'), '0 seconds')
        self.assertEqual(
            archivebot.str2localized_duration(site, '1d'), '1 day')
        self.assertEqual(
            archivebot.str2localized_duration(site, '10h'), '10 hours')

    def test_str2localized_duration_French(self):
        """Test French localizations of duration."""
        site = self.get_site('frwikt')
        self.assertEqual(
            archivebot.str2localized_duration(site, '10d'), '10 jours')
        self.assertEqual(
            archivebot.str2localized_duration(site, '1y'), '1 an')

    def test_str2localized_duration_Japanese(self):
        """Test Japanese localizations of duration."""
        site = self.get_site('jawiki')
        self.assertEqual(
            archivebot.str2localized_duration(site, '4000s'), '4000 秒')


class TestArchiveBotFunctions(TestCase):

    """Test functions in archivebot."""

    net = False

    def test_str2time(self):
        """Test for parsing the shorthand notation of durations."""
        date = datetime(2017, 1, 1)  # non leap year
        self.assertEqual(archivebot.str2time('0d'), timedelta(0))
        self.assertEqual(archivebot.str2time('4000s'), timedelta(seconds=4000))
        self.assertEqual(archivebot.str2time('4000h'), timedelta(hours=4000))
        self.assertEqual(archivebot.str2time('7d'), archivebot.str2time('1w'))
        self.assertEqual(archivebot.str2time('3y'), timedelta(1096))
        self.assertEqual(archivebot.str2time('3y', date), timedelta(1095))
        self.assertRaises(archivebot.MalformedConfigError, archivebot.str2time, '4000@')
        self.assertRaises(archivebot.MalformedConfigError, archivebot.str2time, '$1')
{'fraction_non_alphanumeric': 0.16151202749140894, 'fraction_numerical': 0.041834752726729416, 'mean_word_length': 3.12192118226601, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7359705', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2213, 'n_words': 556}