Commit 161629e6 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: tests: Prepare expected repr properly

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.
parent f23a9ef5
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2019-2021 Nexedi SA and Contributors. # Copyright (C) 2019-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -180,7 +180,7 @@ def test_pymain(): ...@@ -180,7 +180,7 @@ def test_pymain():
_ = pyout(['-m', 'hello', 'abc', 'def'], cwd=testdata) _ = pyout(['-m', 'hello', 'abc', 'def'], cwd=testdata)
# realpath rewrites e.g. `local/lib -> lib` if local/lib is symlink # realpath rewrites e.g. `local/lib -> lib` if local/lib is symlink
hellopy = realpath(join(testdata, 'hello.py')) hellopy = realpath(join(testdata, 'hello.py'))
assert _ == b"hello\nworld\n['%s', 'abc', 'def']\n" % b(hellopy) assert _ == b"hello\nworld\n[%s, 'abc', 'def']\n" % b(repr(hellopy))
# -m<module> # -m<module>
__ = pyout(['-mhello', 'abc', 'def'], cwd=testdata) __ = pyout(['-mhello', 'abc', 'def'], cwd=testdata)
assert __ == _ assert __ == _
...@@ -191,7 +191,7 @@ def test_pymain(): ...@@ -191,7 +191,7 @@ def test_pymain():
# -i after stdin (also tests interactive mode as -i forces interactive even on non-tty) # -i after stdin (also tests interactive mode as -i forces interactive even on non-tty)
d = { d = {
b'hellopy': b(hellopy), b'repr(hellopy)': b(repr(hellopy)),
b'ps1': b'' # cpython emits prompt to stderr b'ps1': b'' # cpython emits prompt to stderr
} }
if is_pypy and not is_gpython: if is_pypy and not is_gpython:
...@@ -208,7 +208,7 @@ def test_pymain(): ...@@ -208,7 +208,7 @@ def test_pymain():
assert _ == b"hello\nworld\n['-c']\n%(ps1)s'~~HELLO~~'\n%(ps1)s" % d assert _ == b"hello\nworld\n['-c']\n%(ps1)s'~~HELLO~~'\n%(ps1)s" % d
# -i after -m # -i after -m
_ = pyout(['-i', '-m', 'hello'], stdin=b'world.tag', cwd=testdata) _ = pyout(['-i', '-m', 'hello'], stdin=b'world.tag', cwd=testdata)
assert _ == b"hello\nworld\n['%(hellopy)s']\n%(ps1)s'~~WORLD~~'\n%(ps1)s" % d assert _ == b"hello\nworld\n[%(repr(hellopy))s]\n%(ps1)s'~~WORLD~~'\n%(ps1)s" % d
# -i after file # -i after file
_ = pyout(['-i', 'testdata/hello.py'], stdin=b'tag', cwd=here) _ = pyout(['-i', 'testdata/hello.py'], stdin=b'tag', cwd=here)
assert _ == b"hello\nworld\n['testdata/hello.py']\n%(ps1)s'~~HELLO~~'\n%(ps1)s" % d assert _ == b"hello\nworld\n['testdata/hello.py']\n%(ps1)s'~~HELLO~~'\n%(ps1)s" % d
......
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