From 4b5880cb36b54e9c466bee9de4f9f2f24112121c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 23 Dec 2018 13:01:32 +0000 Subject: [PATCH] Test process port --- catfish/project/__init__.py | 9 ++++++--- tests/test_project/test_project.py | 3 +++ tests/test_worker/test_server.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/catfish/project/__init__.py b/catfish/project/__init__.py index 7ca9636..50e9f89 100644 --- a/catfish/project/__init__.py +++ b/catfish/project/__init__.py @@ -2,7 +2,7 @@ import os import re from dataclasses import dataclass, field from pathlib import Path -from typing import Dict, List +from typing import Dict, List, Optional from click.termui import _ansi_colors as ansi_colors # type: ignore from dotenv import dotenv_values @@ -109,10 +109,13 @@ class Process: return proc.pid @property - def port(self): + def port(self) -> Optional[int]: proc = self.get_running_process() if proc: - return proc.environ().get("PORT") + process_port = proc.environ().get("PORT") + if process_port is not None: + return int(process_port) + return None @property def colour(self): diff --git a/tests/test_project/test_project.py b/tests/test_project/test_project.py index 80cdf63..91012ec 100644 --- a/tests/test_project/test_project.py +++ b/tests/test_project/test_project.py @@ -91,3 +91,6 @@ class RunningProcessTestCase(BaseWorkerTestCase): def test_pid(self): self.assertEqual(self.process.pid, self.response["pid"]) + + def test_port(self): + self.assertIsNotNone(self.process.port) diff --git a/tests/test_worker/test_server.py b/tests/test_worker/test_server.py index 1902e3c..79b364b 100644 --- a/tests/test_worker/test_server.py +++ b/tests/test_worker/test_server.py @@ -152,7 +152,7 @@ class ProcessPortTestCase(BaseWorkerTestCase): ) process = psutil.Process(response["pid"]) self.assertIn("PORT", process.environ()) - self.assertEqual(self.process.port, process.environ()["PORT"]) + self.assertEqual(self.process.port, int(process.environ()["PORT"])) def test_doesnt_assign_port(self): response = send_to_server(