tests/heredoctest.py
author Brodie Rao <brodie@bitheap.org>
Tue, 01 Nov 2011 12:25:54 -0700
branchstable
changeset 15398 474279be5add
parent 15247 3cd1605e9d8e
child 15434 5635a4017061
permissions -rw-r--r--
tests: fix readline escape characters in heredoctest.py/test-url.py This fix mirrors the changes made to test-doctest.py in b856071435f7 and 967adcf5910d. Without this change, tests running heredoctest.py can fail on certain versions of OS X when TERM is set to xterm-256color: $ /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -m heredoctest <<EOF > >>> open('b', 'w').write('this' * 1000) > EOF + \x1b[?1034h (no-eol) (esc) A similar problem occurs with test-url.py: $ ./run-tests.py test-url.py --- .../tests/test-url.py.out +++ .../tests/test-url.py.err @@ -0,0 +1 @@ + ERROR: .../test-url.py output changed ! Failed test-url.py: output changed # Ran 1 tests, 0 skipped, 1 failed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15235
f7044da7a793 tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     1
import doctest, tempfile, os, sys
f7044da7a793 tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     2
f7044da7a793 tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     3
if __name__ == "__main__":
15398
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15247
diff changeset
     4
    if 'TERM' in os.environ:
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15247
diff changeset
     5
        del os.environ['TERM']
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15247
diff changeset
     6
15235
f7044da7a793 tests: add helper script for processing doctests read from stdin
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     7
    fd, name = tempfile.mkstemp(suffix='hg-tst')
15247
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
     8
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
     9
    try:
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    10
        os.write(fd, sys.stdin.read())
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    11
        os.close(fd)
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    12
        failures, _ = doctest.testfile(name, module_relative=False)
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    13
        if failures:
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    14
            sys.exit(1)
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    15
    finally:
3cd1605e9d8e tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents: 15235
diff changeset
    16
        os.remove(name)