43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import functools
|
|
import os
|
|
from multiprocessing import Process
|
|
|
|
from aiohttp.test_utils import unused_port
|
|
from aiounittest import AsyncTestCase
|
|
from click.testing import CliRunner
|
|
|
|
from catfish import worker
|
|
from catfish.__main__ import cli
|
|
from catfish.utils.processes import CURRENT_PROCESS, terminate_processes
|
|
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
|
|
|
|
|
|
class BaseTestCase(AsyncTestCase):
|
|
DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py")
|
|
|
|
def setUp(self):
|
|
create_base_socket_dir()
|
|
worker.stop_worker()
|
|
self.cli_runner = CliRunner()
|
|
self.cli = cli
|
|
self.run_cli = functools.partial(self.cli_runner.invoke, self.cli)
|
|
|
|
def tearDown(self):
|
|
worker.stop_worker()
|
|
terminate_processes(CURRENT_PROCESS.children(recursive=True))
|
|
delete_base_socket_dir()
|
|
|
|
|
|
class BaseWorkerTestCase(BaseTestCase):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.unused_port = unused_port()
|
|
self.router_process = Process(
|
|
target=worker.run, args=(self.unused_port,), daemon=True
|
|
)
|
|
self.router_process.start()
|
|
worker.wait_for_running_worker()
|
|
|
|
def tearDown(self):
|
|
self.router_process.terminate()
|
|
super().tearDown()
|