From 5fee87b3a27f65357721a0eb79b4f76ad18ab2dd Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 23 Dec 2018 14:37:53 +0000 Subject: [PATCH] Test project status command --- catfish/project/cli.py | 6 ++---- tests/test_project/test_cli.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/catfish/project/cli.py b/catfish/project/cli.py index 01f8986..ce40e4d 100644 --- a/catfish/project/cli.py +++ b/catfish/project/cli.py @@ -43,13 +43,11 @@ def status(running_only): for process in project.processes: if running_only and not process.is_running: continue - port = process.port - pid = process.pid table.add_row( [ click.style(process.ident, fg=process.colour), - pid if pid else "", - port if port else "", + process.pid or "", + process.port or "", ] ) click.echo(table.get_string(sortby="ident")) diff --git a/tests/test_project/test_cli.py b/tests/test_project/test_cli.py index 9ed286e..98f733e 100644 --- a/tests/test_project/test_cli.py +++ b/tests/test_project/test_cli.py @@ -28,3 +28,25 @@ class ProjectRunCLITestCase(BaseTestCase): result = self.run_cli(["project", "run", "pwd"], catch_exceptions=False) self.assertEqual(result.exit_code, 0) self.assertEqual(result.stdout.strip(), str(self.project.root)) + + +class ProjectStatusCLITestCase(BaseTestCase): + def setUp(self): + super().setUp() + self.project = Project(self.EXAMPLE_DIR) + + def test_shows_all_processes(self): + with self.in_example_dir(): + result = self.run_cli(["project", "status"]) + self.assertEqual(result.exit_code, 0) + output = result.stdout + for process in self.project.processes: + self.assertIn(process.ident, output) + + def test_only_shows_running_processes(self): + with self.in_example_dir(): + result = self.run_cli(["project", "status", "--running-only"]) + self.assertEqual(result.exit_code, 0) + output = result.stdout + for process in self.project.processes: + self.assertNotIn(process.ident, output)