#!/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: using `python -V`"
echo "expecting 2 failures."
python test.py
echo
echo '--------------------'
echo "performing the test: using `python2 -V`"
echo "expecting 2 failures."
python2 test.py

