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