diff options
| author | Roy Sommer <illBeRoy@users.noreply.github.com> | 2020-03-07 16:52:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-07 16:52:12 +0200 |
| commit | 58a199d1313bf52cc74776fbde0bef245ba72329 (patch) | |
| tree | 5b5f98cfffc0128c5ba4215f7cbb67c770b691d5 /tests/utils/project.py | |
| parent | updated travis badge to indicate master status (diff) | |
| download | taskipy2-58a199d1313bf52cc74776fbde0bef245ba72329.zip | |
Custom Runner (#11)
Diffstat (limited to 'tests/utils/project.py')
| -rw-r--r-- | tests/utils/project.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/utils/project.py b/tests/utils/project.py new file mode 100644 index 0000000..d6c151b --- /dev/null +++ b/tests/utils/project.py @@ -0,0 +1,42 @@ +import tempfile +import shutil +import os +from os import path +from abc import abstractmethod + +class ProjectDirGenerator: + @abstractmethod + def generate_project(self, temp_dir: str): + pass + + +class GenerateProjectFromFixture(ProjectDirGenerator): + def __init__(self, fixture_dir: str): + self._fixture_dir: str = fixture_dir + + def generate_project(self, temp_dir: str): + shutil.copytree(self._fixture_dir, temp_dir) + + +class GenerateProjectWithPyProjectToml(ProjectDirGenerator): + def __init__(self, py_project_toml: str): + self._py_project_toml: str = py_project_toml + + def generate_project(self, temp_dir: str): + os.makedirs(temp_dir) + with open(path.join(temp_dir, 'pyproject.toml'), 'w') as f: + f.write(self._py_project_toml) + + +class TempProjectDir: + def __init__(self, project_dir_generator: ProjectDirGenerator): + self._tmpdir: str = tempfile.mktemp() + project_dir_generator.generate_project(self._tmpdir) + + @property + def path(self): + return self._tmpdir + + def clean(self): + shutil.rmtree(self._tmpdir, ignore_errors=True) +
\ No newline at end of file |