Revision: 7978 Author: valhallasw Date: 2010-03-05 23:38:35 +0000 (Fri, 05 Mar 2010)
Log Message: ----------- Added basic unit test for _GetAllUI.getData(). Changed userlib.py to use these tests.
Modified Paths: -------------- trunk/pywikipedia/userlib.py
Added Paths: ----------- trunk/pywikipedia/tests/test_userlib.py
Added: trunk/pywikipedia/tests/test_userlib.py =================================================================== --- trunk/pywikipedia/tests/test_userlib.py (rev 0) +++ trunk/pywikipedia/tests/test_userlib.py 2010-03-05 23:38:35 UTC (rev 7978) @@ -0,0 +1,35 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +"""Unit tests for userlib.py""" +__version__ = '$Id$' + +import unittest +import test_utils + +import userlib +import wikipedia + +class _GetAllUI(unittest.TestCase): + def setUp(self): + self.site = wikipedia.getSite('en', 'wikipedia') + self.obj = userlib._GetAllUI(self.site, + [userlib.User(self.site, "Example")], + None, + False) + + def testGetData(self): + data = self.obj.getData() + expecteddata = { + u'Example': { + u'editcount': 1, + u'name': u'Example', + u'gender': u'unknown', + u'blockedby': u'AGK', + u'blockreason': u"Example account. (Restoring [[User:CesarB|CesarB]]'s previous block: my test is complete.)", + u'registration': u'2005-03-19T00:17:19Z'} + } + self.assertEqual(data, expecteddata); + +if __name__ == "__main__": + unittest.main()
Property changes on: trunk/pywikipedia/tests/test_userlib.py ___________________________________________________________________ Added: svn:executable + *
Modified: trunk/pywikipedia/userlib.py =================================================================== --- trunk/pywikipedia/userlib.py 2010-03-05 23:38:33 UTC (rev 7977) +++ trunk/pywikipedia/userlib.py 2010-03-05 23:38:35 UTC (rev 7978) @@ -619,11 +619,17 @@ """ Simple testing code for the [[User:Example]] on the English Wikipedia. """ - try: - Site = wikipedia.getSite() - exampleUser = User(Site, 'Example') - wikipedia.output(exampleUser.getUserPage().get()) - wikipedia.output(exampleUser.getUserPage('Lipsum').get()) - wikipedia.output(exampleUser.getUserTalkPage().get()) - finally: - wikipedia.stopme() + wikipedia.output(""" + This module is not for direct usage from the command prompt. + In code, the usage is as follows: + + >>> exampleUser = User("en", 'Example') + >>> wikipedia.output(exampleUser.getUserPage().get()) + >>> wikipedia.output(exampleUser.getUserPage('Lipsum').get()) + >>> wikipedia.output(exampleUser.getUserTalkPage().get()) + """) + + # unit tests + import tests.test_userlib + import unittest + unittest.main(tests.test_userlib)