Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit45a36d3

Browse files
cclausstrekhleb
cclauss
authored andcommitted
Travis CI: Add flake8 to the testing (trekhleb#5)
* Travis CI: Add flake8 to the testing Add [flake8](http://flake8.pycqa.org) tests to find Python syntax errors and undefined names.__E901,E999,F821,F822,F823__ are the "_showstopper_" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. Most other flake8 issues are merely "style violations" -- useful for readability but they do not effect runtime safety.* F821: undefined name `name`* F822: undefined name `name` in `__all__`* F823: local variable name referenced before assignment* E901: SyntaxError or IndentationError* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree* learn-python should not teach the antipattern of bare exceptionsSee PEP8 andhttps://realpython.com/the-most-diabolical-python-antipattern* noqa F821 - We are intentionally raising NameError* Two consecutive blank lines before a function definition* flake8 --max-complexity=10 --> 12* pylint: disable=broad-except
1 parent72f2e5c commit45a36d3

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

‎.travis.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ python:
55
# Install dependencies.
66
install:
77
-pip install -r requirements.txt
8+
-pip install flake8
89

910
# Run linting and tests.
1011
script:
12+
# stop the build if there are Python syntax errors or undefined names
13+
-flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
14+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
15+
-flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 --statistics
1116
-pylint ./src
1217
-pytest
1318

‎src/control_flow/test_try.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_try():
1818

1919
# The try block will generate an error, because x is not defined:
2020
exception_has_been_caught=False
21+
2122
try:
2223
# pylint: disable=undefined-variable
2324
print(not_existing_variable)
@@ -41,6 +42,7 @@ def test_try():
4142
# You can use the else keyword to define a block of code to be executed
4243
# if no errors were raised.
4344
message=''
45+
# pylint: disable=broad-except
4446
try:
4547
message+='Success.'
4648
exceptNameError:
@@ -54,8 +56,8 @@ def test_try():
5456
# error or not.
5557
message=''
5658
try:
57-
# pylint:disable=undefined-variable
58-
print(not_existing_variable)
59+
# pylint: undefined-variable
60+
print(not_existing_variable)# noqa: F821
5961
exceptNameError:
6062
message+='Something went wrong.'
6163
finally:

‎src/data_types/test_lists.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_del_statement():
195195
withpytest.raises(Exception):
196196
# Referencing the name a hereafter is an error (at least until another
197197
# value is assigned to it).
198-
assertnumbers== []
198+
assertnumbers== []# noqa: F821
199199

200200

201201
deftest_list_comprehensions():

‎src/modules/test_modules.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# It can also be used when utilising from with similar effects:
4040
fromfibonacci_moduleimportfibonacci_at_positionasfibonacci_at_position_renamed
4141

42+
4243
# When a module named spam is imported, the interpreter first searches for a built-in module with
4344
# that name. If not found, it then searches for a file named spam.py in a list of directories
4445
# given by the variable sys.path. sys.path is initialized from these locations:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp