Commit 42ab98a6 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: assertDoc: Include ~/... into PYGOLANG normalization

assertDoc normalizes paths in compared texts with the idea for etalon
output to contain PYGOLANG instead of whatever actual path there will be
when testing the package. This already works.

However IPython, when dumping tracebacks, tries to shorten paths and
abbreviate $HOME with ~ in them. This breaks normalization which misses
to convert prefix of those paths into PYGOLANG.

-> Fix it by teaching assertDoc to also handle paths that start with ~
and correctly normalize them.

This will be needed in the next patch where we will add tests for how
ipython and pytest dump tracebacks for chained exceptions.
parent 2413b5ba
...@@ -1758,7 +1758,9 @@ def assertDoc(want, got): ...@@ -1758,7 +1758,9 @@ def assertDoc(want, got):
got = u(got) got = u(got)
# normalize got to PYGOLANG # normalize got to PYGOLANG
got = got.replace(dir_pygolang, "PYGOLANG") udir_pygolang = abbrev_home(dir_pygolang) # /home/x/.../pygolang -> ~/.../pygolang
got = got.replace(dir_pygolang, "PYGOLANG") # /home/x/.../pygolang -> PYGOLANG
got = got.replace(udir_pygolang, "PYGOLANG") # ~/.../pygolang -> PYGOLANG
# ^$ -> <BLANKLINE> # ^$ -> <BLANKLINE>
while "\n\n" in want: while "\n\n" in want:
...@@ -1794,3 +1796,12 @@ def test_fmtargspec(): ...@@ -1794,3 +1796,12 @@ def test_fmtargspec():
def readfile(path): def readfile(path):
with open(path, "r") as f: with open(path, "r") as f:
return f.read() return f.read()
# abbrev_home returns path with user home prefix abbreviated with ~.
def abbrev_home(path):
home = os.path.expanduser('~')
if path == home:
return '~'
if path.startswith(home+'/'):
return '~'+path[len(home):]
return path
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