diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-20 14:47:23 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-20 14:47:23 +0200 |
| commit | 436d8f6caf2f0a2e50497b96768cea58a01337c2 (patch) | |
| tree | 084f73de8e6f3e97491d86aec7b41a18e8ab4e9e /test/file.py | |
| parent | workflows/ci: minor fixes (diff) | |
| download | aes-tools-436d8f6caf2f0a2e50497b96768cea58a01337c2.tar.gz aes-tools-436d8f6caf2f0a2e50497b96768cea58a01337c2.zip | |
workflows/ci: use Black without extra-options
Diffstat (limited to 'test/file.py')
| -rwxr-xr-x | test/file.py | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/test/file.py b/test/file.py index 6930c8d..e68d7a7 100755 --- a/test/file.py +++ b/test/file.py @@ -24,10 +24,10 @@ class TestExitCode(Enum): SUCCESS, FAILURE, ERROR, SKIPPED = range(1, 5) -_KEY_EXT = 'key' -_IV_EXT = 'iv' -_PLAIN_EXT = 'plain' -_CIPHER_EXT = 'cipher' +_KEY_EXT = "key" +_IV_EXT = "iv" +_PLAIN_EXT = "plain" +_CIPHER_EXT = "cipher" def _list_dirs(root_path): @@ -38,7 +38,7 @@ def _list_dirs(root_path): def _list_files(root_path, ext): - for path in glob(os.path.join(root_path, '*.{}'.format(ext))): + for path in glob(os.path.join(root_path, "*.{}".format(ext))): if os.path.isfile(path): yield path @@ -65,7 +65,7 @@ def _extract_test_name(key_path): def _replace_ext(path, new_ext): - return '{}.{}'.format(os.path.splitext(path)[0], new_ext) + return "{}.{}".format(os.path.splitext(path)[0], new_ext) def _extract_iv_path(key_path): @@ -91,27 +91,27 @@ def _make_output_file(): def run_encryption_test( tools, algorithm, mode, key, plaintext_path, ciphertext_path, iv=None, force=False ): - logging.debug('Running encryption test...') - logging.debug('\tPlaintext file path: %s', plaintext_path) - logging.debug('\tExpected ciphertext file path: %s', ciphertext_path) - logging.debug('\tAlgorithm: %s', algorithm) - logging.debug('\tMode: %s', mode) + logging.debug("Running encryption test...") + logging.debug("\tPlaintext file path: %s", plaintext_path) + logging.debug("\tExpected ciphertext file path: %s", ciphertext_path) + logging.debug("\tAlgorithm: %s", algorithm) + logging.debug("\tMode: %s", mode) with _make_output_file() as tmp_path: - logging.debug('\tEncrypted file path: %s', tmp_path) + logging.debug("\tEncrypted file path: %s", tmp_path) try: tools.run_encrypt_file(algorithm, mode, key, plaintext_path, tmp_path, iv) if force: - logging.warning('Overwriting expected ciphertext file') + logging.warning("Overwriting expected ciphertext file") shutil.copy(tmp_path, ciphertext_path) return TestExitCode.SKIPPED if filecmp.cmp(ciphertext_path, tmp_path): return TestExitCode.SUCCESS - logging.error('The encrypted file doesn\'t match the ciphertext file') + logging.error("The encrypted file doesn't match the ciphertext file") return TestExitCode.FAILURE except CalledProcessError as e: - logging.error('Encountered an exception!') + logging.error("Encountered an exception!") logging.exception(e) return TestExitCode.ERROR @@ -119,49 +119,49 @@ def run_encryption_test( def run_decryption_test( tools, algorithm, mode, key, plaintext_path, ciphertext_path, iv=None ): - logging.debug('Running decryption test...') - logging.debug('\tCiphertext file path: %s', ciphertext_path) - logging.debug('\tExpected plaintext file path: %s', plaintext_path) - logging.debug('\tAlgorithm: %s', algorithm) - logging.debug('\tMode: %s', mode) + logging.debug("Running decryption test...") + logging.debug("\tCiphertext file path: %s", ciphertext_path) + logging.debug("\tExpected plaintext file path: %s", plaintext_path) + logging.debug("\tAlgorithm: %s", algorithm) + logging.debug("\tMode: %s", mode) with _make_output_file() as tmp_path: - logging.debug('\tDecrypted file path: %s', tmp_path) + logging.debug("\tDecrypted file path: %s", tmp_path) try: tools.run_decrypt_file(algorithm, mode, key, ciphertext_path, tmp_path, iv) if filecmp.cmp(tmp_path, plaintext_path): return TestExitCode.SUCCESS - logging.error('The decrypted file doesn\'t match the plaintext file') + logging.error("The decrypted file doesn't match the plaintext file") return TestExitCode.FAILURE except CalledProcessError as e: - logging.error('Encountered an exception!') + logging.error("Encountered an exception!") logging.exception(e) return TestExitCode.ERROR def enum_tests(suite_dir): suite_dir = os.path.abspath(suite_dir) - logging.info('Suite directory path: %s', suite_dir) + logging.info("Suite directory path: %s", suite_dir) for algorithm_dir in _list_dirs(suite_dir): algorithm = os.path.basename(algorithm_dir) maybe_algorithm = Algorithm.try_parse(algorithm) if maybe_algorithm is None: - logging.warning('Unknown or unsupported algorithm: %s', algorithm) + logging.warning("Unknown or unsupported algorithm: %s", algorithm) continue algorithm = maybe_algorithm for mode_dir in _list_dirs(algorithm_dir): mode = os.path.basename(mode_dir) maybe_mode = Mode.try_parse(mode) if maybe_mode is None: - logging.warning('Unknown or unsupported mode: %s', mode) + logging.warning("Unknown or unsupported mode: %s", mode) continue mode = maybe_mode for key_path in _list_keys(mode_dir): key = _read_key(key_path) - logging.debug('Key: %s', key) + logging.debug("Key: %s", key) test_name = _extract_test_name(key_path) - logging.debug('Test name: %s', test_name) + logging.debug("Test name: %s", test_name) iv = None if mode.requires_init_vector(): iv_path = _extract_iv_path(key_path) @@ -178,7 +178,7 @@ _script_name = os.path.splitext(os.path.basename(__file__))[0] def _setup_logging(verbose=False): level = logging.DEBUG if verbose else logging.INFO logging.basicConfig( - format='%(asctime)s | %(module)s | %(levelname)s | %(message)s', level=level + format="%(asctime)s | %(module)s | %(levelname)s | %(message)s", level=level ) @@ -191,11 +191,11 @@ def run_tests(suite_path, tools_path=(), verbose=False, use_sde=False, force=Fal exit_codes.append(run_encryption_test(tools, *test, force)) exit_codes.append(run_decryption_test(tools, *test)) - logging.info('Test exit codes:') - logging.info('\tSkipped: %d', exit_codes.count(TestExitCode.SKIPPED)) - logging.info('\tError(s): %d', exit_codes.count(TestExitCode.ERROR)) - logging.info('\tSucceeded: %d', exit_codes.count(TestExitCode.SUCCESS)) - logging.info('\tFailed: %d', exit_codes.count(TestExitCode.FAILURE)) + logging.info("Test exit codes:") + logging.info("\tSkipped: %d", exit_codes.count(TestExitCode.SKIPPED)) + logging.info("\tError(s): %d", exit_codes.count(TestExitCode.ERROR)) + logging.info("\tSucceeded: %d", exit_codes.count(TestExitCode.SUCCESS)) + logging.info("\tFailed: %d", exit_codes.count(TestExitCode.FAILURE)) if ( exit_codes.count(TestExitCode.ERROR) == 0 @@ -211,32 +211,32 @@ def _parse_args(args=None): args = sys.argv[1:] parser = argparse.ArgumentParser() parser.add_argument( - '--path', - '-p', - dest='tools_path', - metavar='PATH', - nargs='*', - help='set file encryption utilities directory path', + "--path", + "-p", + dest="tools_path", + metavar="PATH", + nargs="*", + help="set file encryption utilities directory path", ) parser.add_argument( - '--sde', - '-e', - dest='use_sde', - action='store_true', - help='use Intel SDE to run the utilities', + "--sde", + "-e", + dest="use_sde", + action="store_true", + help="use Intel SDE to run the utilities", ) parser.add_argument( - '--verbose', '-v', action='store_true', help='verbose log output' + "--verbose", "-v", action="store_true", help="verbose log output" ) parser.add_argument( - '--force', '-f', action='store_true', help='overwrite ciphertext files' + "--force", "-f", action="store_true", help="overwrite ciphertext files" ) parser.add_argument( - '--suite', - '-s', - dest='suite_path', - default=os.path.join(_script_dir, 'data', 'file'), - help='set test suite directory path', + "--suite", + "-s", + dest="suite_path", + default=os.path.join(_script_dir, "data", "file"), + help="set test suite directory path", ) return parser.parse_args(args) @@ -245,5 +245,5 @@ def main(args=None): return run_tests(**vars(_parse_args(args))) -if __name__ == '__main__': +if __name__ == "__main__": sys.exit(main()) |
