Skip to content

Commit 5221014

Browse files
committedApr 15, 2018
Merge branch '405-nonexisting-files' into 'master'
Resolve "flake8 does not generate error when given a non-existent file on the command line" Closes #405 See merge request pycqa/flake8!227
2 parents f05c01b + 59218ca commit 5221014

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
 

‎src/flake8/checker.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ def should_create_file_checker(filename, argument):
210210
filename, filename_patterns
211211
)
212212
is_stdin = filename == '-'
213-
file_exists = os.path.exists(filename)
214213
# NOTE(sigmavirus24): If a user explicitly specifies something,
215214
# e.g, ``flake8 bin/script`` then we should run Flake8 against
216215
# that. Since should_create_file_checker looks to see if the
@@ -221,8 +220,7 @@ def should_create_file_checker(filename, argument):
221220
explicitly_provided = (not running_from_vcs and
222221
not running_from_diff and
223222
(argument == filename))
224-
return ((file_exists and
225-
(explicitly_provided or matches_filename_patterns)) or
223+
return ((explicitly_provided or matches_filename_patterns) or
226224
is_stdin)
227225

228226
checks = self.checks.to_dictionary()

‎tests/unit/test_file_checker.py

+11
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@ def test_repr(*args):
3232
'example.py', checks={}, options=object(),
3333
)
3434
assert repr(file_checker) == 'FileChecker for example.py'
35+
36+
37+
def test_nonexistent_file():
38+
"""Verify that checking non-existent file results in an error."""
39+
c = checker.FileChecker("foobar.py", checks={}, options=object())
40+
41+
assert c.processor is None
42+
assert not c.should_process
43+
assert len(c.results) == 1
44+
error = c.results[0]
45+
assert error[0] == "E902"

‎tests/unit/test_file_processor.py

+5
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,8 @@ def test_log_token(token, log_string):
321321
def test_count_parentheses(current_count, token_text, expected):
322322
"""Verify our arithmetic is correct."""
323323
assert processor.count_parentheses(current_count, token_text) == expected
324+
325+
326+
def test_nonexistent_file():
327+
with pytest.raises(IOError):
328+
processor.FileProcessor("foobar.py", options_from())

0 commit comments

Comments
 (0)
Please sign in to comment.