Back to index

moin  1.9.0~rc2
Public Member Functions
MoinMoin._tests.test_wikiutil.TestParmeterParser Class Reference

List of all members.

Public Member Functions

def testParameterParser
def testTooMuchWantedArguments
def testMalformedArguments
def testWrongTypeFixedPosArgument
def testWrongTypeNamedArgument

Detailed Description

Definition at line 126 of file test_wikiutil.py.


Member Function Documentation

Definition at line 190 of file test_wikiutil.py.

00190 
00191     def testMalformedArguments(self):
00192         args = '='
00193         argParser = wikiutil.ParameterParser("%(width)s%(height)s")
00194         py.test.raises(ValueError, argParser.parse_parameters, args)

Definition at line 128 of file test_wikiutil.py.

00128 
00129     def testParameterParser(self):
00130         tests = [
00131             # trivial
00132             ('', '', 0, {}),
00133 
00134             # fixed
00135             ('%s%i%f%b', '"test",42,23.0,True', 4, {0: 'test', 1: 42, 2: 23.0, 3: True}),
00136 
00137             # fixed and named
00138             ('%s%(x)i%(y)i', '"test"', 1, {0: 'test', 'x': None, 'y': None}),
00139             ('%s%(x)i%(y)i', '"test",1', 1, {0: 'test', 'x': 1, 'y': None}),
00140             ('%s%(x)i%(y)i', '"test",1,2', 1, {0: 'test', 'x': 1, 'y': 2}),
00141             ('%s%(x)i%(y)i', '"test",x=1', 1, {0: 'test', 'x': 1, 'y': None}),
00142             ('%s%(x)i%(y)i', '"test",x=1,y=2', 1, {0: 'test', 'x': 1, 'y': 2}),
00143             ('%s%(x)i%(y)i', '"test",y=2', 1, {0: 'test', 'x': None, 'y': 2}),
00144 
00145             # test mixed acceptance
00146             ("%ifs", '100', 1, {0: 100}),
00147             ("%ifs", '100.0', 1, {0: 100.0}),
00148             ("%ifs", '"100"', 1, {0: "100"}),
00149 
00150             # boolean
00151             ("%(t)b%(f)b", '', 0, {'t': None, 'f': None}),
00152             ("%(t)b%(f)b", 't=1', 0, {'t': True, 'f': None}),
00153             ("%(t)b%(f)b", 'f=False', 0, {'t': None, 'f': False}),
00154             ("%(t)b%(f)b", 't=True, f=0', 0, {'t': True, 'f': False}),
00155 
00156             # integer
00157             ("%(width)i%(height)i", '', 0, {'width': None, 'height': None}),
00158             ("%(width)i%(height)i", 'width=100', 0, {'width': 100, 'height': None}),
00159             ("%(width)i%(height)i", 'height=200', 0, {'width': None, 'height': 200}),
00160             ("%(width)i%(height)i", 'width=100, height=200', 0, {'width': 100, 'height': 200}),
00161 
00162             # float
00163             ("%(width)f%(height)f", '', 0, {'width': None, 'height': None}),
00164             ("%(width)f%(height)f", 'width=100.0', 0, {'width': 100.0, 'height': None}),
00165             ("%(width)f%(height)f", 'height=2.0E2', 0, {'width': None, 'height': 200.0}),
00166             ("%(width)f%(height)f", 'width=1000.0E-1, height=200.0', 0, {'width': 100.0, 'height': 200.0}),
00167 
00168             # string
00169             ("%(width)s%(height)s", '', 0, {'width': None, 'height': None}),
00170             ("%(width)s%(height)s", 'width="really wide"', 0, {'width': 'really wide', 'height': None}),
00171             ("%(width)s%(height)s", 'height="not too high"', 0, {'width': None, 'height': 'not too high'}),
00172             ("%(width)s%(height)s", 'width="really wide", height="not too high"', 0, {'width': 'really wide', 'height': 'not too high'}),
00173             # conversion from given type to expected type
00174             ("%(width)s%(height)s", 'width=100', 0, {'width': '100', 'height': None}),
00175             ("%(width)s%(height)s", 'width=100, height=200', 0, {'width': '100', 'height': '200'}),
00176 
00177             # complex test
00178             ("%i%sf%s%ifs%(a)s|%(b)s", ' 4,"DI\'NG", b=retry, a="DING"', 2, {0: 4, 1: "DI'NG", 'a': 'DING', 'b': 'retry'}),
00179 
00180             ]
00181         for format, args, expected_fixed_count, expected_dict in tests:
00182             argParser = wikiutil.ParameterParser(format)
00183             fixed_count, arg_dict = argParser.parse_parameters(args)
00184             assert (fixed_count, arg_dict) == (expected_fixed_count, expected_dict)

Definition at line 185 of file test_wikiutil.py.

00185 
00186     def testTooMuchWantedArguments(self):
00187         args = 'width=100, height=200, alt=Example'
00188         argParser = wikiutil.ParameterParser("%(width)s%(height)s")
00189         py.test.raises(ValueError, argParser.parse_parameters, args)

Definition at line 195 of file test_wikiutil.py.

00195 
00196     def testWrongTypeFixedPosArgument(self):
00197         args = '0.0'
00198         argParser = wikiutil.ParameterParser("%b")
00199         py.test.raises(ValueError, argParser.parse_parameters, args)

Definition at line 200 of file test_wikiutil.py.

00200 
00201     def testWrongTypeNamedArgument(self):
00202         args = 'flag=0.0'
00203         argParser = wikiutil.ParameterParser("%(flag)b")
00204         py.test.raises(ValueError, argParser.parse_parameters, args)
00205 


The documentation for this class was generated from the following file: