summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-03-11 22:00:01 +0000
committerAnthony Sottile <asottile@umich.edu>2019-03-11 22:00:01 +0000
commitfadedefae2df9fa6dff624fab733d717aea5ca0e (patch)
tree9969bec1dea404db99b67bd6b80ecb20a318497a
parent88caf5ac484f5c09aedc02167c59c66ff0af0068 (diff)
parente9b9ebb58e1e45db3cb17f918a8269288a461100 (diff)
downloadflake8-fadedefae2df9fa6dff624fab733d717aea5ca0e.tar.gz
Merge branch 'charlesfrye/fix-prelim-args' into 'master'
Fixes handling of empty lists by Application Closes #518 See merge request pycqa/flake8!310
-rw-r--r--src/flake8/main/application.py2
-rw-r--r--tests/unit/test_application.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py
index 6e8ddaf..c7859b9 100644
--- a/src/flake8/main/application.py
+++ b/src/flake8/main/application.py
@@ -122,7 +122,7 @@ class Application(object):
# do not need to worry and we can continue. If it is, we successfully
# defer printing the version until just a little bit later.
# Similarly we have to defer printing the help text until later.
- args = (argv or sys.argv)[:]
+ args = (argv if argv is not None else sys.argv)[:]
try:
args.remove("--version")
except ValueError:
diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py
index 5ec9f1f..cb8372b 100644
--- a/tests/unit/test_application.py
+++ b/tests/unit/test_application.py
@@ -1,5 +1,6 @@
"""Tests for the Application class."""
import optparse
+import sys
import mock
import pytest
@@ -97,3 +98,12 @@ def test_prelim_opts_args(application):
assert application.prelim_opts.statistics
assert application.prelim_opts.verbose
assert application.prelim_args == ['src', 'setup.py']
+
+
+def test_prelim_opts_handles_empty(application):
+ """Verify empty argv lists are handled correctly."""
+ irrelevant_args = ['myexe', '/path/to/foo']
+ with mock.patch.object(sys, 'argv', irrelevant_args):
+ application.parse_preliminary_options_and_args([])
+
+ assert application.prelim_args == []