archive
/
catfish
Archived
1
Fork 0

Test process colours and running pid

This commit is contained in:
Jake Howard 2018-12-23 12:07:31 +00:00
parent ef5ce9f442
commit cce567d30e
Signed by: jake
GPG Key ID: 57AFB45680EDD477
3 changed files with 30 additions and 4 deletions

View File

@ -112,9 +112,9 @@ class Process:
def port(self):
proc = self.get_running_process()
if proc:
return proc.pid
return proc.environ().get("PORT")
@property
def color(self):
def colour(self):
proc_index = self.project.processes.index(self)
return list(ansi_colors.keys())[1:][proc_index % len(ansi_colors)]

View File

@ -47,7 +47,7 @@ def status(running_only):
pid = process.pid
table.add_row(
[
click.style(process.ident, fg=process.color),
click.style(process.ident, fg=process.colour),
pid if pid else "",
port if port else "",
]

View File

@ -1,5 +1,8 @@
from click.termui import _ansi_colors as ansi_colors # type: ignore
from catfish.project import DuplicateProcessException, Project, parse_procfile_processes
from tests import BaseTestCase
from catfish.worker.server import PayloadType, send_to_server
from tests import BaseTestCase, BaseWorkerTestCase
class ProjectTestCase(BaseTestCase):
@ -65,3 +68,26 @@ class ProcessTestCase(BaseTestCase):
def test_running_process(self):
self.assertFalse(self.process.is_running)
def test_unique_colour(self):
unique_colours = {proc.colour for proc in self.project.processes}
self.assertEqual(len(unique_colours), len(self.project.processes))
for colour in unique_colours:
self.assertIn(colour, ansi_colors)
class RunningProcessTestCase(BaseWorkerTestCase):
def setUp(self):
super().setUp()
self.project = Project(self.EXAMPLE_DIR)
self.process = self.project.get_process("web")
self.response = send_to_server(
PayloadType.PROCESS,
{"path": str(self.project.root), "process": str(self.process.name)},
)
def test_running_process(self):
self.assertTrue(self.process.is_running)
def test_pid(self):
self.assertEqual(self.process.pid, self.response["pid"])