Back to index

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

List of all members.

Public Member Functions

def testMacroArgs
def testLimited
def testDoubleNameValueSeparator
def testNoNameValue
def testUnitArgument
def testExtendedParser
def testExtendedParserBracketing
def testExtendedParserQuoting
def testExtendedParserMultikey
def testExtendedParserPrefix
def testExtendedParserBracketingErrors

Detailed Description

Definition at line 206 of file test_wikiutil.py.


Member Function Documentation

Definition at line 291 of file test_wikiutil.py.

00291 
00292     def testDoubleNameValueSeparator(self):
00293         tests = [
00294                   # regular and quoting tests
00295                   (u'd==4,=3 ',    ([], {u'd': u'=4', u'': u'3'}, [])),
00296                   (u'===a,b,c,d',  ([], {u'': u'==a'}, [u'b', u'c', u'd'])),
00297                   (u'a,b,===,c,d', ([u'a', u'b'], {u'': u'=='}, [u'c', u'd'])),
00298                 ]
00299 
00300         def _check(a, e):
00301             r = wikiutil.parse_quoted_separated(a)
00302             assert r == e
00303 
00304         for args, expected in tests:
00305             yield _check, args, expected

Here is the call graph for this function:

Definition at line 338 of file test_wikiutil.py.

00338 
00339     def testExtendedParser(self):
00340         tests = [
00341             (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
00342             (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00343             (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
00344             (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
00345             (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00346             (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
00347             (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00348             (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
00349             (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
00350             (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00351             (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
00352             (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
00353             (u'"a  " "b" "c"', None, None, [u'a  ', u'b', u'c']),
00354             (u'"  a" "b" "c"', None, None, [u'  a', u'b', u'c']),
00355             (u'"  a" "b" "c"', None, u':', [u'  a', u'b', u'c']),
00356             (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
00357             (u'   a:a  ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
00358             (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
00359             (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
00360             (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
00361             (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
00362             (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
00363             (u'a:b:c d:e:f', None, u':', [(u'a', u'b:c'), (u'd', 'e:f')]),
00364             (u'a:b:c:d', None, u':', [(u'a', u'b:c:d')]),
00365         ]
00366 
00367         def _check(args, sep, kwsep, expected):
00368             res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep)
00369             assert res == expected
00370 
00371         for test in tests:
00372             yield [_check] + list(test)

Here is the call graph for this function:

Definition at line 373 of file test_wikiutil.py.

00373 
00374     def testExtendedParserBracketing(self):
00375         tests = [
00376             (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
00377             (u'("a", "b", "c")', u',', None, [[u'(', u'a', u'b', u'c']]),
00378             (u'("a"("b", "c"))', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
00379             (u'("a"("b)))", "c"))', u',', None, [[u'(', u'a', [u'(', u'b)))', u'c']]]),
00380             (u'("a"("b>>> ( ab )>", "c"))', u',', None, [[u'(', u'a', [u'(', u'b>>> ( ab )>', u'c']]]),
00381             (u'("a" ("b" "c"))', None, None, [[u'(', u'a', [u'(', u'b', u'c']]]),
00382             (u'("a"("b", "c") ) ', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
00383             (u'("a", <"b", ("c")>)', u',', None, [[u'(', u'a', [u'<', u'b', [u'(', u'c']]]]),
00384             (u',,,(a, b, c)', u',', None, [None, None, None, [u'(', u'a', u'b', u'c']]),
00385         ]
00386 
00387         def _check(args, sep, kwsep, expected):
00388             res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, brackets=(u'<>', u'()'))
00389             assert res == expected
00390 
00391         for test in tests:
00392             yield [_check] + list(test)

Here is the call graph for this function:

Definition at line 493 of file test_wikiutil.py.

00493 
00494     def testExtendedParserBracketingErrors(self):
00495         UCE = wikiutil.BracketUnexpectedCloseError
00496         MCE = wikiutil.BracketMissingCloseError
00497         tests = [
00498             (u'("a", "b", "c"', u',', None, MCE),
00499             (u'("a"("b", "c")', u',', None, MCE),
00500             (u'("a"<"b", "c")>', u',', None, UCE),
00501             (u')("a" ("b" "c"))', None, None, UCE),
00502             (u'("a", ("b", "c">))', u',', None, UCE),
00503             (u'("a", ("b", <"c">>))', u',', None, UCE),
00504             (u'(<(<)>)>', u',', None, UCE),
00505         ]
00506 
00507         def _check(args, sep, kwsep, err):
00508             py.test.raises(err,
00509                            wikiutil.parse_quoted_separated_ext,
00510                            args, sep, kwsep,
00511                            brackets=(u'<>', u'()'))
00512 
00513         for test in tests:
00514             yield [_check] + list(test)

Here is the call graph for this function:

Definition at line 409 of file test_wikiutil.py.

00409 
00410     def testExtendedParserMultikey(self):
00411         tests = [
00412             (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
00413             (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00414             (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
00415             (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
00416             (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00417             (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
00418             (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00419             (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
00420             (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
00421             (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00422             (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
00423             (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
00424             (u'"a  " "b" "c"', None, None, [u'a  ', u'b', u'c']),
00425             (u'"  a" "b" "c"', None, None, [u'  a', u'b', u'c']),
00426             (u'"  a" "b" "c"', None, u':', [u'  a', u'b', u'c']),
00427             (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
00428             (u'   a:a  ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
00429             (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
00430             (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
00431             (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
00432             (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
00433             (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
00434             (u'a:b:c d:e:f', None, u':', [(u'a', u'b', u'c'), (u'd', 'e', u'f')]),
00435             (u'a:b:c:d', None, u':', [(u'a', u'b', u'c', u'd')]),
00436             (u'a:"b:c":d', None, u':', [(u'a', u'b:c', u'd')]),
00437         ]
00438 
00439         def _check(args, sep, kwsep, expected):
00440             res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, multikey=True)
00441             assert res == expected
00442 
00443         for test in tests:
00444             yield [_check] + list(test)

Here is the call graph for this function:

Definition at line 445 of file test_wikiutil.py.

00445 
00446     def testExtendedParserPrefix(self):
00447         P = wikiutil.ParserPrefix('+')
00448         M = wikiutil.ParserPrefix('-')
00449         tests = [
00450             (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
00451             (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00452             (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
00453             (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
00454             (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00455             (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
00456             (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00457             (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
00458             (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
00459             (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
00460             (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
00461             (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
00462             (u'"a  " "b" "c"', None, None, [u'a  ', u'b', u'c']),
00463             (u'"  a" "b" "c"', None, None, [u'  a', u'b', u'c']),
00464             (u'"  a" "b" "c"', None, u':', [u'  a', u'b', u'c']),
00465             (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
00466             (u'   a:a  ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
00467             (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
00468             (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
00469             (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
00470             (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
00471             (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
00472             (u'a:b:c d:e:f', None, u':', [(u'a', u'b', u'c'), (u'd', 'e', u'f')]),
00473             (u'a:b:c:d', None, u':', [(u'a', u'b', u'c', u'd')]),
00474             (u'a:"b:c":d', None, u':', [(u'a', u'b:c', u'd')]),
00475 
00476             (u'-a:b:d', None, u':', [(M, u'a', u'b', u'd')]),
00477             (u'"-a:b:d"', None, u':', [(u'-a:b:d')]),
00478             (u'-"a:b:d"', None, u':', [(M, u'a:b:d')]),
00479             (u'-a:"b:c":"d e f g"', None, u':', [(M, u'a', u'b:c', u'd e f g')]),
00480             (u'+-a:b:d', None, u':', [(P, u'-a', u'b', u'd')]),
00481             (u'-"+a:b:d"', None, u':', [(M, u'+a:b:d')]),
00482             # bit of a weird case...
00483             (u'-+"a:b:d"', None, u':', [(M, u'+"a', u'b', u'd"')]),
00484             (u'-a:"b:c" a +b', None, u':', [(M, u'a', u'b:c'), u'a', (P, u'b')]),
00485         ]
00486 
00487         def _check(args, sep, kwsep, expected):
00488             res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, multikey=True, prefixes='-+')
00489             assert res == expected
00490 
00491         for test in tests:
00492             yield [_check] + list(test)

Here is the call graph for this function:

Definition at line 393 of file test_wikiutil.py.

00393 
00394     def testExtendedParserQuoting(self):
00395         tests = [
00396             (u'"a b" -a b-', u'"', [u'a b', u'-a', u'b-']),
00397             (u'"a b" -a b-', u"-", [u'"a', u'b"', u'a b']),
00398             (u'"a b" -a b-', u'"-', [u'a b', u'a b']),
00399             (u'"a- b" -a b-', u'"-', [u'a- b', u'a b']),
00400             (u'"a- b" -a" b-', u'"-', [u'a- b', u'a" b']),
00401         ]
00402 
00403         def _check(args, quotes, expected):
00404             res = wikiutil.parse_quoted_separated_ext(args, quotes=quotes)
00405             assert res == expected
00406 
00407         for test in tests:
00408             yield [_check] + list(test)

Here is the call graph for this function:

Definition at line 271 of file test_wikiutil.py.

00271 
00272     def testLimited(self):
00273         tests = [
00274                   # regular and quoting tests
00275                   (u'd = 4,c=3,b=2,a= 1 ',    ([], {u'd': u'4',
00276                                                     u'c': u'3,b=2,a= 1'}, [])),
00277                   (u'a,b,c,d',                ([u'a', u'b,c,d'], {}, [])),
00278                   (u'a=b,b,c,d',              ([], {u'a': u'b'}, [u'b,c,d'])),
00279                 ]
00280         for args, expected in tests:
00281             result = wikiutil.parse_quoted_separated(args, seplimit=1)
00282             assert expected == result
00283             for val in result[0]:
00284                 assert val is None or isinstance(val, unicode)
00285             for val in result[1].keys():
00286                 assert val is None or isinstance(val, unicode)
00287             for val in result[1].values():
00288                 assert val is None or isinstance(val, unicode)
00289             for val in result[2]:
00290                 assert val is None or isinstance(val, unicode)

Definition at line 207 of file test_wikiutil.py.

00207 
00208     def testMacroArgs(self):
00209         abcd = [u'a', u'b', u'c', u'd']
00210         abcd_dict = {u'a': u'1', u'b': u'2', u'c': u'3', u'd': u'4'}
00211         tests = [
00212                   # regular and quoting tests
00213                   (u'd = 4,c=3,b=2,a= 1 ',    ([], abcd_dict, [])),
00214                   (u'a,b,c,d',                (abcd, {}, [])),
00215                   (u' a , b , c , d ',        (abcd, {}, [])),
00216                   (u'   a   ',                ([u'a'], {}, [])),
00217                   (u'"  a  "',                ([u'  a  '], {}, [])),
00218                   (u'a,b,c,d, "a,b,c,d"',     (abcd+[u'a,b,c,d'], {}, [])),
00219                   (u'quote " :), b',          ([u'quote " :)', u'b'], {}, [])),
00220                   (u'"quote "" :)", b',       ([u'quote " :)', u'b'], {}, [])),
00221                   (u'=7',                     ([], {u'': u'7'}, [])),
00222                   (u',,',                     ([None, None, None], {}, [])),
00223                   (u',"",',                   ([None, u'', None], {}, [])),
00224                   (u',"", ""',                ([None, u'', u''], {}, [])),
00225                   (u'  ""  ,"", ""',          ([u'', u'', u''], {}, [])),
00226                   # some name=value test
00227                   (u'd = 4,c=3,b=2,a= 1 ',    ([], abcd_dict, [])),
00228                   (u'd=d,e="a,b,c,d"',        ([], {u'd': u'd',
00229                                                     u'e': u'a,b,c,d'}, [])),
00230                   (u'd = d,e = "a,b,c,d"',    ([], {u'd': u'd',
00231                                                     u'e': u'a,b,c,d'}, [])),
00232                   (u'd = d, e = "a,b,c,d"',   ([], {u'd': u'd',
00233                                                     u'e': u'a,b,c,d'}, [])),
00234                   (u'd = , e = "a,b,c,d"',    ([], {u'd': None,
00235                                                     u'e': u'a,b,c,d'}, [])),
00236                   (u'd = "", e = "a,b,c,d"',  ([], {u'd': u'',
00237                                                     u'e': u'a,b,c,d'}, [])),
00238                   (u'd = "", e = ',           ([], {u'd': u'', u'e': None},
00239                                                [])),
00240                   (u'd=""',                   ([], {u'd': u''}, [])),
00241                   (u'd = "", e = ""',         ([], {u'd': u'', u'e': u''},
00242                                                [])),
00243                   # no, None as key isn't accepted
00244                   (u' = "",  e = ""',         ([], {u'': u'', u'e': u''},
00245                                                [])),
00246                   # can quote both name and value:
00247                   (u'd = d," e "= "a,b,c,d"', ([], {u'd': u'd',
00248                                                     u' e ': u'a,b,c,d'}, [])),
00249                   # trailing args
00250                   (u'1,2,a=b,3,4',            ([u'1', u'2'], {u'a': u'b'},
00251                                                [u'3', u'4'])),
00252                   # can quote quotes:
00253                   (u'd = """d"',              ([], {u'd': u'"d'}, [])),
00254                   (u'd = """d"""',            ([], {u'd': u'"d"'}, [])),
00255                   (u'd = "d"" ", e=7',        ([], {u'd': u'd" ', u'e': u'7'},
00256                                                [])),
00257                   (u'd = "d""", e=8',         ([], {u'd': u'd"', u'e': u'8'},
00258                                                [])),
00259                 ]
00260         for args, expected in tests:
00261             result = wikiutil.parse_quoted_separated(args)
00262             assert expected == result
00263             for val in result[0]:
00264                 assert val is None or isinstance(val, unicode)
00265             for val in result[1].keys():
00266                 assert val is None or isinstance(val, unicode)
00267             for val in result[1].values():
00268                 assert val is None or isinstance(val, unicode)
00269             for val in result[2]:
00270                 assert val is None or isinstance(val, unicode)

Definition at line 306 of file test_wikiutil.py.

00306 
00307     def testNoNameValue(self):
00308         abcd = [u'a', u'b', u'c', u'd']
00309         tests = [
00310                   # regular and quoting tests
00311                   (u'd = 4,c=3,b=2,a= 1 ',    [u'd = 4', u'c=3',
00312                                                u'b=2', u'a= 1']),
00313                   (u'a,b,c,d',                abcd),
00314                   (u' a , b , c , d ',        abcd),
00315                   (u'   a   ',                [u'a']),
00316                   (u'"  a  "',                [u'  a  ']),
00317                   (u'a,b,c,d, "a,b,c,d"',     abcd + [u'a,b,c,d']),
00318                   (u'quote " :), b',          [u'quote " :)', u'b']),
00319                   (u'"quote "" :)", b',       [u'quote " :)', u'b']),
00320                   (u'"unended quote',         [u'"unended quote']),
00321                   (u'"',                      [u'"']),
00322                   (u'd=d,e="a,b,c,d"',        [u'd=d', u'e="a', u'b',
00323                                                u'c', u'd"']),
00324                 ]
00325         for args, expected in tests:
00326             result = wikiutil.parse_quoted_separated(args, name_value=False)
00327             assert expected == result
00328             for val in result:
00329                 assert val is None or isinstance(val, unicode)

Definition at line 330 of file test_wikiutil.py.

00330 
00331     def testUnitArgument(self):
00332         result = wikiutil.UnitArgument('7mm', float, ['%', 'mm'])
00333         assert result.get_default() ==  (7.0, 'mm')
00334         assert result.parse_argument('8%') == (8.0, '%')
00335         py.test.raises(ValueError, result.parse_argument,  u'7m')
00336         py.test.raises(ValueError, result.parse_argument,  u'7')
00337         py.test.raises(ValueError, result.parse_argument,  u'mm')


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