Skip to content

Commit

Permalink
test/test_processes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 27, 2024
1 parent 9e5c1ad commit db7289b
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions test/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ async def async_test():
self.assertTrue(proc.has_terminated())
self.assertEqual(proc.state, ProcessState.FINISHED)

loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

def test_pause_play_status_messaging(self):
Expand All @@ -390,8 +390,8 @@ def test_pause_play_status_messaging(self):
Any process can have its status set to a given message. When pausing, a pause message can be set for the
status, which should store the current status, which should be restored, once the process is played again.
"""
PLAY_STATUS = 'process was played by Hans Klok'
PAUSE_STATUS = 'process was paused by Evel Knievel'
PLAY_STATUS = 'process was played by Hans Klok' # noqa: N806
PAUSE_STATUS = 'process was paused by Evel Knievel' # noqa: N806

loop = asyncio.get_event_loop()
proc = utils.WaitForSignalProcess()
Expand All @@ -415,7 +415,7 @@ async def async_test():
await proc.future()

# Check it's done
loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

self.assertTrue(proc.has_terminated())
Expand Down Expand Up @@ -457,8 +457,6 @@ def test_kill_when_paused(self):
async def async_test():
await utils.run_until_waiting(proc)

saved_state = plumpy.Bundle(proc)

result = await proc.pause()
self.assertTrue(result)
self.assertTrue(proc.paused)
Expand All @@ -469,7 +467,7 @@ async def async_test():
with self.assertRaises(plumpy.KilledError):
result = await proc.future()

loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

self.assertEqual(proc.state, ProcessState.KILLED)
Expand All @@ -481,7 +479,7 @@ def test_run_multiple(self):
procs = []
for proc_class in utils.TEST_PROCESSES:
proc = proc_class()
loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
procs.append(proc)

tasks = asyncio.gather(*[p.future() for p in procs])
Expand Down Expand Up @@ -512,20 +510,20 @@ def test_missing_output(self):
self.assertFalse(proc.is_successful)

def test_unsuccessful_result(self):
ERROR_CODE = 256
error_code = 256

class Proc(Process):
@classmethod
def define(cls, spec):
super().define(spec)

def run(self):
return plumpy.UnsuccessfulResult(ERROR_CODE)
return plumpy.UnsuccessfulResult(error_code)

proc = Proc()
proc.execute()

self.assertEqual(proc.result(), ERROR_CODE)
self.assertEqual(proc.result(), error_code)

def test_pause_in_process(self):
"""Test that we can pause and cancel that by playing within the process"""
Expand All @@ -544,7 +542,7 @@ def run(self):
proc = TestPausePlay()
proc.add_process_listener(listener)

loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_forever()

self.assertTrue(proc.paused)
Expand Down Expand Up @@ -722,7 +720,7 @@ async def async_test():
await proc_unbundled.step_until_terminated()
self.assertEqual([SavePauseProc.step2.__name__], proc_unbundled.steps_ran)

loop.create_task(nsync_comeback.step_until_terminated())
loop.create_task(nsync_comeback.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

def test_save_future(self):
Expand All @@ -745,7 +743,7 @@ async def async_test():

self.assertListEqual([SavePauseProc.run.__name__, SavePauseProc.step2.__name__], proc_unbundled.steps_ran)

loop.create_task(proc_unbundled.step_until_terminated())
loop.create_task(proc_unbundled.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

def test_created_bundle(self):
Expand Down Expand Up @@ -799,7 +797,7 @@ async def async_test():
await loaded_proc.step_until_terminated()
self.assertEqual(loaded_proc.outputs, {'finished': True})

loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

def test_double_restart(self):
Expand All @@ -824,7 +822,7 @@ async def async_test():
await loaded_proc.step_until_terminated()
self.assertEqual(loaded_proc.outputs, {'finished': True})

loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

def test_wait_save_continue(self):
Expand All @@ -844,14 +842,14 @@ async def async_test():
# Load from saved state and run again
loader = plumpy.get_object_loader()
proc2 = saved_state.unbundle(plumpy.LoadSaveContext(loader))
asyncio.ensure_future(proc2.step_until_terminated())
asyncio.ensure_future(proc2.step_until_terminated()) # noqa: RUF006
proc2.resume()
result2 = await proc2.future()

# Check results match
self.assertEqual(result1, result2)

loop.create_task(proc.step_until_terminated())
loop.create_task(proc.step_until_terminated()) # noqa: RUF006
loop.run_until_complete(async_test())

def test_killed(self):
Expand Down Expand Up @@ -936,7 +934,7 @@ def define(cls, spec):

original_inputs = [1, 2, 3, 4]

inputs = {'name': {'space': {str(l): l for l in original_inputs}}}
inputs = {'name': {'space': {str(l): l for l in original_inputs}}} # noqa: E741
proc = DummyDynamicProcess(inputs=inputs)

for label, value in proc.inputs['name']['space'].items():
Expand Down

0 comments on commit db7289b

Please sign in to comment.