"Valhallasw" posted a comment on pywikipedia.r10152.
URL: http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10152#c32788
Commit summary for pywikipedia.r10152:
Adding categories sort for Persian Wikipedia
Valhallasw's comment:
Two more issues:
a) The right part of your or is untested: 'title' is not defined anywhere, so
the code cannot work!
b) You should split off the logic into a seperate function; i.e.:
<pre>
=====
if self.site.language() == 'fa':
categories = self._fawikisort(categories)
=====
def _fawikisort(self, categories):
categories.sort()
#Taking main cats to top
for name in categories:
if self._fawikisort_maincat(name):
categories.remove(name)
categories.insert(0, name)
return categories
def _fawikisort_maincat(self, cat):
return re.search(u"(.+?)\|(.{,1}?)", cat.title()) or \
cat.title()==cat.title().split(":")[0]+title
====
</pre>
Then you can easily test the _fawikisort_maincat function:
<pre>
cct = CosmeticChangesToolkit(pywikibot.getSite())
assert(cct._fawikisort_maincat("category name that should be on top"))
assert(not cct._fawikisort_maincat("category name that should not be on top"))
</pre>
If you can do the following:
a) make sure the code actually works!
b) provide examples of input with expected output (for the category list)
I can help you with splitting off the functions and adding tests for them.
_______________________________________________
MediaWiki-CodeReview mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview