Skip to content

Commit f79be96

Browse files
committed
testsuite: apply fixes required for pre-commit
Problem: The pre-commit CI hooks were skipping the testsuite directory `t/`, but that will soon be fixed. This uncovers many formatting issues and other minor errors. Fix the errors and formatting found by the various pre-commit hooks.
1 parent b0ca9ac commit f79be96

35 files changed

+173
-177
lines changed

t/python/subflux.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
###############################################################
42
# Copyright 2014 Lawrence Livermore National Security, LLC
53
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
@@ -10,10 +8,10 @@
108
# SPDX-License-Identifier: LGPL-3.0
119
###############################################################
1210

11+
import argparse
1312
import os
14-
import sys
1513
import subprocess
16-
import argparse
14+
import sys
1715

1816
script_dir = os.path.dirname(os.path.abspath(__file__))
1917

t/python/t0001-handle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
# SPDX-License-Identifier: LGPL-3.0
1111
###############################################################
1212

13-
import unittest
1413
import syslog
14+
import unittest
1515

1616
import flux
17-
from subflux import rerun_under_flux, script_dir
17+
from subflux import rerun_under_flux
1818

1919

2020
def __flux_size():

t/python/t0002-wrapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import unittest
1414

1515
import flux
16-
from flux.core.inner import ffi, raw
1716
import flux.wrapper
17+
from flux.core.inner import ffi, raw
1818
from subflux import rerun_under_flux
1919

2020

@@ -42,12 +42,12 @@ def test_null_handle_exception(self):
4242
f = flux.Flux()
4343
payload = {"seq": 1, "pad": "stuff"}
4444
future = f.rpc("broker.ping", payload)
45-
resp = future.get()
45+
future.get()
4646
future.pimpl.handle = None
4747
with self.assertRaisesRegex(
4848
ValueError, r"Attempting to call a cached, bound method.*NULL handle"
4949
):
50-
resp = future.get()
50+
future.get()
5151

5252
def test_automatic_unwrapping(self):
5353
flux.core.inner.raw.flux_log(flux.Flux("loop://"), 0, "stuff")

t/python/t0003-barrier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# SPDX-License-Identifier: LGPL-3.0
1111
###############################################################
1212

13-
import unittest
1413
import multiprocessing as mp
14+
import unittest
1515

1616
import flux
1717
from subflux import rerun_under_flux

t/python/t0005-kvs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import flux
1616
import flux.kvs
17-
1817
from subflux import rerun_under_flux
1918

2019

@@ -39,7 +38,7 @@ def set_and_check_context(self, key, value, type):
3938
kd2 = flux.kvs.KVSDir(self.f)
4039
nv = kd2[key]
4140
if isinstance(value, bytes) and type is str:
42-
self.assertEqual(value.decode('utf-8'), nv)
41+
self.assertEqual(value.decode("utf-8"), nv)
4342
else:
4443
self.assertEqual(value, nv)
4544
if type is not None:

t/python/t0006-request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# SPDX-License-Identifier: LGPL-3.0
1111
###############################################################
1212

13+
import errno
1314
import unittest
1415

15-
import errno
1616
import flux
1717
from subflux import rerun_under_flux
1818

t/python/t0007-watchers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
# SPDX-License-Identifier: LGPL-3.0
1111
###############################################################
1212

13-
import unittest
14-
import os
1513
import gc
14+
import os
1615
import signal
16+
import unittest
17+
1718
import flux
1819
from subflux import rerun_under_flux
1920

@@ -67,8 +68,8 @@ def test_timer_callback_exception(self):
6768
def cb(x, y, z, w):
6869
raise RuntimeError("this is a test")
6970

70-
with self.f.timer_watcher_create(0.01, cb) as timer:
71-
with self.assertRaises(RuntimeError) as cm:
71+
with self.f.timer_watcher_create(0.01, cb):
72+
with self.assertRaises(RuntimeError):
7273
self.f.reactor_run()
7374

7475
def test_msg_watcher_unicode(self):
@@ -155,7 +156,7 @@ def raise_signal(handle, watcher, revents, args):
155156
# Create new Flux handle to avoid potential stale state in
156157
# self.f handle. (makes test unreliable)
157158
h = flux.Flux()
158-
with h.signal_watcher_create(signal.SIGUSR2, signal_cb) as watcher:
159+
with h.signal_watcher_create(signal.SIGUSR2, signal_cb):
159160
h.timer_watcher_create(0.05, raise_signal).start()
160161
with self.assertRaises(RuntimeError):
161162
rc = h.reactor_run()
@@ -231,7 +232,7 @@ def cb_abort(handle, watcher, revents, _args):
231232
self.f.timer_watcher_create(0.0, cb, repeat=0.05).start()
232233

233234
# Timeout/abort after 5s
234-
tw = self.f.timer_watcher_create(5.0, cb_abort).start()
235+
self.f.timer_watcher_create(5.0, cb_abort).start()
235236
self.f.reactor_run()
236237

237238
# callback should have been called 5 times, not less

t/python/t0009-security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
try:
1919
from flux.security import SecurityContext
20-
except:
20+
except ModuleNotFoundError:
2121
print("1..0 # skip flux.security module not available")
2222
sys.exit(0)
2323

t/python/t0010-job.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,24 @@
1010
# SPDX-License-Identifier: LGPL-3.0
1111
###############################################################
1212

13-
import os
13+
import datetime
1414
import errno
15-
import sys
1615
import json
17-
import unittest
18-
import datetime
19-
import signal
2016
import locale
17+
import os
2118
import pathlib
19+
import signal
2220
import subprocess
21+
import unittest
2322
from glob import glob
2423

25-
import yaml
26-
2724
import flux
28-
import flux.kvs
2925
import flux.constants
26+
import flux.kvs
27+
import yaml
3028
from flux import job
31-
from flux.job import Jobspec, JobspecV1, ffi, JobID, JobInfo
29+
from flux.job import JobInfo, Jobspec, JobspecV1, ffi
3230
from flux.job.stats import JobStats
33-
from flux.future import Future
3431

3532

3633
def __flux_size():
@@ -49,7 +46,7 @@ def setUpClass(self):
4946
self.fh = flux.Flux()
5047
self.use_ascii = False
5148
build_opts = subprocess.check_output(["flux", "version"]).decode()
52-
if locale.getlocale()[1] != "UTF-8" or "ascii-only" in build_opts:
49+
if locale.getlocale()[1] != "UTF-8" or "ascii-only" in build_opts:
5350
self.use_ascii = True
5451

5552
self.jobspec_dir = os.path.abspath(
@@ -90,7 +87,7 @@ def test_03_invalid_construction(self):
9087
):
9188
with self.assertRaises(
9289
(ValueError, TypeError, yaml.scanner.ScannerError)
93-
) as cm:
90+
):
9491
cls.from_yaml_file(invalid_jobspec_filepath)
9592

9693
def test_04_valid_construction(self):
@@ -332,7 +329,7 @@ def cb(future, events):
332329
events.append(event.name)
333330

334331
future.then(cb, events)
335-
rc = self.fh.reactor_run()
332+
self.fh.reactor_run()
336333

337334
# Last event should be "start"
338335
self.assertEqual(events[-1], "start")
@@ -688,32 +685,34 @@ def test_33_get_job(self):
688685
jobid = job.submit(self.fh, self.sleep_jobspec)
689686
meta = job.get_job(self.fh, jobid)
690687
self.assertIsInstance(meta, dict)
691-
for key in ['id',
692-
'userid',
693-
'urgency',
694-
'priority',
695-
't_submit',
696-
't_depend',
697-
'state',
698-
'name',
699-
'cwd',
700-
'ntasks',
701-
'ncores',
702-
'duration',
703-
'nnodes',
704-
'result',
705-
'runtime',
706-
'returncode',
707-
'waitstatus',
708-
'nodelist',
709-
'exception']:
688+
for key in [
689+
"id",
690+
"userid",
691+
"urgency",
692+
"priority",
693+
"t_submit",
694+
"t_depend",
695+
"state",
696+
"name",
697+
"cwd",
698+
"ntasks",
699+
"ncores",
700+
"duration",
701+
"nnodes",
702+
"result",
703+
"runtime",
704+
"returncode",
705+
"waitstatus",
706+
"nodelist",
707+
"exception",
708+
]:
710709
self.assertIn(key, meta)
711710

712-
self.assertEqual(meta['id'], jobid)
713-
self.assertEqual(meta['name'], "sleep")
714-
self.assertTrue(meta['state'] in ["SCHED", "DEPEND", "RUN"])
715-
self.assertEqual(meta['ntasks'], 1)
716-
self.assertEqual(meta['ncores'], 1)
711+
self.assertEqual(meta["id"], jobid)
712+
self.assertEqual(meta["name"], "sleep")
713+
self.assertTrue(meta["state"] in ["SCHED", "DEPEND", "RUN"])
714+
self.assertEqual(meta["ntasks"], 1)
715+
self.assertEqual(meta["ncores"], 1)
717716

718717
# Test a job that does not exist
719718
meta = job.get_job(self.fh, 123456)
@@ -727,11 +726,12 @@ def test_34_timeleft(self):
727726
jobid = job.submit(self.fh, spec, waitable=True)
728727
job.wait(self.fh, jobid=jobid)
729728
try:
730-
dt = job.timeleft()
731-
dt = job.timeleft(self.fh)
729+
job.timeleft()
730+
job.timeleft(self.fh)
732731
except OSError:
733732
pass
734733

734+
735735
if __name__ == "__main__":
736736
from subflux import rerun_under_flux
737737

t/python/t0012-futures.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# SPDX-License-Identifier: LGPL-3.0
1111
###############################################################
1212

13-
import gc
1413
import errno
14+
import gc
1515
import unittest
1616

1717
import flux
@@ -86,8 +86,8 @@ def then_cb(future):
8686
raise RuntimeError("this is a test")
8787

8888
self.f.rpc("broker.ping", self.ping_payload).then(then_cb)
89-
with self.assertRaises(RuntimeError) as cm:
90-
rc = self.f.reactor_run()
89+
with self.assertRaises(RuntimeError):
90+
self.f.reactor_run()
9191

9292
def test_03_future_then_varargs(self):
9393
cb_ran = [False]
@@ -212,7 +212,7 @@ def service_cb(fh, t, msg, arg):
212212
{"count": arg["target"]},
213213
flags=flux.constants.FLUX_RPC_STREAMING,
214214
).then(continuation_cb, arg=arg)
215-
ret = self.f.reactor_run()
215+
self.f.reactor_run()
216216
self.assertEqual(arg["count"], arg["target"])
217217

218218
watcher.stop()
@@ -230,15 +230,15 @@ def test_08_future_from_future(self):
230230
orig_fut = self.f.rpc("broker.ping", payload=self.ping_payload)
231231
new_fut = Future(orig_fut)
232232
del orig_fut
233-
resp_payload = new_fut.get()
233+
new_fut.get()
234234
# Future's `get` returns `None`, so just test that it is fulfilled
235235
self.assertTrue(new_fut.is_ready())
236236

237237
orig_fut = self.f.rpc("foo.bar")
238238
new_fut = Future(orig_fut)
239239
del orig_fut
240240
with self.assertRaises(EnvironmentError):
241-
resp_payload = new_fut.get()
241+
new_fut.get()
242242

243243

244244
if __name__ == "__main__":

0 commit comments

Comments
 (0)