aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-22 12:52:12 +0000
committerNils Gillmann <ng0@n0.is>2018-05-22 12:52:12 +0000
commit5faaa453f3fcc0bf9ee2f277c56524a095c77b94 (patch)
treeb57f70605bd51cf4da186480cc8754296bf21d35 /src/statistics
parent45c1c48c29f47b317287e2fca1b4763a7cbb7452 (diff)
downloadgnunet-5faaa453f3fcc0bf9ee2f277c56524a095c77b94.tar.gz
gnunet-5faaa453f3fcc0bf9ee2f277c56524a095c77b94.zip
test_gnunet_statistics: flake8
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/test_gnunet_statistics.py.in262
1 files changed, 134 insertions, 128 deletions
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in
index 96714cf9a..64e66f238 100644
--- a/src/statistics/test_gnunet_statistics.py.in
+++ b/src/statistics/test_gnunet_statistics.py.in
@@ -8,7 +8,7 @@ import subprocess
8import time 8import time
9 9
10if os.name == "nt": 10if os.name == "nt":
11 tmp = os.getenv ("TEMP") 11 tmp = os.getenv("TEMP")
12elif None != os.environ.get("TMPDIR"): 12elif None != os.environ.get("TMPDIR"):
13 tmp = os.getenv("TMPDIR") 13 tmp = os.getenv("TMPDIR")
14elif None != os.environ.get("TMP"): 14elif None != os.environ.get("TMP"):
@@ -17,136 +17,142 @@ else:
17 tmp = "/tmp" 17 tmp = "/tmp"
18 18
19if os.name == 'nt': 19if os.name == 'nt':
20 st = './gnunet-statistics.exe' 20 st = './gnunet-statistics.exe'
21 arm = 'gnunet-arm.exe' 21 arm = 'gnunet-arm.exe'
22else: 22else:
23 st = './gnunet-statistics' 23 st = './gnunet-statistics'
24 arm = 'gnunet-arm' 24 arm = 'gnunet-arm'
25 25
26run_st = [st, '-c', 'test_statistics_api_data.conf'] 26run_st = [st, '-c', 'test_statistics_api_data.conf']
27run_arm = [arm, '-c', 'test_statistics_api_data.conf'] 27run_arm = [arm, '-c', 'test_statistics_api_data.conf']
28debug = os.getenv ('DEBUG') 28debug = os.getenv('DEBUG')
29if debug: 29if debug:
30 run_arm += [debug.split (' ')] 30 run_arm += [debug.split(' ')]
31 31
32def cleanup (): 32
33 shutil.rmtree (os.path.join (tmp, "gnunet/test-gnunet-statistics"), True) 33def cleanup():
34 34 shutil.rmtree(os.path.join(tmp, "gnunet/test-gnunet-statistics"), True)
35def sub_run (args, want_stdo = True, want_stde = False, nofail = False): 35
36 if want_stdo: 36
37 stdo = subprocess.PIPE 37def sub_run(args, want_stdo=True, want_stde=False, nofail=False):
38 else: 38 if want_stdo:
39 stdo = None 39 stdo = subprocess.PIPE
40 if want_stde: 40 else:
41 stde = subprocess.PIPE 41 stdo = None
42 else: 42 if want_stde:
43 stde = None 43 stde = subprocess.PIPE
44 p = subprocess.Popen (args, stdout = stdo, stderr = stde) 44 else:
45 stdo, stde = p.communicate () 45 stde = None
46 if not nofail: 46 p = subprocess.Popen(args, stdout=stdo, stderr=stde)
47 if p.returncode != 0: 47 stdo, stde = p.communicate()
48 sys.exit (p.returncode) 48 if not nofail:
49 return (p.returncode, stdo, stde) 49 if p.returncode != 0:
50 50 sys.exit(p.returncode)
51def fail (result): 51 return (p.returncode, stdo, stde)
52 print (result) 52
53 r_arm (['-e'], want_stdo = False) 53
54 sys.exit (1) 54def fail(result):
55 55 print(result)
56def r_arm (extra_args, **kw): 56 r_arm(['-e'], want_stdo=False)
57 rc, stdo, stde = sub_run (run_arm + extra_args, **kw) 57 sys.exit(1)
58 if rc != 0: 58
59 fail ("FAIL: error running {}".format (run_arm)) 59
60 return (rc, stdo, stde) 60def r_arm(extra_args, **kw):
61 61 rc, stdo, stde = sub_run(run_arm + extra_args, **kw)
62def r_st (extra_args, normal = True, **kw):
63 rc, stdo, stde = sub_run (run_st + extra_args, **kw)
64 if normal:
65 if rc != 0: 62 if rc != 0:
66 fail ("FAIL: error running {}".format (run_st)) 63 fail("FAIL: error running {}".format(run_arm))
67 else: 64 return (rc, stdo, stde)
68 if rc == 0: 65
69 fail ("FAIL: expected error while running {}".format (run_st)) 66
70 return (rc, stdo, stde) 67def r_st(extra_args, normal=True, **kw):
71 68 rc, stdo, stde = sub_run(run_st + extra_args, **kw)
72def restart (): 69 if normal:
73 print ("Restarting service...") 70 if rc != 0:
74 t = r_arm (['-k', 'statistics']) 71 fail("FAIL: error running {}".format(run_st))
75 time.sleep (1) 72 else:
76 t = r_arm (['-i', 'statistics']) 73 if rc == 0:
77 time.sleep (1) 74 fail("FAIL: expected error while running {}".format(run_st))
78 75 return (rc, stdo, stde)
79 76
80cleanup () 77
81 78def restart():
82print ("Preparing: Starting service...") 79 print("Restarting service...")
83t = r_arm (['-s'], want_stdo = False) 80 t = r_arm(['-k', 'statistics'])
84time.sleep (1) 81 time.sleep(1)
85t = r_arm (['-i', 'statistics'], want_stdo = False) 82 t = r_arm(['-i', 'statistics'])
86time.sleep (1) 83 time.sleep(1)
87 84
88print ("TEST: Bad argument checking...", end='') 85
89r_st (['-x'], normal = False, nofail = True, want_stdo = False, want_stde = True) 86cleanup()
90print ("PASS") 87
91 88print("Preparing: Starting service...")
92print ("TEST: Set value...", end='') 89t = r_arm(['-s'], want_stdo=False)
93r_st (['-n', 'test', '-s', 'subsystem', b'42'], nofail = True, want_stdo = False) 90time.sleep(1)
94print ("PASS") 91t = r_arm(['-i', 'statistics'], want_stdo=False)
95 92time.sleep(1)
96print ("TEST: Set another value...", end='') 93
97r_st (['-n', 'other', '-s', 'osystem', b'43'], nofail = True, want_stdo = False) 94print("TEST: Bad argument checking...", end='')
98print ("PASS") 95r_st(['-x'], normal=False, nofail=True, want_stdo=False, want_stde=True)
99 96print("PASS")
100print ("TEST: Viewing all stats...", end='') 97
101rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 98print("TEST: Set value...", end='')
102if len (stdo.splitlines ()) != 2: 99r_st(['-n', 'test', '-s', 'subsystem', b'42'], nofail=True, want_stdo=False)
103 fail ("FAIL: unexpected output:\n{}".format (stdo)) 100print("PASS")
104print ("PASS") 101
105 102print("TEST: Set another value...", end='')
106print ("TEST: Viewing stats by name...", end='') 103r_st(['-n', 'other', '-s', 'osystem', b'43'], nofail=True, want_stdo=False)
107rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True) 104print("PASS")
108if len ([x for x in stdo.splitlines () if re.search (b'43', x)]) != 1: 105
109 fail ("FAIL: unexpected output:\n{}".format (stdo)) 106print("TEST: Viewing all stats...", end='')
110print ("PASS") 107rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
111 108if len(stdo.splitlines()) != 2:
112print ("TEST: Viewing stats by subsystem...", end='') 109 fail("FAIL: unexpected output:\n{}".format(stdo))
113rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True) 110print("PASS")
114if len ([x for x in stdo.splitlines () if re.search (b'42', x)]) != 1: 111
115 fail ("FAIL: unexpected output:\n{}".format (stdo)) 112print("TEST: Viewing stats by name...", end='')
116print ("PASS") 113rc, stdo, stde = r_st(['-n', 'other'], nofail=True, want_stdo=True)
117 114if len([x for x in stdo.splitlines() if re.search(b'43', x)]) != 1:
118print ("TEST: Set persistent value...", end='') 115 fail("FAIL: unexpected output:\n{}".format(stdo))
119rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False) 116print("PASS")
120rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 117
121if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 1: 118print("TEST: Viewing stats by subsystem...", end='')
122 fail ("FAIL: unexpected output:\n{}".format (stdo)) 119rc, stdo, stde = r_st(['-s', 'subsystem'], nofail=True, want_stdo=True)
123print ("PASS") 120if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1:
124 121 fail("FAIL: unexpected output:\n{}".format(stdo))
125restart () 122print("PASS")
126 123
127print ("TEST: Checking persistence...", end='') 124print("TEST: Set persistent value...", end='')
128rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 125rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail=True, want_stdo=False)
129if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 1: 126rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
130 fail ("FAIL: unexpected output:\n{}".format (stdo)) 127if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
131print ("PASS") 128 fail("FAIL: unexpected output:\n{}".format(stdo))
132 129print("PASS")
133print ("TEST: Removing persistence...", end='') 130
134rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False) 131restart()
135rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 132
136if len ([x for x in stdo.splitlines () if re.search (b'!', x)]) != 0: 133print("TEST: Checking persistence...", end='')
137 fail ("FAIL: unexpected output:\n{}".format (stdo)) 134rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
138print ("PASS") 135if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
139 136 fail("FAIL: unexpected output:\n{}".format(stdo))
140restart () 137print("PASS")
141 138
142print ("TEST: Checking removed persistence...", end='') 139print("TEST: Removing persistence...", end='')
143rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) 140rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], nofail=True, want_stdo=False)
144if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 0: 141rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
145 fail ("FAIL: unexpected output:\n{}".format (stdo)) 142if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0:
146print ("PASS") 143 fail("FAIL: unexpected output:\n{}".format(stdo))
147 144print("PASS")
148print ("Stopping service...") 145
149t = r_arm (['-e'], want_stdo = False) 146restart()
150time.sleep (1) 147
151 148print("TEST: Checking removed persistence...", end='')
152cleanup () 149rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
150if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 0:
151 fail("FAIL: unexpected output:\n{}".format(stdo))
152print("PASS")
153
154print("Stopping service...")
155t = r_arm(['-e'], want_stdo=False)
156time.sleep(1)
157
158cleanup()