Dachary has uploaded a new change for review.

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

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, 9 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/bots/FLOSSbot 
refs/changes/97/315697/1

diff --git a/FLOSSbot/plugin.py b/FLOSSbot/plugin.py
index 6f86d7b..4ea4402 100644
--- a/FLOSSbot/plugin.py
+++ b/FLOSSbot/plugin.py
@@ -104,6 +104,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 +117,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: newchange
Gerrit-Change-Id: I0968477939d7226a35ba27f2c29e39b358a84976
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/bots/FLOSSbot
Gerrit-Branch: master
Gerrit-Owner: Dachary <l...@dachary.org>

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

Reply via email to