aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-09-25 06:11:11 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-09-25 06:11:11 +0300
commitcc050d010d398dbf5449d3885fe145c2f7f5c3b8 (patch)
treeef75f09b4ae9f513ce8308d9621f92bebffef516
parentfix licensing notices (diff)
downloadaes-tools-cc050d010d398dbf5449d3885fe145c2f7f5c3b8.tar.gz
aes-tools-cc050d010d398dbf5449d3885fe145c2f7f5c3b8.zip
test: add Pylint configuration + fix warnings
-rw-r--r--test/.pylintrc108
-rw-r--r--test/cavp.py13
-rw-r--r--test/file.py22
-rw-r--r--test/nist-sp-800-38a.py7
4 files changed, 133 insertions, 17 deletions
diff --git a/test/.pylintrc b/test/.pylintrc
new file mode 100644
index 0000000..3a9b28f
--- /dev/null
+++ b/test/.pylintrc
@@ -0,0 +1,108 @@
+[MESSAGES CONTROL]
+
+# Only show warnings with the listed confidence levels. Leave empty to show
+# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
+confidence=
+
+# Enable the message, report, category or checker with the given id(s). You can
+# either give multiple identifier separated by comma (,) or put this option
+# multiple time (only on the command line, not in the configuration file where
+# it should appear only once). See also the "--disable" option for examples.
+#enable=
+
+# Disable the message, report, category or checker with the given id(s). You
+# can either give multiple identifiers separated by comma (,) or put this
+# option multiple times (only on the command line, not in the configuration
+# file where it should appear only once).You can also use "--disable=all" to
+# disable everything first and then reenable specific checks. For example, if
+# you want to run only the similarities checker, you can use "--disable=all
+# --enable=similarities". If you want to run only the classes checker, but have
+# no Warning level messages displayed, use"--disable=all --enable=classes
+# --disable=W"
+disable=missing-docstring
+
+[BASIC]
+
+# List of builtins function names that should not be used, separated by a comma
+bad-functions=
+
+# Good variable names which should always be accepted, separated by a comma
+good-names=i,e,fd,fp,iv
+
+# Bad variable names which should always be refused, separated by a comma
+bad-names=
+
+# Colon-delimited sets of names that determine each other's naming style when
+# the name regexes allow several styles.
+name-group=
+
+# Include a hint for the correct naming format with invalid-name
+include-naming-hint=no
+
+# Regular expression matching correct method names
+method-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Naming hint for method names
+method-name-hint=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression matching correct inline iteration names
+inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
+
+# Naming hint for inline iteration names
+inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
+
+# Regular expression matching correct module names
+module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
+
+# Naming hint for module names
+module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
+
+# Regular expression matching correct class names
+class-rgx=[A-Z_][a-zA-Z0-9]+$
+
+# Naming hint for class names
+class-name-hint=[A-Z_][a-zA-Z0-9]+$
+
+# Regular expression matching correct function names
+function-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Naming hint for function names
+function-name-hint=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression matching correct class attribute names
+class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
+
+# Naming hint for class attribute names
+class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
+
+# Regular expression matching correct variable names
+variable-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Naming hint for variable names
+variable-name-hint=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression matching correct constant names
+const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
+
+# Naming hint for constant names
+const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
+
+# Regular expression matching correct attribute names
+attr-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Naming hint for attribute names
+attr-name-hint=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression matching correct argument names
+argument-rgx=[a-z_][a-z0-9_]{2,30}$
+
+# Naming hint for argument names
+argument-name-hint=[a-z_][a-z0-9_]{2,30}$
+
+# Regular expression which should only match function or class names that do
+# not require a docstring.
+no-docstring-rgx=^_
+
+# Minimum line length for functions/classes that require docstrings, shorter
+# ones are exempt.
+docstring-min-length=-1
diff --git a/test/cavp.py b/test/cavp.py
index 614e8e4..a08c94b 100644
--- a/test/cavp.py
+++ b/test/cavp.py
@@ -11,11 +11,12 @@ from datetime import datetime
from enum import Enum
import logging
import os.path
+from subprocess import CalledProcessError
import sys
from tempfile import TemporaryDirectory
import zipfile
-from toolkit import *
+from toolkit import Algorithm, BlockInput, Mode, Tools
class _MultiOrderedDict(OrderedDict):
def __setitem__(self, key, value):
@@ -41,6 +42,8 @@ class TestExitCode(Enum):
class TestFile:
def __init__(self, path):
self._path = path
+ self._algorithm = None
+ self._mode = None
self._recognized = False
self._parse_path()
if not self.recognized():
@@ -103,7 +106,7 @@ class TestFile:
keys, plaintexts, ciphertexts, init_vectors = self._encryption_data
inputs = self._gen_inputs(keys, plaintexts, init_vectors)
return self._run_tests(tools.run_encrypt_block, inputs, ciphertexts, use_boxes)
- except Exception as e:
+ except CalledProcessError as e:
logging.error('Encountered an exception!')
logging.exception(e)
return TestExitCode.ERROR
@@ -116,7 +119,7 @@ class TestFile:
keys, plaintexts, ciphertexts, init_vectors = self._decryption_data
inputs = self._gen_inputs(keys, ciphertexts, init_vectors)
return self._run_tests(tools.run_decrypt_block, inputs, plaintexts, use_boxes)
- except Exception as e:
+ except CalledProcessError as e:
logging.error('Encountered an exception!')
logging.exception(e)
return TestExitCode.ERROR
@@ -177,8 +180,8 @@ class TestArchive(zipfile.ZipFile):
def enum_test_files(self):
with TemporaryDirectory() as tmp_dir:
- for p in self.namelist():
- yield TestFile(self.extract(p, tmp_dir))
+ for fp in self.namelist():
+ yield TestFile(self.extract(fp, tmp_dir))
def _build_default_log_path():
return datetime.now().strftime('{}_%Y-%m-%d_%H-%M-%S.log').format(
diff --git a/test/file.py b/test/file.py
index 14b7d35..6953d49 100644
--- a/test/file.py
+++ b/test/file.py
@@ -12,10 +12,11 @@ import filecmp
import logging
import os
import shutil
+from subprocess import CalledProcessError
import sys
from tempfile import NamedTemporaryFile
-from toolkit import *
+from toolkit import Algorithm, Mode, Tools
class TestExitCode(Enum):
SUCCESS, FAILURE, ERROR, SKIPPED = range(1, 5)
@@ -26,19 +27,22 @@ _PLAIN_EXT = 'plain'
_CIPHER_EXT = 'cipher'
def _list_dirs(root_path):
- xs = map(lambda x: os.path.join(root_path, x), os.listdir(root_path))
- return filter(os.path.isdir, xs)
+ for fp in os.listdir(root_path):
+ fp = os.path.join(root_path, fp)
+ if os.path.isdir(fp):
+ yield fp
def _list_files(root_path, ext):
- xs = glob(os.path.join(root_path, '*.{}'.format(ext)))
- return filter(os.path.isfile, xs)
+ for fp in glob(os.path.join(root_path, '*.{}'.format(ext))):
+ if os.path.isfile(fp):
+ yield fp
def _list_keys(root_path):
return _list_files(root_path, _KEY_EXT)
def _read_first_line(path):
- with open(path) as f:
- return f.readline()
+ with open(path) as fd:
+ return fd.readline()
def _read_key(key_path):
return _read_first_line(key_path)
@@ -91,7 +95,7 @@ def run_encryption_test(tools, algorithm, mode, key, plaintext_path,
else:
logging.error('The encrypted file doesn\'t match the ciphertext file')
return TestExitCode.FAILURE
- except Exception as e:
+ except CalledProcessError as e:
logging.error('Encountered an exception!')
logging.exception(e)
return TestExitCode.ERROR
@@ -115,7 +119,7 @@ def run_decryption_test(tools, algorithm, mode, key, plaintext_path,
else:
logging.error('The decrypted file doesn\'t match the plaintext file')
return TestExitCode.FAILURE
- except Exception as e:
+ except CalledProcessError as e:
logging.error('Encountered an exception!')
logging.exception(e)
return TestExitCode.ERROR
diff --git a/test/nist-sp-800-38a.py b/test/nist-sp-800-38a.py
index 300aa5b..024cfe6 100644
--- a/test/nist-sp-800-38a.py
+++ b/test/nist-sp-800-38a.py
@@ -8,9 +8,10 @@ from datetime import datetime
from enum import Enum
import logging
import os.path
+from subprocess import CalledProcessError
import sys
-from toolkit import *
+from toolkit import Algorithm, BlockInput, Mode, Tools
_TEST_PLAINTEXTS = [
'6bc1bee22e409f96e93d7e117393172a',
@@ -188,7 +189,7 @@ def run_encryption_test(tools, algorithm, mode, use_boxes=False):
return TestExitCode.SUCCESS
else:
return TestExitCode.FAILURE
- except Exception as e:
+ except CalledProcessError as e:
logging.error('Encountered an exception!')
logging.exception(e)
return TestExitCode.ERROR
@@ -209,7 +210,7 @@ def run_decryption_test(tools, algorithm, mode, use_boxes=False):
return TestExitCode.SUCCESS
else:
return TestExitCode.FAILURE
- except Exception as e:
+ except CalledProcessError as e:
logging.error('Encountered an exception!')
logging.exception(e)
return TestExitCode.ERROR