From cce567d30eb68b5576088a1c16f70d40b8476bc5 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 23 Dec 2018 12:07:31 +0000 Subject: [PATCH] Test process colours and running pid --- catfish/project/__init__.py | 4 ++-- catfish/project/cli.py | 2 +- tests/test_project/test_project.py | 28 +++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/catfish/project/__init__.py b/catfish/project/__init__.py index 27582cb..7ca9636 100644 --- a/catfish/project/__init__.py +++ b/catfish/project/__init__.py @@ -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)] diff --git a/catfish/project/cli.py b/catfish/project/cli.py index 2749035..01f8986 100644 --- a/catfish/project/cli.py +++ b/catfish/project/cli.py @@ -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 "", ] diff --git a/tests/test_project/test_project.py b/tests/test_project/test_project.py index 2bcda35..80cdf63 100644 --- a/tests/test_project/test_project.py +++ b/tests/test_project/test_project.py @@ -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"])