From 7d107018e85c95d8def9d7d658b0596c80312b8f Mon Sep 17 00:00:00 2001 From: TomV Date: Fri, 5 Feb 2016 22:30:07 +0000 Subject: [PATCH 1/2] Fix #1290: Py3.5's @ operator/assertion rewriting. --- CHANGELOG | 3 +++ _pytest/assertion/rewrite.py | 5 +++++ testing/test_assertrewrite.py | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index ceac3efe4..2bb3bcd66 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 ----- diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 9484ba4b3..14b8e49db 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -453,6 +453,11 @@ binop_map = { 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"): diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 544250ad5..cdf0a3c53 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -279,6 +279,19 @@ class TestAssertionRewrite: 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) == 6""") + testdir.runpytest().assert_outcomes(passed=1) + def test_call(self): def g(a=42, *args, **kwargs): return False From 2b764a0e73b44ba4285d96a770d06fff68a65fa7 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 6 Feb 2016 09:37:13 -0200 Subject: [PATCH 2/2] Fix CHANGELOG entry to new format --- CHANGELOG.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3005c44fe..d36fd5e3c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -57,11 +57,15 @@ ``Config.fromdictargs`` now represents its input much more faithfully. Thanks to `@bukzor`_ for the complete PR (`#680`_). +* Fix (`#1290`_): support Python 3.5's `@` operator in assertion rewriting. + Thanks `@Shinkenjoe`_ for report with test case and `@tomviner`_ for the PR. + .. _#1040: https://github.com/pytest-dev/pytest/pull/1040 .. _#680: https://github.com/pytest-dev/pytest/issues/680 .. _#1287: https://github.com/pytest-dev/pytest/pull/1287 .. _#1226: https://github.com/pytest-dev/pytest/pull/1226 +.. _#1290: https://github.com/pytest-dev/pytest/pull/1290 .. _@MichaelAquilina: https://github.com/MichaelAquilina .. _@bukzor: https://github.com/bukzor .. _@nicoddemus: https://github.com/nicoddemus @@ -69,12 +73,10 @@ .. _@codewarrior0: https://github.com/codewarrior0 .. _@jaraco: https://github.com/jaraco .. _@The-Compiler: https://github.com/The-Compiler +.. _@Shinkenjoe: https://github.com/Shinkenjoe +.. _@tomviner: https://github.com/tomviner - -- 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 -----