Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
name = "dycw-utilities"
readme = "README.md"
requires-python = ">= 3.12"
version = "0.174.18"
version = "0.174.19"

[project.entry-points.pytest11]
pytest-randomly = "utilities.pytest_plugins.pytest_randomly"
Expand Down Expand Up @@ -135,7 +135,7 @@
# bump-my-version
[tool.bumpversion]
allow_dirty = true
current_version = "0.174.18"
current_version = "0.174.19"

[[tool.bumpversion.files]]
filename = "src/utilities/__init__.py"
Expand Down
5 changes: 5 additions & 0 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def _drop_table(table: str, /) -> TextClause:
# fixtures - subprocess


@fixture
def git_repo_url() -> str:
return "https://github.com/CogWorksBWSI/GitPracticeRepo"


@fixture
def ssh_user() -> str:
return "root"
Expand Down
11 changes: 11 additions & 0 deletions src/tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ def test_build(
docker_container=docker_container,
)

@given(
url=urls(all_=True),
path=temp_paths(),
format_=sampled_from(get_literal_elements(_PGDumpFormat)),
jobs=integers(min_value=0),
)
def test_jobs(
self, *, url: URL, path: Path, format_: _PGDumpFormat, jobs: int
) -> None:
_ = _build_pg_dump(url, path, format_=format_, jobs=jobs)

@given(path=temp_paths(), format_=sampled_from(get_literal_elements(_PGDumpFormat)))
def test_path(self, *, path: Path, format_: _PGDumpFormat) -> None:
path = _path_pg_dump(path, format_=format_)
Expand Down
59 changes: 44 additions & 15 deletions src/tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
cp_cmd,
echo_cmd,
expand_path,
git_branch_current,
git_checkout,
git_checkout_cmd,
git_clone,
git_clone_cmd,
git_hard_reset_cmd,
Expand Down Expand Up @@ -235,23 +238,49 @@ def test_subs(self) -> None:
assert result == expected


class TestGitBranchCurrent:
@throttle(delta=5 * MINUTE)
@mark.only
def test_main(self, *, git_repo_url: str, tmp_path: Path) -> None:
git_clone(git_repo_url, tmp_path)
result = git_branch_current(tmp_path)
assert result == "master"


class TestGitCheckout:
@throttle(delta=5 * MINUTE)
@mark.only
def test_main(self, *, git_repo_url: str, tmp_path: Path) -> None:
git_clone(git_repo_url, tmp_path)
git_checkout("branch", tmp_path)
result = git_branch_current(tmp_path)
assert result == "branch"


class TestGitCheckoutCmd:
def test_main(self) -> None:
result = git_checkout_cmd("branch")
expected = ["git", "checkout", "branch"]
assert result == expected


class TestGitClone:
@throttle(delta=5 * MINUTE)
def test_main(self, *, tmp_path: Path) -> None:
git_clone("https://github.com/dycw/template-generic", tmp_path)
assert (tmp_path / ".bumpversion.toml").is_file()
def test_main(self, *, git_repo_url: str, tmp_path: Path) -> None:
git_clone(git_repo_url, tmp_path)
assert (tmp_path / ".git").is_dir()

@throttle(delta=5 * MINUTE)
def test_branch(self, *, git_repo_url: str, tmp_path: Path) -> None:
git_clone(git_repo_url, tmp_path, branch="branch")
result = git_branch_current(tmp_path)
assert result == "branch"


class TestGitCloneCmd:
def test_main(self) -> None:
result = git_clone_cmd("https://github.com/dycw/template-generic", "path")
expected = [
"git",
"clone",
"--recurse-submodules",
"https://github.com/dycw/template-generic",
"path",
]
def test_main(self, *, git_repo_url: str) -> None:
result = git_clone_cmd(git_repo_url, "path")
expected = ["git", "clone", "--recurse-submodules", git_repo_url, "path"]
assert result == expected


Expand Down Expand Up @@ -1198,9 +1227,9 @@ def test_args(self) -> None:

class TestYieldGitRepo:
@throttle(delta=5 * MINUTE)
def test_main(self) -> None:
with yield_git_repo("https://github.com/dycw/template-generic") as temp:
assert (temp / ".bumpversion.toml").is_file()
def test_main(self, *, git_repo_url: str) -> None:
with yield_git_repo(git_repo_url) as temp:
assert (temp / "README.md").is_file()


class TestYieldSSHTempDir:
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utilities/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def get_system() -> System:
"""Get the system/OS name."""
sys = system()
if sys == "Windows": # skipif-ci
if sys == "Windows": # skipif-not-windows
return "windows"
if sys == "Darwin": # skipif-not-macos
return "mac"
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,8 @@ def search_period(
return None
item: dt.datetime = series[index]["start"]
return index if py_date_time > item else None
case never:
assert_never(never)


##
Expand Down
26 changes: 26 additions & 0 deletions src/utilities/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
APT_UPDATE = ["apt", "update", "-y"]
BASH_LC = ["bash", "-lc"]
BASH_LS = ["bash", "-ls"]
GIT_BRANCH_SHOW_CURRENT = ["git", "branch", "--show-current"]
MKTEMP_DIR_CMD = ["mktemp", "-d"]
RESTART_SSHD = ["systemctl", "restart", "sshd"]
UPDATE_CA_CERTIFICATES: str = "update-ca-certificates"
Expand Down Expand Up @@ -221,6 +222,27 @@ def expand_path(
##


def git_branch_current(path: PathLike, /) -> str:
"""Show the current a branch."""
return run(*GIT_BRANCH_SHOW_CURRENT, cwd=path, return_=True)


##


def git_checkout(branch: str, path: PathLike, /) -> None:
"""Switch a branch."""
run(*git_checkout_cmd(branch), cwd=path)


def git_checkout_cmd(branch: str, /) -> list[str]:
"""Command to use 'git checkout' to switch a branch."""
return ["git", "checkout", branch]


##


def git_clone(
url: str, path: PathLike, /, *, sudo: bool = False, branch: str | None = None
) -> None:
Expand Down Expand Up @@ -1175,6 +1197,7 @@ def yield_ssh_temp_dir(
"APT_UPDATE",
"BASH_LC",
"BASH_LS",
"GIT_BRANCH_SHOW_CURRENT",
"MKTEMP_DIR_CMD",
"RESTART_SSHD",
"UPDATE_CA_CERTIFICATES",
Expand All @@ -1194,6 +1217,9 @@ def yield_ssh_temp_dir(
"cp_cmd",
"echo_cmd",
"expand_path",
"git_branch_current",
"git_checkout",
"git_checkout_cmd",
"git_clone",
"git_clone_cmd",
"git_hard_reset_cmd",
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading