From 5997412b980854ebb626d2ddb69bfb10aa467960 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 17 Dec 2018 20:40:11 +0000 Subject: [PATCH] Add base project class --- catfish/project/__init__.py | 14 ++++++++++++++ tests/__init__.py | 1 + tests/test_project/test_project.py | 15 +++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 catfish/project/__init__.py create mode 100644 tests/test_project/test_project.py diff --git a/catfish/project/__init__.py b/catfish/project/__init__.py new file mode 100644 index 0000000..132642a --- /dev/null +++ b/catfish/project/__init__.py @@ -0,0 +1,14 @@ +from dataclasses import dataclass +from pathlib import Path + + +@dataclass +class Project: + root: Path + + def __post_init__(self): + self.root = Path(self.root) + assert self.exists() + + def exists(self): + return self.root.exists() diff --git a/tests/__init__.py b/tests/__init__.py index 0f39144..ee7b914 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -20,6 +20,7 @@ from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir class BaseTestCase(TestCase): DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py") + EXAMPLE_DIR = os.path.join(os.path.dirname(__file__), "../example") def setUp(self): create_base_socket_dir() diff --git a/tests/test_project/test_project.py b/tests/test_project/test_project.py new file mode 100644 index 0000000..001a574 --- /dev/null +++ b/tests/test_project/test_project.py @@ -0,0 +1,15 @@ +from catfish.project import Project +from tests import BaseTestCase + + +class ProjectTestCase(BaseTestCase): + def setUp(self): + super().setUp() + self.project = Project(self.EXAMPLE_DIR) + + def test_exists(self): + self.assertTrue(self.project.exists()) + + def test_cant_create_nonexistent_directory(self): + with self.assertRaises(AssertionError): + Project("/nonexistent")