• Kirill Smelkov's avatar
    gpython: tests: Prepare expected repr properly · 161629e6
    Kirill Smelkov authored
    In several places we were preparing repr of a string as '%s' which works
    ok most of the time but leads to failure if string contains '\'
    characters e.g. if it represents a path and we are running on windows:
    
            def test_pymain():
                from golang import b
    
                ....
    
                # -m <module>
                _ = pyout(['-m', 'hello', 'abc', 'def'], cwd=testdata)
                # realpath rewrites e.g. `local/lib -> lib` if local/lib is symlink
                hellopy = realpath(join(testdata, 'hello.py'))
        >       assert _ == b"hello\nworld\n['%s', 'abc', 'def']\n" % b(hellopy)
        E       assert b"hello\nworld\n['Z:\\\\home\\\\kirr\\\\src\\\\tools\\\\go\\\\pygo-win\\\\pygolang\\\\gpython\\\\testdata\\\\hello.py', 'abc', 'def'
        ]\n" == b"hello\nworld\n['Z:\\home\\kirr\\src\\tools\\go\\pygo-win\\pygolang\\gpython\\testdata\\hello.py', 'abc', 'def']\n"
        E         At index 17 diff: b'\\' != b'h'
        E         Full diff:
        E           (
        E         -  b"hello\nworld\n['Z:\\home\\kirr\\src\\tools\\go\\pygo-win\\pygolang\\gpytho"
        E         ?                                                                  ------------
        E         +  b"hello\nworld\n['Z:\\\\home\\\\kirr\\\\src\\\\tools\\\\go\\\\pygo-win\\\\pygo"
        E         ?                        ++    ++        ++   ++         ++  ++            ++
        E         -  b"n\\testdata\\hello.py', 'abc', 'def']\n",
        E         +  b"lang\\\\gpython\\\\testdata\\\\hello.py', 'abc', 'def']\n",
        E         ?    ++ ++++++++++++++            ++
        E           )
    
        gpython\gpython_test.py:183: AssertionError
    
    -> Fix it by preparing repr via repr(...) properly.
    161629e6
gpython_test.py 14.4 KB