Commit 17c1d2fa authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: Normalize \r\n to \n in doctests on windows

On windows print emits \r\n instead of just \n. Here is how e.g.
test_defer_excchain_dump fails without normalization:

    E           Failed: not equal:
    E           Differences (unified diff with -expected +actual):
    E               @@ -1,42 +1,43 @@
    E               -Traceback (most recent call last):
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in _
    E               -    return f(*argv, **kw)
    E               -  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 42, in main
    E               -    raise RuntimeError("err")
    E               -RuntimeError: err
    E               -<BLANKLINE>
    E               -During handling of the above exception, another exception occurred:
    E               -<BLANKLINE>
    E               -Traceback (most recent call last):
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
    E               -    ...
    E               -  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 31, in d1
    E               -    raise RuntimeError("d1: aaa")
    E               -RuntimeError: d1: aaa
    E               -<BLANKLINE>
    E               -During handling of the above exception, another exception occurred:
    E               -<BLANKLINE>
    E               -Traceback (most recent call last):
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
    E               -    ...
    E               -  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 33, in d2
    E               -    1/0
    E               -ZeroDivisionError: ...
    E               -<BLANKLINE>
    E               -During handling of the above exception, another exception occurred:
    E               -<BLANKLINE>
    E               -Traceback (most recent call last):
    E               -  ... "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 45, in <module>
    E               -    main()
    E               -  ...
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in _
    E               -    with __goframe__:
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
    E               -    ...
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
    E               -    ...
    E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
    E               -    ...
    E               -  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 35, in d3
    E               -    raise RuntimeError("d3: bbb")
    E               -RuntimeError: d3: bbb
    E               +Traceback (most recent call last):
    E               +  File "PYGOLANG/golang/__init__.py", line 106, in _
    E               +    return f(*argv, **kw)
    E               +  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 42, in main
    E               +    raise RuntimeError("err")
    E               +RuntimeError: err
    E               +
    E               +During handling of the above exception, another exception occurred:
    E               +
    E               +Traceback (most recent call last):
    E               +  File "PYGOLANG/golang/__init__.py", line 183, in __exit__
    E               +    d()
    E               +  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 31, in d1
    E               +    raise RuntimeError("d1: aaa")
    E               +RuntimeError: d1: aaa
    E               +
    E               +During handling of the above exception, another exception occurred:
    E               +
    E               +Traceback (most recent call last):
    E               +  File "PYGOLANG/golang/__init__.py", line 183, in __exit__
    E               +    d()
    E               +  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 33, in d2
    E               +    1/0
    E               +ZeroDivisionError: division by zero
    E               +
    E               +During handling of the above exception, another exception occurred:
    E               +
    E               +Traceback (most recent call last):
    E               +  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 45, in <module>
    E               +    main()
    E               +  File "Z:\home\kirr\src\tools\go\pygo-win\1.wenv\lib\site-packages/decorator.py", line 232, in fun
    E               +    return caller(func, *(extras + args), **kw)
    E               +  File "PYGOLANG/golang/__init__.py", line 105, in _
    E               +    with __goframe__:
    E               +  File "PYGOLANG/golang/__init__.py", line 182, in __exit__
    E               +    with __goframe__:
    E               +  File "PYGOLANG/golang/__init__.py", line 182, in __exit__
    E               +    with __goframe__:
    E               +  File "PYGOLANG/golang/__init__.py", line 183, in __exit__
    E               +    d()
    E               +  File "PYGOLANG/golang/testprog/golang_test_defer_excchain.py", line 35, in d3
    E               +    raise RuntimeError("d3: bbb")
    E               +RuntimeError: d3: bbb
parent 06935819
...@@ -1741,6 +1741,15 @@ def _pyrun(argv, stdin=None, stdout=None, stderr=None, **kw): # -> retcode, st ...@@ -1741,6 +1741,15 @@ def _pyrun(argv, stdin=None, stdout=None, stderr=None, **kw): # -> retcode, st
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=stdout, stderr=stderr, env=env, **kw) p = Popen(argv, stdin=(PIPE if stdin else None), stdout=stdout, stderr=stderr, env=env, **kw)
stdout, stderr = p.communicate(stdin) stdout, stderr = p.communicate(stdin)
# on windows print emits \r\n instead of just \n
# normalize that to \n in *out
if os.name == 'nt':
if stdout is not None:
stdout = stdout.replace(b'\r\n', b'\n')
if stderr is not None:
stderr = stderr.replace(b'\r\n', b'\n')
return p.returncode, stdout, stderr return p.returncode, stdout, stderr
# pyrun runs `sys.executable argv... <stdin`. # pyrun runs `sys.executable argv... <stdin`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment