jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/431310 )
Change subject: [tests] Add generate_family_files tests ......................................................................
[tests] Add generate_family_files tests
Bug: T193971 Change-Id: I063bb2ed8b6f4a79f1883841ceba3f76ffb2f4c9 --- A tests/generate_family_files_tests.py 1 file changed, 71 insertions(+), 0 deletions(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/generate_family_files_tests.py b/tests/generate_family_files_tests.py new file mode 100644 index 0000000..be9a19c --- /dev/null +++ b/tests/generate_family_files_tests.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +"""Test generate_family_files script.""" +# +# (C) Pywikibot team, 2018 +# +# Distributed under the terms of the MIT license. +# +from __future__ import absolute_import, unicode_literals + +from random import choice + +from pywikibot import Site + +from tests.aspects import unittest, DefaultSiteTestCase + +import generate_family_file + + +class FamilyTestGenerator(generate_family_file.FamilyFileGenerator): + + """Family file test creator.""" + + def getapis(self): + """Only load additional two additional wikis randomly.""" + save = self.langs + self.langs = [choice(save) for i in range(2)] + self.prefixes = [item['prefix'] for item in self.langs] + super(FamilyTestGenerator, self).getapis() + self.langs = save + + def writefile(self): + """Pass writing.""" + pass + + +class TestGenerateFamilyFiles(DefaultSiteTestCase): + + """Test generate_family_file functionality.""" + + def setUp(self): + """Set up tests class.""" + super(TestGenerateFamilyFiles, self).setUp() + self.generator_instance = FamilyTestGenerator( + url=self.site.base_url(''), name='gff-test', dointerwiki='y') + + def test_initial_attibutes(self): + """Test inital FamilyFileGenerator attributes.""" + self.assertEqual(self.generator_instance.base_url, + self.site.base_url('')) + self.assertEqual(self.generator_instance.name, 'gff-test') + self.assertEqual(self.generator_instance.dointerwiki, 'y') + self.assertIsInstance(self.generator_instance.wikis, dict) + self.assertIsInstance(self.generator_instance.langs, list) + + def test_attibutes_after_run(self): + """Test FamilyFileGenerator attributes after run().""" + self.generator_instance.run() + langs = [self.site.lang] + self.generator_instance.prefixes + for lang in langs: + self.assertIn(lang, self.generator_instance.wikis) + for i in range(10): + lang = choice(self.generator_instance.langs) + site = Site(url=lang['url']) + self.assertEqual(site.lang, lang['prefix']) + + +if __name__ == '__main__': # pragma: no cover + try: + unittest.main() + except SystemExit: + pass
pywikibot-commits@lists.wikimedia.org