Skip to content

Commit

Permalink
testsuite: fix Python futures test for Python 3.12
Browse files Browse the repository at this point in the history
Problem: The python/t0012-future.py test uses assertDictContainsSubset
which has been deprecated for awhile and was removed in Python 3.12.

Update the test to use a custom is_subset() function instead of
unittest's assertDictContainsSubset().
  • Loading branch information
grondo committed Jan 18, 2024
1 parent 5083967 commit 11d1a24
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions t/python/t0012-futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,28 @@ def setUpClass(self):
self.f = flux.Flux()
self.ping_payload = {"seq": 1, "pad": "stuff"}

@staticmethod
def is_subset(x, y):
"""Return true if all keys in x are present and equal to keys in y"""
for key, val in x.items():
if key not in y:
raise ValueError(f"key {key} missing in {y}")
if y[key] != val:
raise ValueError(f"key {key} is not {val} (got {x[key]})")
return True

def test_01_rpc_get(self):
future = self.f.rpc("broker.ping", self.ping_payload)
resp_payload = future.get()
self.assertDictContainsSubset(self.ping_payload, resp_payload)
self.assertTrue(self.is_subset(self.ping_payload, resp_payload))

def test_02_get_flux(self):
future = self.f.rpc("broker.ping", self.ping_payload)
future.get_flux()
# force a full garbage collection pass to test that the handle is not destructed
gc.collect(2)
resp_payload = future.get()
self.assertDictContainsSubset(self.ping_payload, resp_payload)
self.assertTrue(self.is_subset(self.ping_payload, resp_payload))

def test_02_future_wait_for(self):
future = self.f.rpc("broker.ping", self.ping_payload)
Expand All @@ -55,7 +65,7 @@ def test_02_future_wait_for(self):
self.fail(msg="future fulfillment timed out")
else:
raise
self.assertDictContainsSubset(self.ping_payload, resp_payload)
self.assertTrue(self.is_subset(self.ping_payload, resp_payload))

def test_03_future_then(self):
"""Register a 'then' cb and run the reactor to ensure it runs"""
Expand All @@ -67,7 +77,7 @@ def then_cb(future, arg):
try:
resp_payload = future.get()
cb_ran[0] = True
self.assertDictContainsSubset(arg, resp_payload)
self.assertTrue(self.is_subset(arg, resp_payload))
finally:
# ensure that reactor is always stopped, avoiding a hung test
flux_handle.reactor_stop(reactor)
Expand Down

0 comments on commit 11d1a24

Please sign in to comment.