This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
catfish/tests/test_project/test_cli.py

53 lines
1.9 KiB
Python
Raw Permalink Normal View History

2018-12-21 13:00:20 +00:00
from io import StringIO
2018-12-20 18:59:25 +00:00
from dotenv import dotenv_values
2018-12-21 13:00:20 +00:00
from catfish.project import Project
from tests import BaseTestCase
2018-12-20 18:59:25 +00:00
class ProjectRunCLITestCase(BaseTestCase):
def setUp(self):
super().setUp()
self.project = Project(self.EXAMPLE_DIR)
def test_sets_environment(self):
with self.in_example_dir():
2018-12-21 13:00:20 +00:00
result = self.run_cli(["project", "run", "env"], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
env = dotenv_values(stream=StringIO(result.stdout))
self.assertEqual(env["FOO"], "bar")
self.assertEqual(env["PYTHONUNBUFFERED"], "1")
self.assertIsNone(env.get("CATFISH_IDENT"))
self.assertIn(str(self.project.root), env["PATH"])
for path in self.project.get_extra_path():
self.assertIn(str(path), env["PATH"])
def test_sets_working_dir(self):
with self.in_example_dir():
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))
2018-12-23 14:37:53 +00:00
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)