Back to index

moin  1.9.0~rc2
test_util.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     MoinMoin - MoinMoin.util Tests
00004 
00005     @copyright: 2007 MoinMoin:ThomasWaldmann
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 from MoinMoin import util
00010 
00011 class TestUtil:
00012 
00013     def testRangeList(self):
00014         """ util.rangelist: test correct function for misc. input values """
00015         result = util.rangelist([])
00016         expected = ''
00017         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00018 
00019         result = util.rangelist([42])
00020         expected = '42'
00021         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00022 
00023         result = util.rangelist([42, 23])
00024         expected = '23,42'
00025         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00026 
00027         result = util.rangelist([1, 2, 3, 4, 5])
00028         expected = '1-5'
00029         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00030 
00031         result = util.rangelist([2, 5, 3])
00032         expected = '2-3,5'
00033         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00034 
00035         result = util.rangelist([2, 3, 5, 6])
00036         expected = '2-3,5-6'
00037         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00038 
00039         result = util.rangelist([2, 3, 5, 6, 23, 100, 101, 102, 104])
00040         expected = '2-3,5-6,23,100-102,104'
00041         assert result == expected, ('Expected "%(expected)s" but got "%(result)s"') % locals()
00042 
00043     def testRandomString(self):
00044         """ util.random_string: test randomness and length """
00045         length = 8
00046         result1 = util.random_string(length)
00047         result2 = util.random_string(length)
00048         assert result1 != result2, ('Expected different random strings, but got "%(result1)s" and "%(result2)s"') % locals()
00049 
00050         result = len(util.random_string(length))
00051         expected = length
00052         assert result == expected, ('Expected length "%(expected)s" but got "%(result)s"') % locals()
00053 
00054 coverage_modules = ['MoinMoin.util']