[MediaWiki-commits] [Gerrit] [tests] Aditional unittests for build_table - change (pywikibot...xqbot)

2016-04-09 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: [tests] Aditional unittests for build_table
..


[tests] Aditional unittests for build_table

- add py3 compatibility
- add doc strings

Change-Id: I0ca9f38314562b673bafa45087bf41df21c495be
---
M imagereview.py
M tests/imagereview_tests.py
2 files changed, 100 insertions(+), 9 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/imagereview.py b/imagereview.py
index f51a2d9..38af78d 100644
--- a/imagereview.py
+++ b/imagereview.py
@@ -605,7 +605,7 @@
 self.save(i, text, summary=summary)
 return True  # returns klären!!!
 
-def build_table(self, save=True):
+def build_table(self, save=True, unittest=False):
 
 def f(k):
 r = 0
@@ -632,7 +632,7 @@
 table[sortkey].append([image.title(asLink=True, textlink=True),
   uploader, image, u''])
 pywikibot.output(u'\nBuilding wiki table...')
-keys = table.keys()
+keys = list(table.keys())  # py3 compatibility
 if self.getOption('list'):
 keys.sort()
 else:
@@ -668,7 +668,7 @@
 pywikibot.output(u'Max limit %d exceeded.' % 
self.total)
 break
 continue
-if self.inform_user(key, table[key]):
+if not unittest and self.inform_user(key, table[key]):
 pywikibot.output(u'%s done.' % key)
 informed.append(key)
 k += l
@@ -684,7 +684,6 @@
 # jetzt wieder sortieren und (leider) erneuten Druchlauf
 informed.sort()
 keys = informed
-
 for key in keys:
 if self.getOption('check'):
 ##cattext += u'\n== [[Benutzer:%s|]] ==\n\n' % key
@@ -700,7 +699,7 @@
 if self.getOption('check'):
 self.save(cat, cattext, summary=u'Bot: Neue DÜP-Einträge')
 self.save(pywikibot.Page(self.site, self.dest), text)
-return
+return table
 
 def run_check(self):
 MAX = 500
diff --git a/tests/imagereview_tests.py b/tests/imagereview_tests.py
index 3834117..014a276 100644
--- a/tests/imagereview_tests.py
+++ b/tests/imagereview_tests.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8  -*-
-"""Test vandalism modules."""
+"""Test imagereview modules."""
 #
-# (C) xqt, 2015
+# (C) xqt, 2016
 #
 # Distributed under the terms of the MIT license.
 #
@@ -15,6 +15,8 @@
 import unittest
 
 import pywikibot
+from pywikibot import config, Timestamp
+from pywikibot.tools import StringTypes
 
 currentdir = os.path.dirname(
 os.path.abspath(inspect.getfile(inspect.currentframe(
@@ -27,8 +29,6 @@
 class TestMessages(unittest.TestCase):
 
 """Test messages."""
-
-net = False
 
 def test_message_keys(self):
 """Test message keys for mail and talk page."""
@@ -52,18 +52,25 @@
 
 @classmethod
 def setUpClass(cls):
+"""Setup class."""
+super(TestDUP_Image, cls).setUpClass()
 cls.site = pywikibot.Site('de', 'wikipedia')
 cls.review_tpl = pywikibot.Page(cls.site, 'düp', 10)
 
 @classmethod
 def tearDownClass(cls):
+"""Cleanup Class."""
 del cls.site
 del cls.review_tpl
+super(TestDUP_Image, cls).tearDownClass()
 
 def tearDown(self):
+"""Cleanup methods."""
 del self.image
+super(TestDUP_Image, self).tearDown()
 
 def init_content(self):
+"""Instantiate DUP_Image."""
 self.image = imagereview.DUP_Image(self.site, 'Sample.jpg', self.TMPL)
 self.image._templates.append(self.review_tpl)
 self.image.text += self.TMPL
@@ -107,6 +114,91 @@
 self.assertTrue(self.image.hasRefs)
 
 
+class TestCheckImageBot(unittest.TestCase):
+
+"""Test CheckImageBot."""
+
+@classmethod
+def setUpClass(cls):
+"""Setup Class."""
+config.family = 'wikipedia'
+config.mylang = 'de'
+
+def test_invalid_option(self):
+"""Test run method without options."""
+with self.assertRaises(NotImplementedError):
+imagereview.CheckImageBot()
+
+def test_list_option(self):
+"""Test run method with list options."""
+bot = imagereview.CheckImageBot(list=True, total=1)
+self.assertEqual(bot.sort, 1)
+self.assertTrue(bot.filter)
+self.assertEqual(bot.total, 1)
+
+def test_check_option(self):
+"""Test run method with check options."""
+bot = imagereview.CheckImageBot(check=True)
+self.assertEqual(bot.sort, 0)
+self.assertFalse(bot.filter)
+self.assertIsNone(bot.total)
+
+def test_build_table_with_list(self):
+"""Test buildt table with list option."""
+bot = imagereview.CheckImageBot(list=True)
+table = bot.buil

[MediaWiki-commits] [Gerrit] [tests] Aditional unittests for build_table - change (pywikibot...xqbot)

2016-04-09 Thread Xqt (Code Review)
Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/282465

Change subject: [tests] Aditional unittests for build_table
..

[tests] Aditional unittests for build_table

Change-Id: I0ca9f38314562b673bafa45087bf41df21c495be
---
M imagereview.py
M tests/imagereview_tests.py
2 files changed, 98 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/bots/xqbot 
refs/changes/65/282465/1

diff --git a/imagereview.py b/imagereview.py
index f51a2d9..9c59b31 100644
--- a/imagereview.py
+++ b/imagereview.py
@@ -605,7 +605,7 @@
 self.save(i, text, summary=summary)
 return True  # returns klären!!!
 
-def build_table(self, save=True):
+def build_table(self, save=True, unittest=False):
 
 def f(k):
 r = 0
@@ -668,7 +668,7 @@
 pywikibot.output(u'Max limit %d exceeded.' % 
self.total)
 break
 continue
-if self.inform_user(key, table[key]):
+if not unittest and self.inform_user(key, table[key]):
 pywikibot.output(u'%s done.' % key)
 informed.append(key)
 k += l
@@ -684,7 +684,6 @@
 # jetzt wieder sortieren und (leider) erneuten Druchlauf
 informed.sort()
 keys = informed
-
 for key in keys:
 if self.getOption('check'):
 ##cattext += u'\n== [[Benutzer:%s|]] ==\n\n' % key
@@ -700,7 +699,7 @@
 if self.getOption('check'):
 self.save(cat, cattext, summary=u'Bot: Neue DÜP-Einträge')
 self.save(pywikibot.Page(self.site, self.dest), text)
-return
+return table
 
 def run_check(self):
 MAX = 500
diff --git a/tests/imagereview_tests.py b/tests/imagereview_tests.py
index 3834117..ca5f297 100644
--- a/tests/imagereview_tests.py
+++ b/tests/imagereview_tests.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8  -*-
-"""Test vandalism modules."""
+"""Test imagereview modules."""
 #
-# (C) xqt, 2015
+# (C) xqt, 2016
 #
 # Distributed under the terms of the MIT license.
 #
@@ -15,6 +15,8 @@
 import unittest
 
 import pywikibot
+from pywikibot import Timestamp
+from pywikibot.tools import StringTypes
 
 currentdir = os.path.dirname(
 os.path.abspath(inspect.getfile(inspect.currentframe(
@@ -27,8 +29,6 @@
 class TestMessages(unittest.TestCase):
 
 """Test messages."""
-
-net = False
 
 def test_message_keys(self):
 """Test message keys for mail and talk page."""
@@ -52,18 +52,25 @@
 
 @classmethod
 def setUpClass(cls):
+"""Setup class."""
+super(TestDUP_Image, self).setUpClass()
 cls.site = pywikibot.Site('de', 'wikipedia')
 cls.review_tpl = pywikibot.Page(cls.site, 'düp', 10)
 
 @classmethod
 def tearDownClass(cls):
+"""Cleanup Class."""
 del cls.site
 del cls.review_tpl
+super(TestDUP_Image, self).tearDownClass()
 
 def tearDown(self):
+"""Cleanup methods."""
 del self.image
+super(TestDUP_Image, self).tearDown()
 
 def init_content(self):
+"""Instantiate DUP_Image."""
 self.image = imagereview.DUP_Image(self.site, 'Sample.jpg', self.TMPL)
 self.image._templates.append(self.review_tpl)
 self.image.text += self.TMPL
@@ -107,6 +114,90 @@
 self.assertTrue(self.image.hasRefs)
 
 
+class TestCheckImageBot(unittest.TestCase):
+
+"""Test CheckImageBot."""
+
+def test_invalid_option(self):
+"""Test run method without options."""
+with self.assertRaises(NotImplementedError):
+bot = imagereview.CheckImageBot()
+
+def test_invalid_option(self):
+"""Test run method without options."""
+with self.assertRaises(NotImplementedError):
+bot = imagereview.CheckImageBot()
+
+def test_list_option(self):
+"""Test run method with list options."""
+bot = imagereview.CheckImageBot(list=True, total=1)
+self.assertEqual(bot.sort, 1)
+self.assertTrue(bot.filter)
+self.assertEqual(bot.total, 1)
+
+def test_check_option(self):
+"""Test run method with check options."""
+bot = imagereview.CheckImageBot(check=True)
+self.assertEqual(bot.sort, 0)
+self.assertFalse(bot.filter)
+self.assertIsNone(bot.total)
+
+def test_build_table_with_list(self):
+"""Test buildt table with list option."""
+bot = imagereview.CheckImageBot(list=True)
+table = bot.build_table(False)
+if not table:
+self.assertSkip()   
+key = table.keys()[0]
+data = table[key]
+item = data[0]
+self.assertIsInstance(key, StringTypes)
+self.assertIsInstance(data, list)
+self.assertIsInstance(item, list)
+self.assertEqual(len(item