mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 22:40:09 +01:00
allow globs in file_patterns
This commit is contained in:
parent
710019ee44
commit
1e633a2a7d
10 changed files with 136 additions and 43 deletions
52
test/util.py
52
test/util.py
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import tempfile
|
||||
|
|
@ -21,44 +22,67 @@ class Shell:
|
|||
_MODULE_PATH = pl.Path(__file__)
|
||||
FIXTURES_DIR = _MODULE_PATH.parent / "fixtures"
|
||||
|
||||
FIXTURE_PATH_PARTS = [
|
||||
["README.rst"],
|
||||
["README.md"],
|
||||
["setup.cfg"],
|
||||
["setup.py"],
|
||||
["pycalver.toml"],
|
||||
["src", "module_v1", "__init__.py"],
|
||||
["src", "module_v2", "__init__.py"],
|
||||
]
|
||||
|
||||
|
||||
class Project:
|
||||
def __init__(self, project_prefix="a"):
|
||||
if not project_prefix.endswith("_"):
|
||||
project_prefix += "_"
|
||||
def __init__(self, project="a"):
|
||||
if not project.startswith("project_"):
|
||||
project = "project_" + project
|
||||
|
||||
tmpdir = pl.Path(tempfile.mkdtemp(prefix="pytest_"))
|
||||
self.tmpdir = tmpdir
|
||||
|
||||
_project_dir = tmpdir / "pycalver_project"
|
||||
_project_dir.mkdir()
|
||||
self.dir = tmpdir / "pycalver_project"
|
||||
self.dir.mkdir()
|
||||
|
||||
for fpath in FIXTURES_DIR.glob(project_prefix + "*"):
|
||||
fname = fpath.name[len(project_prefix) :]
|
||||
shutil.copy(fpath, _project_dir / fname)
|
||||
fixtures_subdir = FIXTURES_DIR / project
|
||||
|
||||
self.dir = _project_dir
|
||||
for path_parts in FIXTURE_PATH_PARTS:
|
||||
fixture_fpath = fixtures_subdir.joinpath(*path_parts)
|
||||
if fixture_fpath.exists():
|
||||
project_fpath = self.dir.joinpath(*path_parts)
|
||||
project_fpath.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(str(fixture_fpath), str(project_fpath))
|
||||
|
||||
def __enter__(self):
|
||||
self.prev_cwd = os.getcwd()
|
||||
os.chdir(self.dir)
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc):
|
||||
shutil.rmtree(str(self.tmpdir))
|
||||
os.chdir(self.prev_cwd)
|
||||
return False
|
||||
|
||||
def sh(self, cmd):
|
||||
shell = Shell(str(self.dir))
|
||||
return shell(cmd)
|
||||
|
||||
def _vcs_addall(self, cmd):
|
||||
added_file_paths = []
|
||||
for path_parts in FIXTURE_PATH_PARTS:
|
||||
maybe_file_path = self.dir.joinpath(*path_parts)
|
||||
if maybe_file_path.exists():
|
||||
self.sh(f"{cmd} add {str(maybe_file_path)}")
|
||||
added_file_paths.append(maybe_file_path)
|
||||
|
||||
assert len(added_file_paths) >= 2
|
||||
|
||||
def git_init(self):
|
||||
self.sh("git init")
|
||||
self.sh("git add pycalver.toml")
|
||||
self.sh("git add README.md")
|
||||
self._vcs_addall(cmd="git")
|
||||
self.sh("git commit -m 'initial commit'")
|
||||
|
||||
def hg_init(self):
|
||||
self.sh = Shell(str(self.dir))
|
||||
self.sh("hg init")
|
||||
self.sh("hg add pycalver.toml")
|
||||
self.sh("hg add README.md")
|
||||
self._vcs_addall(cmd="hg")
|
||||
self.sh("hg commit -m 'initial commit'")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue