#!/bin/sh

# this shell script simply creates 
# mydecorator.py and test.py in the current
# directory. It then executes "python test.py"

echo "creating 'mydecorator.py'..."

cat > mydecorator.py <<END
# mydecorator.py
import functools

def simplelog(f):
    @functools.wraps(f)
    def new_f(*args, **kwds):
        print "Wrapper calling func"
        return f(*args, **kwds)
    return new_f

END

echo "creating 'test.py'..."

cat > test.py << END
# test.py
from mydecorator import simplelog

@simplelog
def test():
    """decorated function.

    This test should fail since the expected 
    output is different from the actual one
    >>> test()
    'works!'
    """
    return "works not"

def test2():
    """undecorated function.

    This test should fail since the expected 
    output is different from the actual one
    >>> test2()
    'works!'
    """
    return "works not"

if __name__ == '__main__':
    import doctest
    doctest.testmod()


END

echo "performing the test:"
echo "python test.py"
python test.py

echo "-------------------------------------"
echo "test() should have failed too but it does not due"
echo "to the usage of a decorator defined in a separate file"

