diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-29 22:35:29 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-29 22:35:29 +0200 |
commit | 8c5c0138d71023079e9f0ac45f2f01a7e96784bc (patch) | |
tree | d15c4579c00fcb7d1f73a0d8f627b5ab398efbd1 /test/py/lib/test_repo.py | |
parent | log: minor refactoring (diff) | |
download | cimple-8c5c0138d71023079e9f0ac45f2f01a7e96784bc.tar.gz cimple-8c5c0138d71023079e9f0ac45f2f01a7e96784bc.zip |
test: shuffle files a bit
This should hopefully reduce clutter in the test/ directory.
Side note: if I leave the __init__.py file in the new py/ directory,
pytest fails with import errors. To make it work, I need to either
delete it or keep the __init__.py file in both test/ and py/. No idea
why.
Diffstat (limited to 'test/py/lib/test_repo.py')
-rw-r--r-- | test/py/lib/test_repo.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/py/lib/test_repo.py b/test/py/lib/test_repo.py new file mode 100644 index 0000000..1922245 --- /dev/null +++ b/test/py/lib/test_repo.py @@ -0,0 +1,48 @@ +# Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com> +# This file is part of the "cimple" project. +# For details, see https://github.com/egor-tensin/cimple. +# Distributed under the MIT License. + +import logging +import os +import shutil + +from .process import Process + + +class Repo: + BRANCH = 'main' + + def __init__(self, path): + self.path = os.path.abspath(path) + os.makedirs(path, exist_ok=True) + self.run('git', 'init', '-q', f'--initial-branch={Repo.BRANCH}') + self.run('git', 'config', 'user.name', 'Test User') + self.run('git', 'config', 'user.email', 'test@example.com') + + def run(self, *args, **kwargs): + Process.run(*args, cwd=self.path, **kwargs) + + +class TestRepo(Repo): + # Prevent Pytest from discovering test cases in this class: + __test__ = False + + DATA_DIR = 'test_repo' + CI_SCRIPT = 'ci.sh' + OUTPUT_DIR = 'output' + + @staticmethod + def get_ci_script(): + return os.path.join(os.path.dirname(__file__), TestRepo.DATA_DIR, TestRepo.CI_SCRIPT) + + def __init__(self, path): + super().__init__(path) + shutil.copy(self.get_ci_script(), self.path) + self.run('git', 'add', '.') + self.run('git', 'commit', '-q', '-m', 'add CI script') + self.output_dir = os.path.join(self.path, TestRepo.OUTPUT_DIR) + os.makedirs(self.output_dir, exist_ok=True) + + def count_ci_output_files(self): + return len([name for name in os.listdir(self.output_dir) if os.path.isfile(os.path.join(self.output_dir, name))]) |