Test process port

This commit is contained in:
Jake Howard 2018-12-23 13:01:32 +00:00
parent 5c04b5f85c
commit 4b5880cb36
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 10 additions and 4 deletions

View file

@ -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):

View file

@ -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)

View file

@ -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(