jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/566466 )
Change subject: [IMPR] Simplify randomly choice ......................................................................
[IMPR] Simplify randomly choice
use random.sample to chose list of unique elements
Change-Id: I16c4890c7749215ebc7bba99e1d24635000fdbfc --- M tests/generate_family_files_tests.py 1 file changed, 3 insertions(+), 12 deletions(-)
Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/generate_family_files_tests.py b/tests/generate_family_files_tests.py index e8471ac..e5d1aad 100644 --- a/tests/generate_family_files_tests.py +++ b/tests/generate_family_files_tests.py @@ -7,7 +7,7 @@ # from __future__ import absolute_import, division, unicode_literals
-from random import choice +from random import sample
from pywikibot import Site from pywikibot.tools import PY2 @@ -29,17 +29,8 @@ def getapis(self): """Only load additional ten additional different wikis randomly.""" save = self.langs - seen = set() - self.langs = [] - - while len(seen) < 10: - new = choice(save) - key = new['prefix'] - if key not in seen: - seen.add(key) - self.langs.append(new) - - self.prefixes = list(seen) + self.langs = sample(save, 10) + self.prefixes = [item['prefix'] for item in self.langs] super(FamilyTestGenerator, self).getapis() self.langs = save
pywikibot-commits@lists.wikimedia.org