From a5f5e7ed9b07b902af4438d76087e034abcba9b2 Mon Sep 17 00:00:00 2001 From: ng0 Date: Sat, 12 Oct 2019 18:16:07 +0000 Subject: [PATCH] format python --- contrib/scripts/gnunet-chk.py.in | 23 +- contrib/scripts/gnunet_janitor.py.in | 1 + contrib/scripts/gnunet_pyexpect.py.in | 20 +- contrib/scripts/pydiffer.py.in | 5 +- .../scripts/removetrailingwhitespace.py.in | 1 - contrib/scripts/terminate.py.in | 2 +- src/arm/test_gnunet_arm.py.in | 26 +- src/consensus/consensus-simulation.py.in | 15 +- src/dht/test_dht_tools.py.in | 29 +- src/fs/test_gnunet_fs_idx.py.in | 57 +++- src/fs/test_gnunet_fs_psd.py.in | 75 ++++- src/fs/test_gnunet_fs_rec.py.in | 90 +++++- src/integration-tests/gnunet_pyexpect.py.in | 115 ++++--- src/integration-tests/gnunet_testing.py.in | 100 ++++-- ...st_integration_bootstrap_and_connect.py.in | 2 +- .../test_integration_clique.py.in | 14 +- .../test_integration_disconnect.py.in | 300 +++++++++--------- .../test_integration_disconnect_nat.py.in | 22 +- .../test_integration_reconnect.py.in | 272 ++++++++-------- .../test_integration_reconnect_nat.py.in | 25 +- src/peerinfo-tool/test_gnunet_peerinfo.py.in | 75 ++++- src/revocation/test_local_revocation.py.in | 31 +- src/statistics/test_gnunet_statistics.py.in | 8 +- 23 files changed, 827 insertions(+), 481 deletions(-) diff --git a/contrib/scripts/gnunet-chk.py.in b/contrib/scripts/gnunet-chk.py.in index 0fb591627..7d2cf73d3 100755 --- a/contrib/scripts/gnunet-chk.py.in +++ b/contrib/scripts/gnunet-chk.py.in @@ -29,9 +29,8 @@ import sys from Crypto.Cipher import AES from functools import reduce - # Defaults -DBLOCK_SIZE = (32 * 1024) # Data block size +DBLOCK_SIZE = (32 * 1024) # Data block size # Pick a multiple of 2 here to achive 8-byte alignment! We also # probably want DBlocks to have (roughly) the same size as IBlocks. @@ -39,7 +38,7 @@ DBLOCK_SIZE = (32 * 1024) # Data block size # byte = 2 * 512 bits). DO NOT CHANGE! CHK_PER_INODE = 256 -CHK_HASH_SIZE = 64 # SHA-512 hash = 512 bits = 64 bytes +CHK_HASH_SIZE = 64 # SHA-512 hash = 512 bits = 64 bytes CHK_QUERY_SIZE = CHK_HASH_SIZE # Again a SHA-512 hash @@ -94,11 +93,11 @@ class AESKey(object): """Class for AES Keys. Contains the main key and the initialization vector. """ - key = None # The actual AES key - iv = None # The initialization vector - cipher = None # The cipher object - KEY_SIZE = 32 # AES 256-bit key = 32 bytes - IV_SIZE = AES.block_size # Initialization vector size (= AES block size) + key = None # The actual AES key + iv = None # The initialization vector + cipher = None # The cipher object + KEY_SIZE = 32 # AES 256-bit key = 32 bytes + IV_SIZE = AES.block_size # Initialization vector size (= AES block size) def __init__(self, passphrase): """Creates a new AES key. @@ -355,13 +354,15 @@ def chkuri_from_path(path): def usage(): """Prints help about using this script.""" - print(""" + print( + """ Usage: gnunet-chk.py [options] file Prints the Content Hash Key of given file in GNUNET-style URI. Options: -h, --help : prints this message -""") +""" + ) if '__main__' == __name__: @@ -373,7 +374,7 @@ if '__main__' == __name__: usage() sys.exit(2) for option, value in opts: - if option in("-h", "--help"): + if option in ("-h", "--help"): usage() sys.exit(0) if len(args) != 1: diff --git a/contrib/scripts/gnunet_janitor.py.in b/contrib/scripts/gnunet_janitor.py.in index b0b50ca76..d6834bfb4 100644 --- a/contrib/scripts/gnunet_janitor.py.in +++ b/contrib/scripts/gnunet_janitor.py.in @@ -31,6 +31,7 @@ import time import signal import terminate + def get_process_list(): result = [] pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] diff --git a/contrib/scripts/gnunet_pyexpect.py.in b/contrib/scripts/gnunet_pyexpect.py.in index 188436f51..48f8acdc1 100644 --- a/contrib/scripts/gnunet_pyexpect.py.in +++ b/contrib/scripts/gnunet_pyexpect.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -27,7 +27,7 @@ import shutil import time -class pexpect (object): +class pexpect(object): def __init__(self): super(pexpect, self).__init__() @@ -54,12 +54,22 @@ class pexpect (object): if len(stream) == 0: return True else: - print("Failed to find `{1}' in {0}, which is `{2}' ({3})".format(s, r, stream, len(stream))) + print( + "Failed to find `{1}' in {0}, which is `{2}' ({3})". + format(s, r, stream, len(stream)) + ) sys.exit(2) - raise ValueError("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format(r)) + raise ValueError( + "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'" + .format(r) + ) m = r.search(stream.decode(), flags) if not m: - print("Failed to find `{1}' in {0}, which is is `{2}'".format(s, r.pattern, stream)) + print( + "Failed to find `{1}' in {0}, which is is `{2}'".format( + s, r.pattern, stream + ) + ) sys.exit(2) stream = stream[m.end():] if s == 'stdout': diff --git a/contrib/scripts/pydiffer.py.in b/contrib/scripts/pydiffer.py.in index 35d9ffa35..08f0f4ae6 100644 --- a/contrib/scripts/pydiffer.py.in +++ b/contrib/scripts/pydiffer.py.in @@ -10,7 +10,10 @@ def getdiff(old, new): diff = [] with open(old) as a: with open(new) as b: - for l in difflib.unified_diff(a.read().splitlines(), b.read().splitlines()): + for l in difflib.unified_diff( + a.read().splitlines(), + b.read().splitlines() + ): diff.append(l) return diff diff --git a/contrib/scripts/removetrailingwhitespace.py.in b/contrib/scripts/removetrailingwhitespace.py.in index 5824fb591..e6c2d9014 100755 --- a/contrib/scripts/removetrailingwhitespace.py.in +++ b/contrib/scripts/removetrailingwhitespace.py.in @@ -3,7 +3,6 @@ import sys import re - for fileName in sys.argv[1:]: f = open(fileName, 'r+') fileString = f.read() diff --git a/contrib/scripts/terminate.py.in b/contrib/scripts/terminate.py.in index f57ac6167..2cb4a13c4 100644 --- a/contrib/scripts/terminate.py.in +++ b/contrib/scripts/terminate.py.in @@ -26,7 +26,7 @@ import subprocess import os -class dummyobj (object): +class dummyobj(object): pass diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in index 1d067b5d9..9605c4eae 100644 --- a/src/arm/test_gnunet_arm.py.in +++ b/src/arm/test_gnunet_arm.py.in @@ -56,25 +56,41 @@ def fail(result): def end_arm_failer(command, rc, stdo, stde, normal): if normal: if rc != 0: - fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + fail( + "FAIL: error running {}\nCommand output was:\n{}\n{}".format( + command, stdo, stde + ) + ) else: if rc == 0: - fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + fail( + "FAIL: expected error while running {}\nCommand output was:\n{}\n{}" + .format(command, stdo, stde) + ) def print_only_failer(command, rc, stdo, stde, normal): if normal: if rc != 0: - print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + print( + "FAIL: error running {}\nCommand output was:\n{}\n{}".format( + command, stdo, stde + ) + ) sys.exit(1) else: if rc == 0: - print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + print( + "FAIL: expected error while running {}\nCommand output was:\n{}\n{}" + .format(command, stdo, stde) + ) sys.exit(1) def r_something(to_run, extra_args, failer=None, normal=True, **kw): - rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, want_stde=True, **kw) + rc, stdo, stde = sub_run( + to_run + extra_args, nofail=True, want_stde=True, **kw + ) if failer is not None: failer(to_run + extra_args, rc, stdo, stde, normal) return (rc, stdo, stde) diff --git a/src/consensus/consensus-simulation.py.in b/src/consensus/consensus-simulation.py.in index 39daf81c6..c6b97e63f 100644 --- a/src/consensus/consensus-simulation.py.in +++ b/src/consensus/consensus-simulation.py.in @@ -46,9 +46,10 @@ def simulate(k, n, verbose): def done_p(): for x in range(k, n): - if bsc(info[x]) < n-k: + if bsc(info[x]) < n - k: return False return True + rounds = 0 while not done_p(): if verbose: @@ -65,7 +66,10 @@ def simulate(k, n, verbose): partner_physical = peers.index(partner_logical) if peer_physical < k or partner_physical < k: if verbose: - print("bad peer in connection", peer_physical, "--", partner_physical) + print( + "bad peer in connection", peer_physical, "--", + partner_physical + ) continue if peer_logical & arc == 0: # we are outgoing @@ -78,8 +82,11 @@ def simulate(k, n, verbose): ghost_partner_logical = (peer_logical - arc) % n if ghost_partner_logical & arc == 0: peer_type = peer_type + ", ghost incoming" - new_info[peer_physical] = new_info[peer_physical] | info[peer_physical] | info[partner_physical] - new_info[partner_physical] = new_info[partner_physical] | info[peer_physical] | info[partner_physical] + new_info[peer_physical] = new_info[peer_physical] | info[ + peer_physical] | info[partner_physical] + new_info[partner_physical + ] = new_info[partner_physical] | info[ + peer_physical] | info[partner_physical] else: peer_type = "incoming" if verbose > 1: diff --git a/src/dht/test_dht_tools.py.in b/src/dht/test_dht_tools.py.in index 2d9379a42..c2f95e4b5 100644 --- a/src/dht/test_dht_tools.py.in +++ b/src/dht/test_dht_tools.py.in @@ -94,20 +94,34 @@ def r_put(extra_args, **kw): def end_arm_failer(command, rc, stdo, stde, normal): if normal: if rc != 0: - fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + fail( + "FAIL: error running {}\nCommand output was:\n{}\n{}".format( + command, stdo, stde + ) + ) else: if rc == 0: - fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + fail( + "FAIL: expected error while running {}\nCommand output was:\n{}\n{}" + .format(command, stdo, stde) + ) def print_only_failer(command, rc, stdo, stde, normal): if normal: if rc != 0: - print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + print( + "FAIL: error running {}\nCommand output was:\n{}\n{}".format( + command, stdo, stde + ) + ) cleanup(1) else: if rc == 0: - print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) + print( + "FAIL: expected error while running {}\nCommand output was:\n{}\n{}" + .format(command, stdo, stde) + ) cleanup(1) @@ -122,10 +136,13 @@ print("PASS") time.sleep(1) print("TEST: Testing get...", end='') -rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo=True, failer=end_arm_failer) +rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], + want_stdo=True, + failer=end_arm_failer) stdo = stdo.decode('utf-8').replace('\r', '').splitlines() expect = "Result 0, type 8:\ntestdata".splitlines() -if len(stdo) != 2 or len(expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: +if len(stdo) != 2 or len(expect + ) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: fail("output `{}' differs from expected `{}'".format(stdo, expect)) print("PASS") diff --git a/src/fs/test_gnunet_fs_idx.py.in b/src/fs/test_gnunet_fs_idx.py.in index 4798cf503..2c8c7e8ec 100755 --- a/src/fs/test_gnunet_fs_idx.py.in +++ b/src/fs/test_gnunet_fs_idx.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -43,7 +43,9 @@ elif os.name == 'nt': unindex = './gnunet-unindex.exe' if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True + ) else: shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) @@ -53,22 +55,59 @@ arm.communicate() try: pub = pexpect() - pub.spawn(None, [publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) + pub.spawn( + None, [ + publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', + "description:Test archive", '-k', 'tst', + 'test_gnunet_fs_rec_data.tgz' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n" + ) + ) down = pexpect() - down.spawn(None, [download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) + down.spawn( + None, [ + download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', + 'test_gnunet_fs_rec_data.tar.gz', + 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + down.expect( + "stdout", + re.compile( + r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n" + ) + ) os.remove("test_gnunet_fs_rec_data.tar.gz") un = pexpect() - un.spawn(None, [unindex, '-c', 'test_gnunet_fs_idx_data.conf', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + un.spawn( + None, [ + unindex, '-c', 'test_gnunet_fs_idx_data.conf', + 'test_gnunet_fs_rec_data.tgz' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) un.expect("stdout", re.compile(r'Unindexing done\.\r?\n')) finally: - arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf']) + arm = subprocess.Popen([ + gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf' + ]) arm.communicate() if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True + ) else: shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) diff --git a/src/fs/test_gnunet_fs_psd.py.in b/src/fs/test_gnunet_fs_psd.py.in index a1e4db9d5..abb3d0b83 100755 --- a/src/fs/test_gnunet_fs_psd.py.in +++ b/src/fs/test_gnunet_fs_psd.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -38,8 +38,8 @@ except NameError: reload(sys) # Force encoding to utf-8, as this test otherwise fails -# on some systems (see #5094). In Python 3+ there is no attribute -# sys.setdefaultencoding anymore. +# on some systems (see #5094). In Python 3+ there is no attribute +# sys.setdefaultencoding anymore. if (3 < sys.version_info[0]): sys.setdefaultencoding('utf8') @@ -68,9 +68,11 @@ if "GNUNET_PREFIX" in os.environ: else: print("You need to export GNUNET_PREFIX") sys.exit(1) - + if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True + ) else: shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) @@ -80,23 +82,68 @@ arm.communicate() # first, basic publish-search-download run try: pub = pexpect() - pub.spawn(None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - pub.expect("stdout", re.compile(r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) + pub.spawn( + None, [ + publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', + "description:Test archive", '-k', 'tst', + 'test_gnunet_fs_rec_data.tgz' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + pub.expect( + "stdout", + re.compile(r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n") + ) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n" + ) + ) s = pexpect() - s.spawn(None, [search, '-V', '-t', '1000 ms', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'tst'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - s.expect("stdout", re.compile(r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n')) + s.spawn( + None, [ + search, '-V', '-t', '1000 ms', '-N', '1', '-c', + 'test_gnunet_fs_psd_data.conf', 'tst' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + s.expect( + "stdout", + re.compile( + r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n' + ) + ) down = pexpect() - down.spawn(None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) + down.spawn( + None, [ + download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', + 'test_gnunet_fs_rec_data.tar.gz', + 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + down.expect( + "stdout", + re.compile( + r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n" + ) + ) os.remove("test_gnunet_fs_rec_data.tar.gz") finally: - arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf']) + arm = subprocess.Popen([ + gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf' + ]) arm.communicate() if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True + ) else: shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) diff --git a/src/fs/test_gnunet_fs_rec.py.in b/src/fs/test_gnunet_fs_rec.py.in index 0f881564f..0e1512b26 100755 --- a/src/fs/test_gnunet_fs_rec.py.in +++ b/src/fs/test_gnunet_fs_rec.py.in @@ -50,7 +50,9 @@ elif os.name == 'nt': directory = './gnunet-directory.exe' if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True + ) else: shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) @@ -65,33 +67,83 @@ tar.extractall() # first, basic publish-search-download run try: pub = pexpect() - pub.spawn(None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + pub.spawn( + None, [ + publish, '-c', 'test_gnunet_fs_rec_data.conf', '-k', 'testdir', + 'dir/' + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) # Can't say much for publishing, except that the last one is the toplevel directory pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n" + ) + ) pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n" + ) + ) pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n" + ) + ) pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n" + ) + ) pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n" + ) + ) pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) - pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) - pub.expect("stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) + pub.expect( + "stdout", + re.compile( + r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n" + ) + ) + pub.expect( + "stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n") + ) m = pub.expect("stdout", re.compile(r".+\r?\n")) if not m: sys.exit(3) output = m.string - url = output[output.find("`")+1:output.find("'")] + url = output[output.find("`") + 1:output.find("'")] down = pexpect() - down.spawn(None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + down.spawn( + None, [ + download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', + 'rdir.gnd', url + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n")) d = pexpect() - d.spawn(None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + d.spawn( + None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n")) d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n")) d.expect("stdout", re.compile(r"COPYING (.*)\r?\n")) @@ -101,14 +153,20 @@ try: os.remove("rdir/a.gnd") diff = dcdiff('dir', 'rdir') if len(diff) != 0: - raise Exception("Unexpected difference between source directory and downloaded result:\n{}".format(diff)) - + raise Exception( + "Unexpected difference between source directory and downloaded result:\n{}" + .format(diff) + ) finally: - arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) + arm = subprocess.Popen([ + gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf' + ]) arm.communicate() if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True + ) else: shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) shutil.rmtree("dir", True) diff --git a/src/integration-tests/gnunet_pyexpect.py.in b/src/integration-tests/gnunet_pyexpect.py.in index d757634a5..aad84e4f7 100644 --- a/src/integration-tests/gnunet_pyexpect.py.in +++ b/src/integration-tests/gnunet_pyexpect.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -26,58 +26,69 @@ import sys import shutil import time -class pexpect (object): - def __init__ (self): - super (pexpect, self).__init__ () - def spawn (self, stdin, arglist, *pargs, **kwargs): - env = kwargs.pop ('env', None) - if env is None: - env = os.environ.copy () - # This messes up some testcases, disable log redirection - env.pop ('GNUNET_FORCE_LOGFILE', None) - self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs) - if self.proc is None: - print ("Failed to spawn a process {0}".format (arglist)) - sys.exit (1) - if stdin is not None: - self.stdo, self.stde = self.proc.communicate (stdin) - else: - self.stdo, self.stde = self.proc.communicate () - return self.proc +class pexpect(object): + def __init__(self): + super(pexpect, self).__init__() + + def spawn(self, stdin, arglist, *pargs, **kwargs): + env = kwargs.pop('env', None) + if env is None: + env = os.environ.copy() + # This messes up some testcases, disable log redirection + env.pop('GNUNET_FORCE_LOGFILE', None) + self.proc = subprocess.Popen(arglist, *pargs, env=env, **kwargs) + if self.proc is None: + print("Failed to spawn a process {0}".format(arglist)) + sys.exit(1) + if stdin is not None: + self.stdo, self.stde = self.proc.communicate(stdin) + else: + self.stdo, self.stde = self.proc.communicate() + return self.proc - def expect (self, s, r, flags=0): - stream = self.stdo if s == 'stdout' else self.stde - if isinstance (r, str): - if r == "EOF": - if len (stream) == 0: - return True + def expect(self, s, r, flags=0): + stream = self.stdo if s == 'stdout' else self.stde + if isinstance(r, str): + if r == "EOF": + if len(stream) == 0: + return True + else: + print( + "Failed to find `{1}' in {0}, which is `{2}' ({3})". + format(s, r, stream, len(stream)) + ) + sys.exit(2) + raise ValueError( + "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'" + .format(r) + ) + m = r.search(stream, flags) + if not m: + print( + "Failed to find `{1}' in {0}, which is is `{2}'".format( + s, r.pattern, stream + ) + ) + sys.exit(2) + stream = stream[m.end():] + if s == 'stdout': + self.stdo = stream else: - print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream))) - sys.exit (2) - raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r)) - m = r.search (stream, flags) - if not m: - print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream)) - sys.exit (2) - stream = stream[m.end ():] - if s == 'stdout': - self.stdo = stream - else: - self.stde = stream - return m + self.stde = stream + return m - def read (self, s, size=-1): - stream = self.stdo if s == 'stdout' else self.stde - result = "" - if size < 0: - result = stream - new_stream = "" - else: - result = stream[0:size] - new_stream = stream[size:] - if s == 'stdout': - self.stdo = new_stream - else: - self.stde = new_stream - return result + def read(self, s, size=-1): + stream = self.stdo if s == 'stdout' else self.stde + result = "" + if size < 0: + result = stream + new_stream = "" + else: + result = stream[0:size] + new_stream = stream[size:] + if s == 'stdout': + self.stdo = new_stream + else: + self.stde = new_stream + return result diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in index c3596d232..10f9d4475 100644 --- a/src/integration-tests/gnunet_testing.py.in +++ b/src/integration-tests/gnunet_testing.py.in @@ -30,11 +30,13 @@ import logging logger = logging.getLogger() handler = logging.StreamHandler() formatter = logging.Formatter( - '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') + '%(asctime)s %(name)-12s %(levelname)-8s %(message)s' +) handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.DEBUG) + class Check(object): def __init__(self, test): self.fulfilled = False @@ -92,7 +94,9 @@ class Check(object): neg += 1 else: pos += 1 - logger.debug('%s out of %s conditions fulfilled', str(pos), str(pos+neg)) + logger.debug( + '%s out of %s conditions fulfilled', str(pos), str(pos + neg) + ) return self.fulfilled def reset(self): @@ -115,9 +119,13 @@ class Condition(object): def evaluate(self, failed_only): if ((self.fulfilled == False) and (failed_only == True)): - logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled)) + logger.debug( + '%s condition for was %s', str(self.type), str(self.fulfilled) + ) elif (failed_only == False): - logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled)) + logger.debug( + '%s condition for was %s', str(self.type), str(self.fulfilled) + ) return self.fulfilled @@ -140,9 +148,15 @@ class FileExistCondition(Condition): def evaluate(self, failed_only): if ((self.fulfilled == False) and (failed_only == True)): - logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled)) + logger.debug( + '%s confition for file %s was %s', str(self.type), self.file, + str(self.fulfilled) + ) elif (failed_only == False): - logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled)) + logger.debug( + '%s confition for file %s was %s', str(self.type), self.file, + str(self.fulfilled) + ) return self.fulfilled @@ -158,7 +172,9 @@ class StatisticsCondition(Condition): def check(self): if (self.fulfilled == False): - self.result = self.peer.get_statistics_value(self.subsystem, self.name) + self.result = self.peer.get_statistics_value( + self.subsystem, self.name + ) if (self.result == self.value): self.fulfilled = True return True @@ -174,8 +190,14 @@ class StatisticsCondition(Condition): else: fail = "" op = " == " - if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): - logger.debug('%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s', self.peer.id[:4].decode("utf-8"), self.peer.cfg, self.subsystem.ljust(12), self.name.ljust(30), self.value, op, self.result, fail) + if (((self.fulfilled == False) and (failed_only == True)) + or (failed_only == False)): + logger.debug( + '%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s', + self.peer.id[:4].decode("utf-8"), self.peer.cfg, + self.subsystem.ljust(12), self.name.ljust(30), self.value, op, + self.result, fail + ) return self.fulfilled @@ -195,8 +217,12 @@ class EqualStatisticsCondition(Condition): def check(self): if (self.fulfilled == False): - self.result = self.peer.get_statistics_value(self.subsystem, self.name) - self.result2 = self.peer2.get_statistics_value(self.subsystem2, self.name2) + self.result = self.peer.get_statistics_value( + self.subsystem, self.name + ) + self.result2 = self.peer2.get_statistics_value( + self.subsystem2, self.name2 + ) if (self.result == self.result2): self.fulfilled = True return True @@ -206,8 +232,14 @@ class EqualStatisticsCondition(Condition): return True def evaluate(self, failed_only): - if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): - logger.debug('%s %s %s == %s %s %s %s %s', self.peer.id[:4], self.subsystem.ljust(12), self.name.ljust(30), self.result, self.peer2.id[:4], self.subsystem2.ljust(12), self.name2.ljust(30), self.result2) + if (((self.fulfilled == False) and (failed_only == True)) + or (failed_only == False)): + logger.debug( + '%s %s %s == %s %s %s %s %s', self.peer.id[:4], + self.subsystem.ljust(12), self.name.ljust(30), self.result, + self.peer2.id[:4], self.subsystem2.ljust(12), + self.name2.ljust(30), self.result2 + ) return self.fulfilled @@ -262,19 +294,23 @@ class Peer(object): # print('ERROR! Peer using cfg ' + # self.cfg + # ' could not be stopped') - logger.debug('ERROR! Peer using cfg %s could not be stopped', self.cfg) + logger.debug( + 'ERROR! Peer using cfg %s could not be stopped', self.cfg + ) self.started = False return ret else: return False def start(self): - os.unsetenv ("XDG_CONFIG_HOME") - os.unsetenv ("XDG_DATA_HOME") - os.unsetenv ("XDG_CACHE_HOME") + os.unsetenv("XDG_CONFIG_HOME") + os.unsetenv("XDG_DATA_HOME") + os.unsetenv("XDG_CACHE_HOME") self.test.p("Starting peer using cfg " + self.cfg) try: - server = subprocess.Popen([self.test.gnunetarm, '-sq', '-c', self.cfg]) + server = subprocess.Popen([ + self.test.gnunetarm, '-sq', '-c', self.cfg + ]) server.communicate() except OSError: # print("Can not start peer") @@ -285,7 +321,11 @@ class Peer(object): test = '' try: server = pexpect() - server.spawn(None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + server.spawn( + None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) test = server.read("stdout", 1024) except OSError: # print("Can not get peer identity") @@ -299,7 +339,9 @@ class Peer(object): return False self.test.p("Stopping peer using cfg " + self.cfg) try: - server = subprocess.Popen([self.test.gnunetarm, '-eq', '-c', self.cfg]) + server = subprocess.Popen([ + self.test.gnunetarm, '-eq', '-c', self.cfg + ]) server.communicate() except OSError: # print("Can not stop peer") @@ -310,7 +352,14 @@ class Peer(object): def get_statistics_value(self, subsystem, name): server = pexpect() - server.spawn(None, [self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, '-s', subsystem], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + server.spawn( + None, [ + self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, + '-s', subsystem + ], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) # server.expect ("stdout", re.compile (r"")) test = server.read("stdout", 10240) tests = test.partition(b'\n') @@ -319,9 +368,14 @@ class Peer(object): tests = (tests[0][:-1], tests[1], tests[2]) tests = tests[0] result = tests.decode("utf-8").strip() - logger.debug('running gnunet-statistics %s for %s "/" %s yields %s', self.cfg, name, subsystem, result) + logger.debug( + 'running gnunet-statistics %s for %s "/" %s yields %s', self.cfg, + name, subsystem, result + ) if (result.isdigit() == True): return result else: - logger.debug('Invalid statistics value: %s is not a number!', result) + logger.debug( + 'Invalid statistics value: %s is not a number!', result + ) return -1 diff --git a/src/integration-tests/test_integration_bootstrap_and_connect.py.in b/src/integration-tests/test_integration_bootstrap_and_connect.py.in index 4b4b35629..ddac326cd 100755 --- a/src/integration-tests/test_integration_bootstrap_and_connect.py.in +++ b/src/integration-tests/test_integration_bootstrap_and_connect.py.in @@ -32,7 +32,6 @@ from gnunet_testing import Check from gnunet_testing import Condition from gnunet_testing import * - # # This test tests if a fresh peer bootstraps from a hostlist server and then # successfully connects to the server @@ -124,6 +123,7 @@ def check(): check.run_blocking(check_timeout, success_cont, fail_cont) + # # Test execution # diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in index 0444cf249..a23c025ca 100755 --- a/src/integration-tests/test_integration_clique.py.in +++ b/src/integration-tests/test_integration_clique.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -113,9 +113,13 @@ def check_connect(): check.add(StatisticsCondition(client, 'dht', '# peers connected', 2)) check.add(StatisticsCondition(client, 'fs', '# peers connected', 2)) - check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2)) + check.add( + StatisticsCondition(client_nat, 'transport', '# peers connected', 2) + ) check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2)) - check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2)) + check.add( + StatisticsCondition(client_nat, 'topology', '# peers connected', 2) + ) check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2)) check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2)) @@ -127,6 +131,7 @@ def check_connect(): check.run_blocking(check_timeout, success_cont, fail_cont) + # # Test execution # @@ -199,7 +204,8 @@ def run(): cleanup() sys.exit(success) - if ((client.started == True) and (client_nat.started == True) and (server.started == True)): + if ((client.started == True) and (client_nat.started == True) + and (server.started == True)): test.p('Peers started, running check') check_connect() diff --git a/src/integration-tests/test_integration_disconnect.py.in b/src/integration-tests/test_integration_disconnect.py.in index 737014e61..9861728c2 100755 --- a/src/integration-tests/test_integration_disconnect.py.in +++ b/src/integration-tests/test_integration_disconnect.py.in @@ -32,7 +32,6 @@ from gnunet_testing import Check from gnunet_testing import Condition from gnunet_testing import * - # # This test tests if a fresh peer bootstraps from a hostlist server and then # successfully connects to the server. When both peers are connected @@ -48,158 +47,169 @@ verbose = True check_timeout = 180 if os.name == "nt": - tmp = os.getenv ("TEMP") - signals = [signal.SIGTERM, signal.SIGINT] + tmp = os.getenv("TEMP") + signals = [signal.SIGTERM, signal.SIGINT] else: - tmp = "/tmp" - signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] - -def cleanup_onerror (function, path, excinfo): - import stat - if not os.path.exists (path): - pass - elif not os.access(path, os.W_OK): - # Is the error an access error ? - os.chmod (path, stat.S_IWUSR) - function (path) - else: - raise - -def cleanup (): - shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), False, cleanup_onerror) - shutil.rmtree (os.path.join (tmp, "c_no_nat_client"), False, cleanup_onerror) - - -def success_disconnect_cont (check): - print('Peers disconnected successfully') - global success - success = True; - - -def fail_disconnect_cont (check): - global success - success = False; - print('Peers failed to disconnect') - check.evaluate(True) - -def check_disconnect (): - test.p ('Shutting down bootstrap server') - server.stop () - check = Check (test) - check.add (StatisticsCondition (client, 'transport', '# peers connected',0)) - check.add (StatisticsCondition (client, 'core', '# peers connected',0)) - check.add (StatisticsCondition (client, 'topology', '# peers connected',0)) - check.add (StatisticsCondition (client, 'dht', '# peers connected',0)) - check.add (StatisticsCondition (client, 'fs', '# peers connected',0)) - check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont) - - -def success_connect_cont (check): - print('Peers connected successfully') - check_disconnect () - - -def fail_connect_cont (check): - global success - success= False - print('Peers failed to connected!') - check.evaluate(True) - - -def check_connect (): - check = Check (test) - check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) - check.add (StatisticsCondition (server, 'core', '# peers connected',1)) - check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) - check.add (StatisticsCondition (server, 'dht', '# peers connected',1)) - check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) - - check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) - check.add (StatisticsCondition (client, 'core', '# peers connected',1)) - check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) - check.add (StatisticsCondition (client, 'dht', '# peers connected',1)) - check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) - - check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) + tmp = "/tmp" + signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] + + +def cleanup_onerror(function, path, excinfo): + import stat + if not os.path.exists(path): + pass + elif not os.access(path, os.W_OK): + # Is the error an access error ? + os.chmod(path, stat.S_IWUSR) + function(path) + else: + raise + + +def cleanup(): + shutil.rmtree( + os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror + ) + shutil.rmtree(os.path.join(tmp, "c_no_nat_client"), False, cleanup_onerror) + + +def success_disconnect_cont(check): + print('Peers disconnected successfully') + global success + success = True + + +def fail_disconnect_cont(check): + global success + success = False + print('Peers failed to disconnect') + check.evaluate(True) + + +def check_disconnect(): + test.p('Shutting down bootstrap server') + server.stop() + check = Check(test) + check.add(StatisticsCondition(client, 'transport', '# peers connected', 0)) + check.add(StatisticsCondition(client, 'core', '# peers connected', 0)) + check.add(StatisticsCondition(client, 'topology', '# peers connected', 0)) + check.add(StatisticsCondition(client, 'dht', '# peers connected', 0)) + check.add(StatisticsCondition(client, 'fs', '# peers connected', 0)) + check.run_blocking( + check_timeout, success_disconnect_cont, fail_disconnect_cont + ) + + +def success_connect_cont(check): + print('Peers connected successfully') + check_disconnect() + + +def fail_connect_cont(check): + global success + success = False + print('Peers failed to connected!') + check.evaluate(True) + + +def check_connect(): + check = Check(test) + check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'dht', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) + + check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'dht', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) + + check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) + # # Test execution # -def SigHandler(signum = None, frame = None): - global success - global server - global client - - print('Test was aborted!') - if (None != server): - server.stop () - if (None != client): - client.stop () - cleanup () - sys.exit(success) - -def run (): - global success - global test - global server - global client - - server = None - client = None - success = False - - for sig in signals: - signal.signal(sig, SigHandler) - - test = Test ('test_integration_bootstrap_and_connect.py', verbose) - cleanup () - - server = Peer(test, './confs/c_bootstrap_server.conf'); - client = Peer(test, './confs/c_no_nat_client.conf'); - - if (True != server.start()): - print('Failed to start server') - if (None != server): - server.stop () - cleanup () - sys.exit(success) - - # Give the server time to start - time.sleep(5) - - if (True != client.start()): - print('Failed to start client') - if (None != server): - server.stop () - if (None != client): - client.stop () - cleanup () - sys.exit(success) - - if ((client.started == True) and (server.started == True)): - test.p ('Peers started, running check') - time.sleep(5) - check_connect () - server.stop () - client.stop () - - cleanup () - - if (success == False): - print ('Test failed') - return False - else: - return True + +def SigHandler(signum=None, frame=None): + global success + global server + global client + + print('Test was aborted!') + if (None != server): + server.stop() + if (None != client): + client.stop() + cleanup() + sys.exit(success) + + +def run(): + global success + global test + global server + global client + + server = None + client = None + success = False + + for sig in signals: + signal.signal(sig, SigHandler) + + test = Test('test_integration_bootstrap_and_connect.py', verbose) + cleanup() + + server = Peer(test, './confs/c_bootstrap_server.conf') + client = Peer(test, './confs/c_no_nat_client.conf') + + if (True != server.start()): + print('Failed to start server') + if (None != server): + server.stop() + cleanup() + sys.exit(success) + + # Give the server time to start + time.sleep(5) + + if (True != client.start()): + print('Failed to start client') + if (None != server): + server.stop() + if (None != client): + client.stop() + cleanup() + sys.exit(success) + + if ((client.started == True) and (server.started == True)): + test.p('Peers started, running check') + time.sleep(5) + check_connect() + server.stop() + client.stop() + + cleanup() + + if (success == False): + print('Test failed') + return False + else: + return True + try: - run () + run() except (KeyboardInterrupt, SystemExit): - print('Test interrupted') - server.stop () - client.stop () - cleanup () + print('Test interrupted') + server.stop() + client.stop() + cleanup() if (success == False): - sys.exit(1) + sys.exit(1) else: - sys.exit(0) + sys.exit(0) diff --git a/src/integration-tests/test_integration_disconnect_nat.py.in b/src/integration-tests/test_integration_disconnect_nat.py.in index c3d5d8901..d3ff84ebe 100755 --- a/src/integration-tests/test_integration_disconnect_nat.py.in +++ b/src/integration-tests/test_integration_disconnect_nat.py.in @@ -32,7 +32,6 @@ from gnunet_testing import Check from gnunet_testing import Condition from gnunet_testing import * - # # This test tests if a fresh peer bootstraps from a hostlist server and then # successfully connects to the server. When both peers are connected @@ -68,7 +67,9 @@ def cleanup_onerror(function, path, excinfo): def cleanup(): - shutil.rmtree(os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror) + shutil.rmtree( + os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror + ) shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror) @@ -80,7 +81,7 @@ def success_disconnect_cont(check): def fail_disconnect_cont(check): global success - success = False; + success = False print('Peers failed to disconnect') check.evaluate(True) @@ -96,7 +97,9 @@ def check_disconnect(): check.add(StatisticsCondition(server, 'topology', '# peers connected', 0)) check.add(StatisticsCondition(server, 'dht', '# peers connected', 0)) check.add(StatisticsCondition(server, 'fs', '# peers connected', 0)) - check.run_blocking(check_timeout, success_disconnect_cont, fail_disconnect_cont) + check.run_blocking( + check_timeout, success_disconnect_cont, fail_disconnect_cont + ) def success_connect_cont(check): @@ -115,9 +118,13 @@ def check_connect(): global server global nat_client check = Check(test) - check.add(StatisticsCondition(nat_client, 'transport', '# peers connected', 1)) + check.add( + StatisticsCondition(nat_client, 'transport', '# peers connected', 1) + ) check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1)) - check.add(StatisticsCondition(nat_client, 'topology', '# peers connected', 1)) + check.add( + StatisticsCondition(nat_client, 'topology', '# peers connected', 1) + ) check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1)) check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1)) @@ -134,6 +141,7 @@ def check_connect(): # Test execution # + def SigHandler(signum=None, frame=None): global success global server @@ -204,7 +212,7 @@ def run(): try: run() -except(KeyboardInterrupt, SystemExit): +except (KeyboardInterrupt, SystemExit): print('Test interrupted') server.stop() nat_client.stop() diff --git a/src/integration-tests/test_integration_reconnect.py.in b/src/integration-tests/test_integration_reconnect.py.in index 8c4193680..5bffb72e3 100755 --- a/src/integration-tests/test_integration_reconnect.py.in +++ b/src/integration-tests/test_integration_reconnect.py.in @@ -32,7 +32,6 @@ from gnunet_testing import Check from gnunet_testing import Condition from gnunet_testing import * - # # This test tests if a fresh peer bootstraps from a hostlist server and then # successfully connects to the server. When both peers are connected @@ -43,195 +42,196 @@ from gnunet_testing import * #definitions - testname = "test_integration_restart" verbose = True check_timeout = 180 if os.name == "nt": - tmp = os.getenv ("TEMP") - signals = [signal.SIGTERM, signal.SIGINT] + tmp = os.getenv("TEMP") + signals = [signal.SIGTERM, signal.SIGINT] else: - tmp = "/tmp" - signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] - -def cleanup_onerror (function, path, excinfo): - import stat - if not os.path.exists (path): - pass - elif not os.access(path, os.W_OK): - # Is the error an access error ? - os.chmod (path, stat.S_IWUSR) - function (path) - else: - raise - -def cleanup (): + tmp = "/tmp" + signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] + + +def cleanup_onerror(function, path, excinfo): + import stat + if not os.path.exists(path): + pass + elif not os.access(path, os.W_OK): + # Is the error an access error ? + os.chmod(path, stat.S_IWUSR) + function(path) + else: + raise + + +def cleanup(): retries = 10 - path = os.path.join (tmp, "c_bootstrap_server") - test.p ("Removing " + path) + path = os.path.join(tmp, "c_bootstrap_server") + test.p("Removing " + path) while ((os.path.exists(path)) and (retries > 0)): - shutil.rmtree ((path), False, cleanup_onerror) - time.sleep (1) + shutil.rmtree((path), False, cleanup_onerror) + time.sleep(1) retries -= 1 if (os.path.exists(path)): - test.p ("Failed to remove " + path) - + test.p("Failed to remove " + path) retries = 10 - path = os.path.join (tmp, "c_no_nat_client") - test.p ("Removing " + path) + path = os.path.join(tmp, "c_no_nat_client") + test.p("Removing " + path) while ((os.path.exists(path)) and (retries > 0)): - shutil.rmtree ((path), False, cleanup_onerror) - time.sleep (1) + shutil.rmtree((path), False, cleanup_onerror) + time.sleep(1) retries -= 1 if (os.path.exists(path)): - test.p ("Failed to remove " + path) + test.p("Failed to remove " + path) + -def success_restart_cont (check): - global success - print('Peers connected successfully after restart') - server.stop () - client.stop () - success = True; +def success_restart_cont(check): + global success + print('Peers connected successfully after restart') + server.stop() + client.stop() + success = True -def fail_restart_cont (check): - global success - success = False; - print('Peers failed to connect after restart') - check.evaluate(True) +def fail_restart_cont(check): + global success + success = False + print('Peers failed to connect after restart') + check.evaluate(True) -def success_connect_cont (check): - print('Peers connected successfully') - server.stop () - client.stop () +def success_connect_cont(check): + print('Peers connected successfully') + server.stop() + client.stop() - time.sleep(5) + time.sleep(5) - test.p ('Restarting client & server') - server.start () - client.start () + test.p('Restarting client & server') + server.start() + client.start() - check = Check (test) - check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) - check.add (StatisticsCondition (client, 'core', '# peers connected',1)) - check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) - check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) + check = Check(test) + check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) - check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) - check.add (StatisticsCondition (server, 'core', '# peers connected',1)) - check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) - check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) + check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) - check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont) + check.run_blocking(check_timeout, success_restart_cont, fail_restart_cont) -def fail_connect_cont (check): - global success - success= False; - print('Peers failed to connect') - check.evaluate(True) +def fail_connect_cont(check): + global success + success = False + print('Peers failed to connect') + check.evaluate(True) -def check_connect (): - check = Check (test) - check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) - check.add (StatisticsCondition (client, 'core', '# peers connected',1)) - check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) - check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) +def check_connect(): + check = Check(test) + check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) + check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) - check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) - check.add (StatisticsCondition (server, 'core', '# peers connected',1)) - check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) - check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) + check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) + check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) + + check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) - check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) # # Test execution # -def SigHandler(signum = None, frame = None): - global success - global server - global client - - print('Test was aborted!') - if (None != server): - server.stop () - if (None != client): - client.stop () - cleanup () - sys.exit(success) +def SigHandler(signum=None, frame=None): + global success + global server + global client -def run (): - global success - global test - global server - global client + print('Test was aborted!') + if (None != server): + server.stop() + if (None != client): + client.stop() + cleanup() + sys.exit(success) - success = False - server = None - client = None - for sig in signals: - signal.signal(sig, SigHandler) +def run(): + global success + global test + global server + global client + success = False + server = None + client = None - test = Test ('test_integration_disconnect', verbose) - cleanup () - server = Peer(test, './confs/c_bootstrap_server.conf'); - server.start(); + for sig in signals: + signal.signal(sig, SigHandler) - client = Peer(test, './confs/c_no_nat_client.conf'); - client.start(); + test = Test('test_integration_disconnect', verbose) + cleanup() + server = Peer(test, './confs/c_bootstrap_server.conf') + server.start() + client = Peer(test, './confs/c_no_nat_client.conf') + client.start() - if (True != server.start()): - print('Failed to start server') - if (None != server): - server.stop () - if (None != server): - client.stop () - cleanup () - sys.exit(success) + if (True != server.start()): + print('Failed to start server') + if (None != server): + server.stop() + if (None != server): + client.stop() + cleanup() + sys.exit(success) - # Give the server time to start - time.sleep(5) + # Give the server time to start + time.sleep(5) - if (True != client.start()): - print('Failed to start client') - if (None != server): - server.stop () - if (None != server): - client.stop () - cleanup () - sys.exit(success) + if (True != client.start()): + print('Failed to start client') + if (None != server): + server.stop() + if (None != server): + client.stop() + cleanup() + sys.exit(success) - check_connect () + check_connect() - server.stop () - client.stop () - cleanup () + server.stop() + client.stop() + cleanup() - if (success == False): - print ('Test failed') - return True - else: - return False + if (success == False): + print('Test failed') + return True + else: + return False try: - run () + run() except (KeyboardInterrupt, SystemExit): print('Test interrupted') - server.stop () - client.stop () - cleanup () + server.stop() + client.stop() + cleanup() if (success == False): - sys.exit(1) + sys.exit(1) else: - sys.exit(0) + sys.exit(0) diff --git a/src/integration-tests/test_integration_reconnect_nat.py.in b/src/integration-tests/test_integration_reconnect_nat.py.in index 45626d50d..751a0484b 100755 --- a/src/integration-tests/test_integration_reconnect_nat.py.in +++ b/src/integration-tests/test_integration_reconnect_nat.py.in @@ -32,7 +32,6 @@ from gnunet_testing import Check from gnunet_testing import Condition from gnunet_testing import * - # # This test tests if a fresh peer bootstraps from a hostlist server and then # successfully connects to the server. When both peers are connected @@ -43,7 +42,6 @@ from gnunet_testing import * # definitions - testname = "test_integration_restart" verbose = True check_timeout = 180 @@ -82,7 +80,7 @@ def cleanup(): retries = 10 path = os.path.join(tmp, "c_nat_client") test.p("Removing " + path) - while((os.path.exists(path)) and(retries > 0)): + while ((os.path.exists(path)) and (retries > 0)): shutil.rmtree((path), False, cleanup_onerror) time.sleep(1) retries -= 1 @@ -91,18 +89,18 @@ def cleanup(): def success_restart_cont(check): - global success - print('Peers connected successfully after restart') - server.stop() - client.stop() - success = True + global success + print('Peers connected successfully after restart') + server.stop() + client.stop() + success = True def fail_restart_cont(check): - global success - success = False - print('Peers failed to connect after restart') - check.evaluate(True) + global success + success = False + print('Peers failed to connect after restart') + check.evaluate(True) def success_connect_cont(check): @@ -151,6 +149,7 @@ def check_connect(): check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) + # # Test execution # @@ -227,7 +226,7 @@ def run(): try: run() -except(KeyboardInterrupt, SystemExit): +except (KeyboardInterrupt, SystemExit): print('Test interrupted') server.stop() client.stop() diff --git a/src/peerinfo-tool/test_gnunet_peerinfo.py.in b/src/peerinfo-tool/test_gnunet_peerinfo.py.in index d07224b14..5d9daa930 100755 --- a/src/peerinfo-tool/test_gnunet_peerinfo.py.in +++ b/src/peerinfo-tool/test_gnunet_peerinfo.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -43,53 +43,94 @@ elif os.name == 'nt': pinfo = pexpect() - if os.name == "nt": shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True) else: shutil.rmtree("/tmp/gnunet-test-peerinfo", True) # create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable! -hkk = subprocess.Popen([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey']) +hkk = subprocess.Popen([ + gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', + '/tmp/gnunet-test-peerinfo/.hostkey' +]) hkk.communicate() -arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf']) +arm = subprocess.Popen([ + gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf' +]) arm.communicate() try: - pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + pinfo.spawn( + None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n')) - pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - pinfo.expect("stdout", re.compile(r'....................................................\r?\n')) - - pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - pinfo.expect("stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n')) - - arm = subprocess.Popen([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf']) + pinfo.spawn( + None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + pinfo.expect( + "stdout", + re. + compile(r'....................................................\r?\n') + ) + + pinfo.spawn( + None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + pinfo.expect( + "stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n') + ) + + arm = subprocess.Popen([ + gnunetarm, '-q', '-i', 'transport', '-c', + 'test_gnunet_peerinfo_data.conf' + ]) arm.communicate() time.sleep(1) - pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + pinfo.spawn( + None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) pinfo.expect("stdout", re.compile("Peer `.*'\r?\n")) m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n")) while len(m.group(0)) > 0: m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)")) - pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + pinfo.spawn( + None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) pinfo.expect("stdout", re.compile("Peer `.*'\r?\n")) m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n")) while len(m.group(0)) > 0: m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)")) - pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + pinfo.spawn( + None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) pid = pinfo.read("stdout") pid.strip() finally: - arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf']) + arm = subprocess.Popen([ + gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf' + ]) arm.communicate() if os.name == "nt": - shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True) + shutil.rmtree( + os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True + ) else: shutil.rmtree("/tmp/gnunet-test-peerinfo", True) diff --git a/src/revocation/test_local_revocation.py.in b/src/revocation/test_local_revocation.py.in index 4cc6119ca..d73d0a869 100644 --- a/src/revocation/test_local_revocation.py.in +++ b/src/revocation/test_local_revocation.py.in @@ -11,7 +11,7 @@ # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # @@ -39,7 +39,10 @@ elif os.name == 'nt': 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) +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') @@ -55,10 +58,15 @@ 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 = 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 + "'") + raise Exception( + "gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + + "'" + ) sys.stdout.flush() sys.stderr.flush() @@ -72,11 +80,15 @@ try: print("Testing key " + rev_key) sys.stdout.flush() sys.stderr.flush() - tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) + 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) + 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") @@ -86,7 +98,9 @@ try: print("Revoking key " + rev_key) sys.stdout.flush() sys.stderr.flush() - rev = subprocess.Popen([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION]) + 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") @@ -94,7 +108,8 @@ try: 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) + 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: diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in index b14dc9d9e..3a13c24f3 100644 --- a/src/statistics/test_gnunet_statistics.py.in +++ b/src/statistics/test_gnunet_statistics.py.in @@ -122,7 +122,9 @@ if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1: print("PASS") print("TEST: Set persistent value...", end='') -rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail=True, want_stdo=False) +rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], + nofail=True, + want_stdo=False) rc, stdo, stde = r_st([], nofail=True, want_stdo=True) if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: fail("FAIL: unexpected output:\n{}".format(stdo)) @@ -137,7 +139,9 @@ if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: print("PASS") print("TEST: Removing persistence...", end='') -rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], nofail=True, want_stdo=False) +rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], + nofail=True, + want_stdo=False) rc, stdo, stde = r_st([], nofail=True, want_stdo=True) if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0: fail("FAIL: unexpected output:\n{}".format(stdo)) -- 2.25.1