Skip to content

Commit

Permalink
Use pytest-pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Apr 11, 2019
1 parent d39feab commit 4a95e09
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 48 deletions.
93 changes: 50 additions & 43 deletions docs/utils/linkfix.py
Expand Up @@ -14,50 +14,57 @@

import re

# Used for remembering the file (and its contents)
# so we don't have to open the same file again.
_filename = None
_contents = None

# A regex that matches standard linkcheck output lines
line_re = re.compile(u'(.*)\:\d+\:\s\[(.*)\]\s(?:(.*)\sto\s(.*)|(.*))')

# Read lines from the linkcheck output file
try:
with open("build/linkcheck/output.txt") as out:
output_lines = out.readlines()
except IOError:
print("linkcheck output not found; please run linkcheck first.")
exit(1)

# For every line, fix the respective file
for line in output_lines:
match = re.match(line_re, line)

if match:
newfilename = match.group(1)
errortype = match.group(2)

# Broken links can't be fixed and
# I am not sure what do with the local ones.
if errortype.lower() in ["broken", "local"]:
print("Not Fixed: " + line)
else:
# If this is a new file
if newfilename != _filename:

# Update the previous file
if _filename:
with open(_filename, "w") as _file:
_file.write(_contents)
def main():

# Used for remembering the file (and its contents)
# so we don't have to open the same file again.
_filename = None
_contents = None

# A regex that matches standard linkcheck output lines
line_re = re.compile(u'(.*)\:\d+\:\s\[(.*)\]\s(?:(.*)\sto\s(.*)|(.*))')

# Read lines from the linkcheck output file
try:
with open("build/linkcheck/output.txt") as out:
output_lines = out.readlines()
except IOError:
print("linkcheck output not found; please run linkcheck first.")
exit(1)

# For every line, fix the respective file
for line in output_lines:
match = re.match(line_re, line)

if match:
newfilename = match.group(1)
errortype = match.group(2)

_filename = newfilename
# Broken links can't be fixed and
# I am not sure what do with the local ones.
if errortype.lower() in ["broken", "local"]:
print("Not Fixed: " + line)
else:
# If this is a new file
if newfilename != _filename:

# Update the previous file
if _filename:
with open(_filename, "w") as _file:
_file.write(_contents)

_filename = newfilename

# Read the new file to memory
with open(_filename) as _file:
_contents = _file.read()

_contents = _contents.replace(match.group(3), match.group(4))
else:
# We don't understand what the current line means!
print("Not Understood: " + line)

# Read the new file to memory
with open(_filename) as _file:
_contents = _file.read()

_contents = _contents.replace(match.group(3), match.group(4))
else:
# We don't understand what the current line means!
print("Not Understood: " + line)
if __name__ == '__main__':
main()
58 changes: 58 additions & 0 deletions pylintrc
@@ -0,0 +1,58 @@
[MASTER]
ignore=docs,tests

[MESSAGES CONTROL]
disable=abstract-method,
anomalous-backslash-in-string,
arguments-differ,
attribute-defined-outside-init,
bad-indentation,
bare-except,
broad-except,
catching-non-exception,
cell-var-from-loop,
comparison-with-callable,
consider-using-set-comprehension,
dangerous-default-value,
deprecated-method,
deprecated-module,
expression-not-assigned,
eval-used,
fixme,
function-redefined,
global-statement,
import-error,
inherit-non-class,
invalid-name,
keyword-arg-before-vararg,
logging-format-interpolation,
logging-not-lazy,
lost-exception,
method-hidden,
missing-docstring,
no-init,
no-member,
no-method-argument,
no-name-in-module,
no-self-argument,
no-value-for-parameter,
pointless-string-statement,
protected-access,
redefined-builtin,
redefined-outer-name,
reimported,
relative-import, # https://github.com/PyCQA/pylint/issues/2180
signature-differs,
super-init-not-called,
too-many-ancestors,
too-many-function-args,
unexpected-special-method-signature,
unnecessary-pass,
unsubscriptable-object,
unused-argument,
unused-import,
unused-variable,
unused-wildcard-import,
used-before-assignment,
wildcard-import,
R,C
2 changes: 1 addition & 1 deletion pytest.ini
Expand Up @@ -2,5 +2,5 @@
usefixtures = chdir
python_files=test_*.py __init__.py
python_classes=
addopts = --doctest-modules --assert=plain
addopts = --pylint --doctest-modules --assert=plain
twisted = 1
5 changes: 3 additions & 2 deletions tests/requirements-py2.txt
Expand Up @@ -2,9 +2,10 @@
mock
mitmproxy==0.10.1
netlib==0.10.1
pytest==2.9.2
pytest
pytest-cov
pytest-pylint
pytest-twisted
pytest-cov==2.2.1
jmespath
brotlipy
testfixtures
Expand Down
5 changes: 3 additions & 2 deletions tests/requirements-py3.txt
@@ -1,6 +1,7 @@
pytest==3.6.3
pytest
pytest-cov
pytest-pylint
pytest-twisted
pytest-cov==2.5.1
testfixtures
jmespath
leveldb; sys_platform != "win32"
Expand Down

0 comments on commit 4a95e09

Please sign in to comment.