jenkins-bot has submitted this change and it was merged.

Change subject: plugin: make sure - _ are treated as space
......................................................................


plugin: make sure - _ are treated as space

When used as attributes self.P_* or self.Q_*

Change-Id: I0968477939d7226a35ba27f2c29e39b358a84976
Signed-off-by: Loic Dachary <l...@dachary.org>
---
M FLOSSbot/plugin.py
M tests/test_plugin.py
2 files changed, 10 insertions(+), 2 deletions(-)

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



diff --git a/FLOSSbot/plugin.py b/FLOSSbot/plugin.py
index 6f86d7b..7c6dcc1 100644
--- a/FLOSSbot/plugin.py
+++ b/FLOSSbot/plugin.py
@@ -16,6 +16,7 @@
 #
 import argparse
 import logging
+import re
 from datetime import datetime, timedelta
 
 import pywikibot
@@ -104,6 +105,10 @@
         },
     }
 
+    @staticmethod
+    def normalize_name(name):
+        return re.sub('[-_]', ' ', name)
+
     def search_entity(self, site, name, **kwargs):
         if name in Plugin.authoritative[site.code]:
             candidate = pywikibot.ItemPage(
@@ -113,7 +118,8 @@
         candidates = []
         for p in site.search_entities(name, 'en', **kwargs):
             log.debug("looking for entity " + name + ", found " + str(p))
-            if p.get('label') == name:
+            if (Plugin.normalize_name(p.get('label')) ==
+                    Plugin.normalize_name(name)):
                 if kwargs['type'] == 'property':
                     candidates.append(p)
                 else:
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 90a0e9e..1a45398 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -112,9 +112,11 @@
         bot = Bot.factory([
             '--test',
             '--user=FLOSSbotCI',
+            '--verbose',
         ])
         plugin = Plugin(bot, bot.args)
-        name = WikidataHelper.random_name()
+        # ensure space, - and _ are accepted
+        name = WikidataHelper.random_name() + "-some thing_else"
         entity = {
             "labels": {
                 "en": {

-- 
To view, visit https://gerrit.wikimedia.org/r/315697
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0968477939d7226a35ba27f2c29e39b358a84976
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/bots/FLOSSbot
Gerrit-Branch: master
Gerrit-Owner: Dachary <l...@dachary.org>
Gerrit-Reviewer: Dachary <l...@dachary.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to