• Kirill Smelkov's avatar
    golang: tests: Spawn subprocess python with $PYTHONIOENCODING set to encoding... · 8d723b34
    Kirill Smelkov authored
    golang: tests: Spawn subprocess python with $PYTHONIOENCODING set to encoding of stdin/stdout/stderr
    
    We need to do it because on Windows `python x.py | ...` runs with stdio
    encoding set to cp125X even if just `python x.py` runs with stdio
    encoding=UTF-8.
    
        (1.wenv) Z:\home\kirr\src\tools\go\pygo-win\pygolang\golang\testprog>python golang_test_str.py
        print(qq(b)): "привет b"
        print(qq(u)): "привет u"
    
        (1.wenv) Z:\home\kirr\src\tools\go\pygo-win\pygolang\golang\testprog>python golang_test_str.py |more
        print(qq(b)): "яЁштхЄ b"
        print(qq(u)): "яЁштхЄ u"
    
        (1.wenv) Z:\home\kirr\src\tools\go\pygo-win\pygolang\golang\testprog>python golang_test_str.py >aaa.txt
        (1.wenv) Z:\home\kirr\src\tools\go\pygo-win\pygolang\golang\testprog>type aaa.txt
        print(qq(b)): "яЁштхЄ b"
        print(qq(u)): "яЁштхЄ u"
    
    Which leads to the following test_strings_print failure:
    
        E           Failed: not equal:
        E           Expected:
        E               print(qq(b)): "привет b"
        E               print(qq(u)): "привет u"
        E           Got:
        E               print(qq(b)): "������ b"
        E               print(qq(u)): "������ u"
    
    We also change golang_test_str.py to print not only russian and english
    letters, but also greek ones. This is to make sure that stdout IO encoding would
    not go cp125X unnoticed because then printing will fail with UnicodeEncodeError.
    
    Note: in the above example both got and expected are wrong. Via
    $PYTHONIOENCODING we only fix "got" and we will fix "expected" in the followup
    patch. After current patch test_strings_print result is
    
        E           Failed: not equal:
        E           Expected:
        E               print(qq(b)): "привет αβγ b"
        E               print(qq(u)): "привет αβγ u"
        E           Got:
        E               print(qq(b)): "привет αβγ b"
        E               print(qq(u)): "привет αβγ u"
    8d723b34
golang_test.py 53 KB