@@ -0,0 +1,2713 @@
+from fudge.patcher import with_patched_object%0Afrom functools import wraps%0Afrom nose.tools import eq_%0A%0Afrom nose.tools import raises%0Afrom fabric.state import output%0Afrom fabric.utils import warn, indent, abort%0Aimport sys%0Afrom StringIO import StringIO%0A%0A#%0A# Setup/teardown helpers and decorators%0A#%0A%0Adef mock_streams(*which):%0A    %22%22%22%0A    Replaces %60%60sys.stderr%60%60 with a %60%60StringIO%60%60 during the test, then restores%0A    after.%0A%0A    Must specify which stream via string args, e.g.::%0A%0A        @mock_streams('stdout')%0A        def func():%0A            pass%0A%0A        @mock_streams('stderr')%0A        def func():%0A            pass%0A%0A        @mock_streams('stdout', 'stderr')%0A        def func()%0A            pass%0A    %22%22%22%0A    def mocked_streams_decorator(func):%0A        @wraps(func)%0A        def inner_wrapper(*args, **kwargs):%0A            if 'stdout' in which:%0A                my_stdout, sys.stdout = sys.stdout, StringIO()%0A            if 'stderr' in which:%0A                my_stderr, sys.stderr = sys.stderr, StringIO()%0A            result = func(*args, **kwargs)%0A            if 'stderr' in which:%0A                sys.stderr = my_stderr%0A            if 'stdout' in which:%0A                sys.stdout = my_stdout%0A            return result%0A        return inner_wrapper%0A    return mocked_streams_decorator%0A%0A@mock_streams('stderr')%0A@with_patched_object(output, 'warnings', True)%0Adef test_warn():%0A    warn(%22Test%22)%0A    result = sys.stderr.getvalue()%0A    assert %22%5CnWarning: Test%5Cn%5Cn%22 == result%0A%0Adef test_indent():%0A    for description, input, output in (%0A        (%22Sanity check: 1 line string%22,%0A            'Test', '    Test'),%0A        (%22List of strings turns in to strings joined by %5Cn%22,%0A            %5B%22Test%22, %22Test%22%5D, '    Test%5Cn    Test'),%0A    ):%0A        eq_.description = description%0A        yield eq_, indent(input), output%0A        del eq_.description%0A%0Adef test_indent_with_strip():%0A    for description, input, output in (%0A        (%22Sanity check: 1 line string%22,%0A            indent('Test', strip=True), '    Test'),%0A        (%22Check list of strings%22,%0A            indent(%5B%22Test%22, %22Test%22%5D, strip=True), '    Test%5Cn    Test'),%0A        (%22Check list of strings%22,%0A            indent(%5B%22        Test%22, %22        Test%22%5D, strip=True), '    Test%5Cn    Test'),%0A    ):%0A        eq_.description = description%0A        yield eq_, input, output%0A        del eq_.description%0A%0A@mock_streams('stderr')%0A@raises(SystemExit)%0Adef test_abort():%0A    %22%22%22%0A    Abort should raise SystemExit%0A    %22%22%22%0A    abort(%22Test%22)%0A%0A@mock_streams('stderr')%0A@with_patched_object(output, 'aborts', True)%0Adef test_abort_message():%0A    try:%0A        abort(%22Test%22)%0A    except SystemExit:%0A        pass%0A    result = sys.stderr.getvalue()%0A    eq_(%22%5CnFatal error: Test%5Cn%5CnAborting.%5Cn%22, result)%0A   %0A

Add basic tests for utils