Commit c4c92794 authored by Clément Gillard's avatar Clément Gillard Committed by Akim Demaille
Browse files

pylint: refactor tests/bin

See #61. Refactor Python scripts in tests/bin
to comply with `pylint`.

* tests/bin/bench-power: Reorder imports.
* tests/bin/rat.py: Fix string escapes.
* tests/bin/test.py: Reorder and remove duplicate imports.
* tests/bin/update-test: Remove unused imports and useless `global`s.
* python/pylintrc: Add new entries to ignore.
parent 6c4e10cc
......@@ -27,7 +27,8 @@ disable=
redefined-builtin,no-self-use,pointless-statement,wildcard-import,
no-method-argument,fixme,cyclic-import,duplicate-code,
super-init-not-called,redefined-outer-name,too-many-branches,
too-many-nested-blocks
too-many-nested-blocks,multiple-imports,too-many-statements,
unused-wildcard-import,bad-indentation
[REPORTS]
......
......@@ -71,8 +71,8 @@
## 7 0.03 0.09 0.32 1.30 5.23 22.40 95.73
##
import vcsn
import timeit
import vcsn
repetitions = 1
......@@ -87,6 +87,9 @@ for i in val:
a[i] = aut.conjunction(i)
time[i] = dict()
# Known pylint issue: https://github.com/PyCQA/pylint/issues/178
# FIXME: Remove this once issue is fixed.
# pylint: disable=undefined-loop-variable,cell-var-from-loop
for i in val:
for j in val:
t = min(timeit.repeat(lambda: a[i].conjunction(a[j]),
......
......@@ -24,7 +24,7 @@ contexts = {
}
def context_update():
global context, ctx
global context, ctx # pylint: disable=global-statement
if context in contexts:
context = contexts[context]
ctx = vcsn.context(context)
......@@ -49,7 +49,7 @@ def pp(re):
def check_rat_exp(fname):
file = open(fname, 'r', encoding='utf-8')
lineno = 0
global context, identities
global context, identities # pylint: disable=global-statement
for line in file:
lineno += 1
loc = fname + ':' + str(lineno)
......@@ -99,7 +99,7 @@ def check_rat_exp(fname):
# == tests that boths are equivalent.
# => check the actual result.
m = re.match('(.*\S)\s*(=>|==)\s*(.*)$', line)
m = re.match(r'(.*\S)\s*(=>|==)\s*(.*)$', line)
if m is not None:
l = m.group(1)
op = m.group(2)
......@@ -118,7 +118,7 @@ def check_rat_exp(fname):
continue
# !: Look for syntax errors.
m = re.match('(.*\S)\s+(!.*)$', line)
m = re.match(r'(.*\S)\s+(!.*)$', line)
if m is not None:
l = m.group(1)
err = m.group(2)
......
from difflib import unified_diff as diff
import atexit
import inspect
import os
import re
......@@ -23,12 +24,11 @@ medir = sys.argv[0].replace(".py", ".dir")
# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
def which(program):
'Return the file name for program if it exists, None otherwise.'
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
fpath, _ = os.path.split(program)
if fpath:
if is_exe(program):
return program
......@@ -75,7 +75,6 @@ def rst_diff(expected, effective):
def load(fname):
"Load the library automaton file `fname`."
import vcsn
return vcsn.automaton(filename=vcsn.datadir + "/" + fname)
......@@ -95,7 +94,7 @@ def automaton(a):
def FAIL(*msg, **kwargs):
global count, nfail
global count, nfail # pylint: disable=global-statement
count += 1
nfail += 1
# Don't display multi-line failure messages, only the first line
......@@ -112,7 +111,7 @@ def FAIL(*msg, **kwargs):
def PASS(*msg, **kwargs):
global count, npass
global count, npass # pylint: disable=global-statement
count += 1
npass += 1
print('ok ', count, *msg)
......@@ -278,5 +277,4 @@ def PLAN():
print('PASS:', npass)
print('FAIL:', nfail)
import atexit
atexit.register(PLAN)
......@@ -7,7 +7,7 @@
# usage:
# update-test --builddir=_build tests/python/*.py tests/python/determinize.dir/*
import argparse, os, re, sys
import argparse, re
parser = argparse.ArgumentParser(description='Update test cases.')
parser.add_argument('tests', metavar='test', nargs='+',
......@@ -51,7 +51,6 @@ def diff_to_re(match):
if is_diff:
frm = "\n".join(frm)
to = "\n".join(to)
global subst
subst[frm] = to
def exp_eff_to_re(match):
......@@ -67,7 +66,6 @@ def exp_eff_to_re(match):
for l in match.group(2).splitlines(True):
to += l[1:]
to = to[:-1]
global subst
subst[fr] = to
if args.verbose:
print("SUBST: {} -> {}".format(fr, to))
......@@ -78,7 +76,7 @@ def update(test, logfile):
log = contents(logfile)
if args.verbose:
print("LOG: ", logfile)
global subst
global subst # pylint: disable=global-statement
subst = dict()
re.sub(r'Expected out.*?::\n\n((?:^\t.*\n)+)\n'
+'Effective out.*?::\n\n((?:^\t.*\n)+)\n',
......@@ -87,7 +85,7 @@ def update(test, logfile):
# diff_to_re, log, flags = re.MULTILINE)
if subst != dict():
# Turn "subst{frm} -> to" into a large RE.
frm = '|'.join(map(re.escape, subst.keys()))
frm = '|'.join([re.escape(x) for x in subst.keys()])
if args.verbose:
print("FROM:", frm)
test = re.sub("(" + frm + ")",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment