/usr/share/pyshared/simpleparse/tests/test_common_strings.py is in python-simpleparse 2.1.0a1-6build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import unittest, string
from simpleparse.parser import Parser
from simpleparse.common import strings
from simpleparse import dispatchprocessor
parseTests = [
# each production should match the whole of all of the first,
# and not match any of the second...
("string_triple_single", [
"""'''this and that'''""",
"""'''this \\''' '''""",
"""''''''""",
"""''''\\''''""",
],[]),
("string_triple_double", [
'''"""this and that"""''',
'''"""this \\""" """''',
'''""""""''',
'''""""\\""""''',
],[]),
("string_double_quote", [
'"\\p"',
'"\\""',
],[]),
("string",[
"'this'",
'"that"',
r'"\b\f\n\r"',
r'"\x32\xff\xcf"',
r'"\032\033\055\077"',
r'"\t\v\\\a\b\f\n\r"',
r'"\t"',
r'"\v"',
r'"\""',
], []),
]
class CommonTests(unittest.TestCase):
def testBasic( self ):
proc = dispatchprocessor.DispatchProcessor()
setattr(proc, "string", strings.StringInterpreter())
for production, yestable, notable in parseTests:
p = Parser( "x := %s"%production, 'x')
for data in yestable:
if production == 'string':
success, results, next = p.parse( data, processor=proc)
else:
success, results, next = p.parse( data)
assert success and (next == len(data)), """Did not parse string %s as a %s result=%s"""%( repr(data), production, (success, results, next))
assert results, """Didn't get any results for string %s as a %s result=%s"""%( repr(data), production, (success, results, next))
if production == 'string':
expected = eval( data, {},{})
assert results[0] == expected, """Got different interpreted value for data %s, we got %s, expected %s"""%( repr(data), repr(results[0]), repr(expected))
for data in notable:
success, results, next = p.parse( data)
assert not success, """Parsed %s of %s as a %s result=%s"""%( repr(data), production, (success, results, next))
def getSuite():
return unittest.makeSuite(CommonTests, 'test')
if __name__ == "__main__":
unittest.main(defaultTest="getSuite")
|