diff options
| author | Anthony Sottile <asottile@umich.edu> | 2019-01-31 21:53:19 -0800 |
|---|---|---|
| committer | Anthony Sottile <asottile@umich.edu> | 2019-01-31 21:55:10 -0800 |
| commit | 8df38c92b93cd586da2ded9d86ad2283663a3feb (patch) | |
| tree | ad0a4eefbed5acae7d952f51af8521488eac2660 /tests | |
| parent | 79148a02eeeff68f966e703832987c6309b8a001 (diff) | |
| download | flake8-8df38c92b93cd586da2ded9d86ad2283663a3feb.tar.gz | |
Fix reporting of UndefinedLocal pyflakes error
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_pyflakes_codes.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/unit/test_pyflakes_codes.py b/tests/unit/test_pyflakes_codes.py index 837e971..77f3e56 100644 --- a/tests/unit/test_pyflakes_codes.py +++ b/tests/unit/test_pyflakes_codes.py @@ -1,4 +1,5 @@ """Tests of pyflakes monkey patches.""" +import ast import pyflakes @@ -13,3 +14,20 @@ def test_all_pyflakes_messages_have_flake8_codes_assigned(): if name[0].isupper() and obj.message } assert messages == set(pyflakes_shim.FLAKE8_PYFLAKES_CODES) + + +def test_undefined_local_code(): + """In pyflakes 2.1.0 this code's string formatting was changed.""" + src = '''\ +import sys + +def f(): + sys = sys +''' + tree = ast.parse(src) + checker = pyflakes_shim.FlakesChecker(tree, (), 't.py') + message_texts = [s for _, _, s, _ in checker.run()] + assert message_texts == [ + "F823 local variable 'sys' defined in enclosing scope on line 1 referenced before assignment", # noqa: E501 + "F841 local variable 'sys' is assigned to but never used", + ] |
