Skip to content

Trying to fix tests on windows #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ jobs:
- run: pip freeze

- name: test with extras
run: |
make test
coverage xml
run: make test

- run: coverage xml

- uses: codecov/[email protected]
with:
Expand All @@ -71,9 +71,9 @@ jobs:
run: pip uninstall -y multidict numpy pydantic asyncpg

- name: test without extras
run: |
make test
coverage xml
run: make test

- run: coverage xml

- uses: codecov/[email protected]
with:
Expand Down
13 changes: 7 additions & 6 deletions devtools/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ def _process(self, args, kwargs) -> DebugOutput:
warning=self._show_warnings and 'error parsing code, call stack too shallow',
)

filename = call_frame.f_code.co_filename
function = call_frame.f_code.co_name
if filename.startswith('/'):
# make the path relative
from pathlib import Path

from pathlib import Path

path = Path(call_frame.f_code.co_filename)
if path.is_absolute():
# make the path relative
cwd = Path('.').resolve()
try:
filename = str(Path(filename).relative_to(cwd))
path = path.relative_to(cwd)
except ValueError:
# happens if filename path is not within CWD
pass
Expand All @@ -173,7 +174,7 @@ def _process(self, args, kwargs) -> DebugOutput:
arguments = list(self._process_args(ex, args, kwargs))

return self.output_class(
filename=filename,
filename=str(path),
lineno=lineno,
frame=function,
arguments=arguments,
Expand Down
53 changes: 20 additions & 33 deletions tests/test_expr_render.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
import asyncio
import re
import sys

import pytest

from devtools import Debug, debug

from .utils import normalise_output


def foobar(a, b, c):
return a + b + c


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_simple():
a = [1, 2, 3]
v = debug.format(len(a))
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
# print(s)
assert (
'tests/test_expr_render.py:<line no> test_simple\n'
' len(a): 3 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_subscription():
a = {1: 2}
v = debug.format(a[1])
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert (
'tests/test_expr_render.py:<line no> test_subscription\n'
' a[1]: 2 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_exotic_types():
aa = [1, 2, 3]
v = debug.format(
Expand All @@ -49,8 +47,7 @@ def test_exotic_types():
{a: a + 1 for a in aa},
(a for a in aa),
)
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = re.sub(r'(at 0x)\w+', r'\1<hash>', s)
s = normalise_output(str(v))
print('\n---\n{}\n---'.format(v))

# Generator expression source changed in 3.8 to include parentheses, see:
Expand Down Expand Up @@ -83,68 +80,63 @@ def test_exotic_types():
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_newline():
v = debug.format(
foobar(1, 2, 3))
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
# print(s)
assert (
'tests/test_expr_render.py:<line no> test_newline\n'
' foobar(1, 2, 3): 6 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_trailing_bracket():
v = debug.format(
foobar(1, 2, 3)
)
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
# print(s)
assert (
'tests/test_expr_render.py:<line no> test_trailing_bracket\n'
' foobar(1, 2, 3): 6 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_multiline():
v = debug.format(
foobar(1,
2,
3)
)
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
# print(s)
assert (
'tests/test_expr_render.py:<line no> test_multiline\n'
' foobar(1, 2, 3): 6 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_multiline_trailing_bracket():
v = debug.format(
foobar(1, 2, 3
))
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
# print(s)
assert (
'tests/test_expr_render.py:<line no> test_multiline_trailing_bracket\n'
' foobar(1, 2, 3 ): 6 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
@pytest.mark.skipif(sys.version_info < (3, 6), reason='kwarg order is not guaranteed for 3.5')
def test_kwargs():
v = debug.format(
foobar(1, 2, 3),
a=6,
b=7
)
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert (
'tests/test_expr_render.py:<line no> test_kwargs\n'
' foobar(1, 2, 3): 6 (int)\n'
Expand All @@ -153,7 +145,6 @@ def test_kwargs():
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
@pytest.mark.skipif(sys.version_info < (3, 6), reason='kwarg order is not guaranteed for 3.5')
def test_kwargs_multiline():
v = debug.format(
Expand All @@ -162,7 +153,7 @@ def test_kwargs_multiline():
a=6,
b=7
)
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert (
'tests/test_expr_render.py:<line no> test_kwargs_multiline\n'
' foobar(1, 2, 3): 6 (int)\n'
Expand All @@ -171,20 +162,18 @@ def test_kwargs_multiline():
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_multiple_trailing_lines():
v = debug.format(
foobar(
1, 2, 3
),
)
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert (
'tests/test_expr_render.py:<line no> test_multiple_trailing_lines\n foobar( 1, 2, 3 ): 6 (int)'
) == s


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_very_nested_last_statement():
def func():
return debug.format(
Expand All @@ -201,14 +190,13 @@ def func():

v = func()
# check only the original code is included in the warning
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert s == (
'tests/test_expr_render.py:<line no> func\n'
' abs( abs( abs( abs( -1 ) ) ) ): 1 (int)'
)


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_syntax_warning():
def func():
return debug.format(
Expand All @@ -227,7 +215,7 @@ def func():

v = func()
# check only the original code is included in the warning
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert s == (
'tests/test_expr_render.py:<line no> func\n'
' abs( abs( abs( abs( abs( -1 ) ) ) ) ): 1 (int)'
Expand All @@ -254,14 +242,13 @@ def func():
)

v = func()
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert s == (
'tests/test_expr_render.py:<line no> func\n'
' abs( abs( abs( abs( abs( -1 ) ) ) ) ): 1 (int)'
)


@pytest.mark.xfail(sys.platform == 'win32', reason='as yet unknown windows problem')
def test_await():
async def foo():
return 1
Expand All @@ -272,7 +259,7 @@ async def bar():
loop = asyncio.new_event_loop()
v = loop.run_until_complete(bar())
loop.close()
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert (
'tests/test_expr_render.py:<line no> bar\n'
' await foo(): 1 (int)'
Expand All @@ -284,7 +271,7 @@ def test_other_debug_arg():
v = debug.format([1, 2])

# check only the original code is included in the warning
s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert s == (
'tests/test_expr_render.py:<line no> test_other_debug_arg\n'
' [1, 2] (list) len=2'
Expand All @@ -297,7 +284,7 @@ def test_other_debug_arg_not_literal():
y = 2
v = debug.format([x, y])

s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert s == (
'tests/test_expr_render.py:<line no> test_other_debug_arg_not_literal\n'
' [x, y]: [1, 2] (list) len=2'
Expand All @@ -310,7 +297,7 @@ def test_executing_failure():
y = 2

# executing fails inside a pytest assert ast the AST is modified
assert re.sub(r':\d{2,}', ':<line no>', str(debug.format([x, y]))) == (
assert normalise_output(str(debug.format([x, y]))) == (
'tests/test_expr_render.py:<line no> test_executing_failure '
'(executing failed to find the calling node)\n'
' [1, 2] (list) len=2'
Expand All @@ -326,7 +313,7 @@ def test_format_inside_error():
except RuntimeError as e:
v = str(e)

s = re.sub(r':\d{2,}', ':<line no>', str(v))
s = normalise_output(str(v))
assert s == (
'tests/test_expr_render.py:<line no> test_format_inside_error\n'
' [x, y]: [1, 2] (list) len=2'
Expand Down
Loading