Skip to content

Commit

Permalink
Fix pytest-dev#1290: Py3.5's @ operator/assertion rewriting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomviner committed Feb 5, 2016
1 parent b5dc7d9 commit f63b706
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
2.8.8.dev1
----------

- fix #1290: support Python 3.5's @ operator in assertion rewriting.
Thanks Shinkenjoe for report with test case and Tom Viner for the PR.

2.8.7
-----

Expand Down
5 changes: 5 additions & 0 deletions _pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ def _call_reprcompare(ops, results, expls, each_obj):
ast.In: "in",
ast.NotIn: "not in"
}
# Python 3.5+ compatibility
try:
binop_map[ast.MatMult] = "@"
except AttributeError:
pass

# Python 3.4+ compatibility
if hasattr(ast, "NameConstant"):
Expand Down
13 changes: 13 additions & 0 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ def f():
assert False or 4 % 2
assert getmsg(f) == "assert (False or (4 % 2))"

@pytest.mark.skipif("sys.version_info < (3,5)")
def test_at_operator_issue1290(self, testdir):
testdir.makepyfile("""
class Matrix:
def __init__(self, num):
self.num = num
def __matmul__(self, other):
return self.num * other.num
def test_multmat_operator():
assert Matrix(2) @ Matrix(3) == 42""")
testdir.runpytest().assert_outcomes(failed=1)

def test_call(self):
def g(a=42, *args, **kwargs):
return False
Expand Down

0 comments on commit f63b706

Please sign in to comment.