From 0c3d92310090ac82848c4a4607ca6f1f6815c6bd Mon Sep 17 00:00:00 2001 From: Brian Mego Date: Mon, 3 Aug 2020 21:28:48 -0500 Subject: [PATCH] Adds walrus test and python 3.7/3.8 tox definitions --- tox.ini | 2 +- yapf/yapflib/py3compat.py | 2 ++ yapftests/reformatter_basic_test.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index dca30d2b3..f42b884f0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py27,py34,py35,py36 +envlist=py27,py34,py35,py36,py37,py38 [testenv] commands= diff --git a/yapf/yapflib/py3compat.py b/yapf/yapflib/py3compat.py index 5373b013a..7c9052374 100644 --- a/yapf/yapflib/py3compat.py +++ b/yapf/yapflib/py3compat.py @@ -20,6 +20,8 @@ PY3 = sys.version_info[0] >= 3 PY36 = sys.version_info[0] >= 3 and sys.version_info[1] >= 6 +PY37 = sys.version_info[0] >= 3 and sys.version_info[1] >= 7 +PY38 = sys.version_info[0] >= 3 and sys.version_info[1] >= 8 if PY3: StringIO = io.StringIO diff --git a/yapftests/reformatter_basic_test.py b/yapftests/reformatter_basic_test.py index 50cfdbc56..d6155adfe 100644 --- a/yapftests/reformatter_basic_test.py +++ b/yapftests/reformatter_basic_test.py @@ -3033,6 +3033,19 @@ def testForceMultilineDict_False(self): finally: style.SetGlobalStyle(style.CreateYapfStyle()) + @unittest.skipUnless(py3compat.PY38, 'Requires Python 3.8') + def testWalrus(self): + unformatted_code = textwrap.dedent("""\ + if (x := len([1]*1000)>100): + print(f'{x} is pretty big' ) + """) + expected = textwrap.dedent("""\ + if (x := len([1] * 1000) > 100): + print(f'{x} is pretty big') + """) + uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code) + self.assertCodeEqual(expected, reformatter.Reformat(uwlines)) + if __name__ == '__main__': unittest.main()