Skip to content

Commit

Permalink
Rename test/ to tests/
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Dec 1, 2024
1 parent 50d7e1a commit edc9797
Show file tree
Hide file tree
Showing 30 changed files with 159 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
run: pip install -e .[tests]

- name: Run pytest
run: pytest -sv --cov=plumpy test
run: pytest -s --cov=plumpy tests

- name: Create xml coverage
run: coverage xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: pip install .[tests]

- name: Run pytest
run: pytest -s --cov=plumpy test
run: pytest -s --cov=plumpy tests/

- name: Create xml coverage
run: coverage xml
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ name = 'plumpy'
exclude = [
'docs/',
'examples/',
'test/',
'tests/',
]

[tool.flynt]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, player, track):
super().__init__(player)
self.track = track
self._last_time = None
self._played = 0.0
self._played = 0.

def __str__(self):
if self.in_state:
Expand All @@ -40,7 +40,7 @@ def exit(self):
super().exit()
self._update_time()

def play(self, track=None):
def play(self, track=None): # pylint: disable=no-self-use, unused-argument
return False

def _update_time(self):
Expand All @@ -55,7 +55,8 @@ class Paused(state_machine.State):
TRANSITIONS = {STOP: STOPPED}

def __init__(self, player, playing_state):
assert isinstance(playing_state, Playing), 'Must provide the playing state to pause'
assert isinstance(playing_state, Playing), \
'Must provide the playing state to pause'
super().__init__(player)
self.playing_state = playing_state

Expand All @@ -64,7 +65,7 @@ def __str__(self):

def play(self, track=None):
if track is not None:
self.state_machine.transition_to(Playing, track)
self.state_machine.transition_to(Playing, track=track)
else:
self.state_machine.transition_to(self.playing_state)

Expand All @@ -80,7 +81,7 @@ def __str__(self):
return '[]'

def play(self, track):
self.state_machine.transition_to(Playing, track)
self.state_machine.transition_to(Playing, track=track)


class CdPlayer(state_machine.StateMachine):
Expand All @@ -107,7 +108,7 @@ def play(self, track=None):

@state_machine.event(from_states=Playing, to_states=Paused)
def pause(self):
self.transition_to(Paused, self._state)
self.transition_to(Paused, playing_state=self._state)
return True

@state_machine.event(from_states=(Playing, Paused), to_states=Stopped)
Expand All @@ -116,13 +117,14 @@ def stop(self):


class TestStateMachine(unittest.TestCase):

def test_basic(self):
cd_player = CdPlayer()
self.assertEqual(cd_player.state, STOPPED)

cd_player.play('Eminem - The Real Slim Shady')
self.assertEqual(cd_player.state, PLAYING)
time.sleep(1.0)
time.sleep(1.)

cd_player.pause()
self.assertEqual(cd_player.state, PAUSED)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 14 additions & 8 deletions test/rmq/test_process_comms.py → tests/rmq/test_process_comms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-
import asyncio
import copy

import kiwipy
from kiwipy import rmq
import pytest
import shortuuid
from kiwipy import rmq

import plumpy
import plumpy.communications
from plumpy import process_comms
import plumpy.communications

from .. import utils

Expand Down Expand Up @@ -43,11 +44,12 @@ def sync_controller(thread_communicator: rmq.RmqThreadCommunicator):


class TestRemoteProcessController:

@pytest.mark.asyncio
async def test_pause(self, thread_communicator, async_controller):
proc = utils.WaitForSignalProcess(communicator=thread_communicator)
# Run the process in the background
asyncio.ensure_future(proc.step_until_terminated()) # noqa: RUF006
asyncio.ensure_future(proc.step_until_terminated())
# Send a pause message
result = await async_controller.pause_process(proc.pid)

Expand All @@ -59,7 +61,7 @@ async def test_pause(self, thread_communicator, async_controller):
async def test_play(self, thread_communicator, async_controller):
proc = utils.WaitForSignalProcess(communicator=thread_communicator)
# Run the process in the background
asyncio.ensure_future(proc.step_until_terminated()) # noqa: RUF006
asyncio.ensure_future(proc.step_until_terminated())
assert proc.pause()

# Send a play message
Expand All @@ -77,7 +79,7 @@ async def test_play(self, thread_communicator, async_controller):
async def test_kill(self, thread_communicator, async_controller):
proc = utils.WaitForSignalProcess(communicator=thread_communicator)
# Run the process in the event loop
asyncio.ensure_future(proc.step_until_terminated()) # noqa: RUF006
asyncio.ensure_future(proc.step_until_terminated())

# Send a kill message and wait for it to be done
result = await async_controller.kill_process(proc.pid)
Expand All @@ -90,7 +92,7 @@ async def test_kill(self, thread_communicator, async_controller):
async def test_status(self, thread_communicator, async_controller):
proc = utils.WaitForSignalProcess(communicator=thread_communicator)
# Run the process in the background
asyncio.ensure_future(proc.step_until_terminated()) # noqa: RUF006
asyncio.ensure_future(proc.step_until_terminated())

# Send a status message
status = await async_controller.get_status(proc.pid)
Expand Down Expand Up @@ -121,6 +123,7 @@ def on_broadcast_receive(**msg):


class TestRemoteProcessThreadController:

@pytest.mark.asyncio
async def test_pause(self, thread_communicator, sync_controller):
proc = utils.WaitForSignalProcess(communicator=thread_communicator)
Expand Down Expand Up @@ -195,15 +198,18 @@ async def test_kill_all(self, thread_communicator, sync_controller):
for _ in range(10):
procs.append(utils.WaitForSignalProcess(communicator=thread_communicator))

sync_controller.kill_all('bang bang, I shot you down')
msg = copy.copy(process_comms.KILL_MSG)
msg[process_comms.MESSAGE_KEY] = 'bang bang, I shot you down'

sync_controller.kill_all(msg)
await utils.wait_util(lambda: all([proc.killed() for proc in procs]))
assert all([proc.state == plumpy.ProcessState.KILLED for proc in procs])

@pytest.mark.asyncio
async def test_status(self, thread_communicator, sync_controller):
proc = utils.WaitForSignalProcess(communicator=thread_communicator)
# Run the process in the background
asyncio.ensure_future(proc.step_until_terminated()) # noqa: RUF006
asyncio.ensure_future(proc.step_until_terminated())

# Send a status message
status_future = sync_controller.get_status(proc.pid)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 10 additions & 3 deletions test/test_process_comms.py → tests/test_process_comms.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# -*- coding: utf-8 -*-
import asyncio
from test import utils
import unittest

from kiwipy import rmq
import pytest

import plumpy
from plumpy import process_comms
from test import utils
from plumpy import communications, process_comms


class Process(plumpy.Process):

def run(self):
pass


class CustomObjectLoader(plumpy.DefaultObjectLoader):

def load_object(self, identifier):
if identifier == 'jimmy':
return Process
Expand All @@ -35,14 +41,15 @@ async def test_continue():
pid = process.pid
persister.save_checkpoint(process)
del process
process = None

result = await launcher._continue(None, **plumpy.create_continue_body(pid)[process_comms.TASK_ARGS])
assert result == utils.DummyProcess.EXPECTED_OUTPUTS


@pytest.mark.asyncio
async def test_loader_is_used():
"""Make sure that the provided class loader is used by the process launcher"""
""" Make sure that the provided class loader is used by the process launcher """
loader = CustomObjectLoader()
proc = Process()
persister = plumpy.InMemoryPersister(loader=loader)
Expand Down
File renamed without changes.
Loading

0 comments on commit edc9797

Please sign in to comment.