From e955fc4920bb3ab49307485e8bd5fe6c89438cc5 Mon Sep 17 00:00:00 2001 From: Nils Gillmann Date: Wed, 23 May 2018 07:29:10 +0000 Subject: [PATCH] revocation: test_local_revocation: Adjust to flake8 Signed-off-by: Nils Gillmann --- src/revocation/test_local_revocation.py.in | 139 ++++++++++----------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/src/revocation/test_local_revocation.py.in b/src/revocation/test_local_revocation.py.in index 28257715f..067091b58 100644 --- a/src/revocation/test_local_revocation.py.in +++ b/src/revocation/test_local_revocation.py.in @@ -1,6 +1,6 @@ #!@PYTHON@ # This file is part of GNUnet. -# (C) 2010 Christian Grothoff (and other contributing authors) +# (C) 2010, 2018 Christian Grothoff (and other contributing authors) # # GNUnet is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published @@ -26,90 +26,89 @@ import re import shutil if os.name == 'posix': - config = 'gnunet-config' - gnunetarm = 'gnunet-arm' - ident = 'gnunet-identity' - revoc = './gnunet-revocation' + config = 'gnunet-config' + gnunetarm = 'gnunet-arm' + ident = 'gnunet-identity' + revoc = './gnunet-revocation' elif os.name == 'nt': - config = 'gnunet-config.exe' - gnunetarm = 'gnunet-arm.exe' - ident = 'gnunet-identity.exe' - revoc = './gnunet-revocation.exe' + config = 'gnunet-config.exe' + gnunetarm = 'gnunet-arm.exe' + ident = 'gnunet-identity.exe' + revoc = './gnunet-revocation.exe' TEST_CONFIGURATION = "test_revocation.conf" TEST_REVOCATION_EGO = "revoc_test" - -get_clean = subprocess.Popen ([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE) -cleandir, x = get_clean.communicate () +get_clean = subprocess.Popen([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE) +cleandir, x = get_clean.communicate() cleandir = cleandir.decode("utf-8") -cleandir = cleandir.rstrip ('\n').rstrip ('\r') +cleandir = cleandir.rstrip('\n').rstrip('\r') -if os.path.isdir (cleandir): - shutil.rmtree (cleandir, True) +if os.path.isdir(cleandir): + shutil.rmtree(cleandir, True) res = 0 -arm = subprocess.Popen ([gnunetarm, '-s', '-c', TEST_CONFIGURATION]) -arm.communicate () +arm = subprocess.Popen([gnunetarm, '-s', '-c', TEST_CONFIGURATION]) +arm.communicate() try: - print ("Creating an ego " + TEST_REVOCATION_EGO) - sys.stdout.flush () - sys.stderr.flush () - idc = subprocess.Popen ([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION]) - idc.communicate () - if idc.returncode != 0: - raise Exception ("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'") + print("Creating an ego " + TEST_REVOCATION_EGO) + sys.stdout.flush() + sys.stderr.flush() + idc = subprocess.Popen([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION]) + idc.communicate() + if idc.returncode != 0: + raise Exception("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'") - sys.stdout.flush () - sys.stderr.flush () - idd = subprocess.Popen ([ident, '-d'], stdout=subprocess.PIPE) - rev_key, x = idd.communicate () - rev_key = rev_key.decode("utf-8") - if len (rev_key.split ()) < 3: - raise Exception ("can't get revocation key out of `" + rev_key + "'") - rev_key = rev_key.split ()[2] + sys.stdout.flush() + sys.stderr.flush() + idd = subprocess.Popen([ident, '-d'], stdout=subprocess.PIPE) + rev_key, x = idd.communicate() + rev_key = rev_key.decode("utf-8") + if len(rev_key.split()) < 3: + raise Exception("can't get revocation key out of `" + rev_key + "'") + rev_key = rev_key.split()[2] - print ("Testing key " + rev_key) - sys.stdout.flush () - sys.stderr.flush () - tst = subprocess.Popen ([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) - output_not_revoked, x = tst.communicate () - output_not_revoked = output_not_revoked.decode("utf-8") - if tst.returncode != 0: - raise Exception ("gnunet-revocation failed to test a key - " + str (tst.returncode) + ": " + output_not_revoked) - if 'valid' not in output_not_revoked: - res = 1 - print ("Key was not valid") - else: - print ("Key was valid") + print("Testing key " + rev_key) + sys.stdout.flush() + sys.stderr.flush() + tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) + output_not_revoked, x = tst.communicate() + output_not_revoked = output_not_revoked.decode("utf-8") + if tst.returncode != 0: + raise Exception("gnunet-revocation failed to test a key - " + str(tst.returncode) + ": " + output_not_revoked) + if 'valid' not in output_not_revoked: + res = 1 + print("Key was not valid") + else: + print("Key was valid") - print ("Revoking key " + rev_key) - sys.stdout.flush () - sys.stderr.flush () - rev = subprocess.Popen ([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION]) - rev.communicate () - if rev.returncode != 0: - raise Exception ("gnunet-revocation failed to revoke a key") + print("Revoking key " + rev_key) + sys.stdout.flush() + sys.stderr.flush() + rev = subprocess.Popen([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION]) + rev.communicate() + if rev.returncode != 0: + raise Exception("gnunet-revocation failed to revoke a key") - print ("Testing revoked key " + rev_key) - sys.stdout.flush () - sys.stderr.flush () - tst = subprocess.Popen ([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) - output_revoked, x = tst.communicate () - output_revoked = output_revoked.decode("utf-8") - if tst.returncode != 0: - raise Exception ("gnunet-revocation failed to test a revoked key") - if 'revoked' not in output_revoked: - res = 1 - print ("Key was not revoked") - else: - print ("Key was revoked") + print("Testing revoked key " + rev_key) + sys.stdout.flush() + sys.stderr.flush() + tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) + output_revoked, x = tst.communicate() + output_revoked = output_revoked.decode("utf-8") + if tst.returncode != 0: + raise Exception("gnunet-revocation failed to test a revoked key") + if 'revoked' not in output_revoked: + res = 1 + print("Key was not revoked") + else: + print("Key was revoked") finally: - arm = subprocess.Popen ([gnunetarm, '-e', '-c', TEST_CONFIGURATION]) - arm.communicate () - if os.path.isdir (cleandir): - shutil.rmtree (cleandir, True) + arm = subprocess.Popen([gnunetarm, '-e', '-c', TEST_CONFIGURATION]) + arm.communicate() + if os.path.isdir(cleandir): + shutil.rmtree(cleandir, True) -sys.exit (res) +sys.exit(res) -- 2.25.1