view tests/test-check-code @ 11988:8380ed691df8

util: add an interpolate() function to for replacing multiple values util.interpolate can be used to replace multiple items in a string all at once (and optionally apply a function to the replacement), without worrying about recursing: >>> import util >>> s = '$foo, $spam' >>> util.interpolate(r'\$', { 'foo': 'bar', 'spam': 'eggs' }, s) 'bar, eggs' >>> util.interpolate(r'\$', { 'foo': 'spam', 'spam': 'foo' }, s) 'spam, foo' >>> util.interpolate(r'\$', { 'foo': 'spam', 'spam': 'foo' }, s, lambda s: s.upper()) 'SPAM, FOO' The patch also changes filemerge.py to use this new function.
author Steve Losh <steve@stevelosh.com>
date Wed, 18 Aug 2010 18:18:26 -0400
parents 0cae834cdc80
children
line wrap: on
line source

#!/bin/sh
#cd `dirname $0`
cat > correct.py <<EOF
def toto(arg1, arg2):
    del arg2
    return (5 + 6, 9)
EOF

cat > wrong.py <<EOF
def toto( arg1, arg2):
    del(arg2)
    return ( 5+6, 9)
EOF

cat > quote.py <<EOF
# let's use quote in comments
(''' ( 4x5 )
but """\\''' and finally''',
"""let's fool checkpatch""", '1+2',
'"""', 42+1, """and
( 4-1 ) """, "( 1+1 )\" and ")
a, '\\\\\\\\', "\\\\\\" x-2", "c-1"
EOF

cat > non-py24.py <<EOF
# Using builtins that does not exist in Python 2.4
if any():
    x = all()
    y = format(x)

# Do not complain about our own definition
def any(x):
    pass
EOF

check_code=`dirname $0`/../contrib/check-code.py
${check_code} ./wrong.py ./correct.py ./quote.py ./non-py24.py

exit 0