http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11698
Revision: 11698 Author: legoktm Date: 2013-06-28 07:54:39 +0000 (Fri, 28 Jun 2013) Log Message: ----------- Convert to unittest module, all tests currently passing
Modified Paths: -------------- branches/rewrite/tests/dry_site_tests.py
Modified: branches/rewrite/tests/dry_site_tests.py =================================================================== --- branches/rewrite/tests/dry_site_tests.py 2013-06-28 02:24:51 UTC (rev 11697) +++ branches/rewrite/tests/dry_site_tests.py 2013-06-28 07:54:39 UTC (rev 11698) @@ -1,28 +1,33 @@ import pywikibot +import unittest
+ class DrySite(pywikibot.site.APISite): @property def userinfo(self): return self._userinfo
-def test_logged_in(): - x = DrySite('en') - - x._userinfo = {'name': None, 'groups': []} - x._username = ['normal_user', 'sysop_user']
- assert not x.logged_in(True) - assert not x.logged_in(False) - - x._userinfo['name'] = 'normal_user' - assert not x.logged_in(True) - assert x.logged_in(False) - - x._userinfo['name'] = 'sysop_user' - x._userinfo['groups'] = ['sysop'] - assert x.logged_in(True) - assert not x.logged_in(False) +class TestDrySite(unittest.TestCase): + def test_logged_in(self): + x = DrySite('en')
+ x._userinfo = {'name': None, 'groups': []} + x._username = ['normal_user', 'sysop_user'] + + self.assertFalse(x.logged_in(True)) + self.assertFalse(x.logged_in(False)) + + x._userinfo['name'] = 'normal_user' + self.assertFalse(x.logged_in(True)) + self.assertTrue(x.logged_in(False)) + + x._userinfo['name'] = 'sysop_user' + x._userinfo['groups'] = ['sysop'] + self.assertTrue(x.logged_in(True)) + self.assertFalse(x.logged_in(False)) + + class SiteMock(object): last_login = None last_fn_called = False @@ -32,20 +37,23 @@
def inner_fn(self, *args, **kwargs): self.last_fn_called = (args, kwargs) - return (args, kwargs) + return args, kwargs
-def test_must_be_user(): - x = SiteMock() - wrapped_inner = pywikibot.site.must_be(group='user')(x.inner_fn) - assert(wrapped_inner(x,1,2,3,a='a', b='b') == ((x,1,2,3), {'a': 'a', 'b': 'b'})) - assert(x.last_fn_called == ((x,1,2,3), {'a': 'a', 'b': 'b'})) - assert(x.last_login == 'user')
-def test_must_be_sysop(): - x = SiteMock() - wrapped_inner = pywikibot.site.must_be(group='sysop')(x.inner_fn) - assert(wrapped_inner(x,1,2,3,a='a', b='b') == ((x,1,2,3), {'a': 'a', 'b': 'b'})) - assert(x.last_fn_called == ((x,1,2,3), {'a': 'a', 'b': 'b'})) - assert(x.last_login == 'sysop') +class TestSiteMock(unittest.TestCase): + def test_must_be_user(self): + x = SiteMock() + wrapped_inner = pywikibot.site.must_be(group='user')(x.inner_fn) + self.assertEqual(wrapped_inner(x,1,2,3,a='a', b='b'), ((x,1,2,3), {'a': 'a', 'b': 'b'})) + self.assertEqual(x.last_fn_called, ((x,1,2,3), {'a': 'a', 'b': 'b'})) + self.assertEqual(x.last_login, 'user')
+ def test_must_be_sysop(self): + x = SiteMock() + wrapped_inner = pywikibot.site.must_be(group='sysop')(x.inner_fn) + self.assertEqual(wrapped_inner(x,1,2,3,a='a', b='b'), ((x,1,2,3), {'a': 'a', 'b': 'b'})) + self.assertEqual(x.last_fn_called, ((x,1,2,3), {'a': 'a', 'b': 'b'})) + self.assertEqual(x.last_login, 'sysop')
+if __name__ == '__main__': + unittest.main()
pywikipedia-svn@lists.wikimedia.org