From 2b34d34b5ce4c27e1c6ce8a6d637f4dbea012d04 Mon Sep 17 00:00:00 2001 From: Derek Wan Date: Wed, 31 Dec 2025 19:43:24 +0900 Subject: [PATCH 1/4] 2025-12-31 19:43:24 (Wed) > DW-Mac > derekwan From 91dfc0fc394a7d43b68acf745405384249d8b5bf Mon Sep 17 00:00:00 2001 From: Derek Wan Date: Wed, 31 Dec 2025 19:46:34 +0900 Subject: [PATCH 2/4] 2025-12-31 19:46:34 (Wed) > DW-Mac > derekwan --- pyproject.toml | 4 ++-- src/tests/test_postgres.py | 11 +++++++++++ src/tests/test_subprocess.py | 15 +++++++++++---- src/utilities/__init__.py | 2 +- src/utilities/platform.py | 2 +- src/utilities/polars.py | 2 ++ uv.lock | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ac7416475..52a3a57ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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" diff --git a/src/tests/test_postgres.py b/src/tests/test_postgres.py index f24690e36..59a2505cf 100644 --- a/src/tests/test_postgres.py +++ b/src/tests/test_postgres.py @@ -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_) diff --git a/src/tests/test_subprocess.py b/src/tests/test_subprocess.py index a9db25c05..53b87d899 100644 --- a/src/tests/test_subprocess.py +++ b/src/tests/test_subprocess.py @@ -238,8 +238,15 @@ def test_subs(self) -> None: 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() + git_clone("https://github.com/CogWorksBWSI/GitPracticeRepo", tmp_path) + assert (tmp_path / ".git").is_dir() + + @throttle(delta=5 * MINUTE) + def test_branch(self, *, tmp_path: Path) -> None: + git_clone( + "https://github.com/CogWorksBWSI/GitPracticeRepo", tmp_path, branch="branch" + ) + assert (tmp_path / ".git").is_dir() class TestGitCloneCmd: @@ -1199,8 +1206,8 @@ 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() + with yield_git_repo("https://github.com/CogWorksBWSI/GitPracticeRepo") as temp: + assert (temp / "README.md").is_file() class TestYieldSSHTempDir: diff --git a/src/utilities/__init__.py b/src/utilities/__init__.py index ee4f5e6a7..a60fe7534 100644 --- a/src/utilities/__init__.py +++ b/src/utilities/__init__.py @@ -1,3 +1,3 @@ from __future__ import annotations -__version__ = "0.174.18" +__version__ = "0.174.19" diff --git a/src/utilities/platform.py b/src/utilities/platform.py index d107711c4..b867bb107 100644 --- a/src/utilities/platform.py +++ b/src/utilities/platform.py @@ -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" diff --git a/src/utilities/polars.py b/src/utilities/polars.py index 5dd1c909c..b6d5703ec 100644 --- a/src/utilities/polars.py +++ b/src/utilities/polars.py @@ -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) ## diff --git a/uv.lock b/uv.lock index c0f758a86..e4ad426b9 100644 --- a/uv.lock +++ b/uv.lock @@ -634,7 +634,7 @@ wheels = [ [[package]] name = "dycw-utilities" -version = "0.174.18" +version = "0.174.19" source = { editable = "." } dependencies = [ { name = "atomicwrites" }, From 8607db8684dbc4c7e23377be339a8c723705bcb2 Mon Sep 17 00:00:00 2001 From: Derek Wan Date: Wed, 31 Dec 2025 19:58:11 +0900 Subject: [PATCH 3/4] 2025-12-31 19:58:11 (Wed) > DW-Mac > derekwan --- src/tests/conftest.py | 5 ++++ src/tests/test_subprocess.py | 58 +++++++++++++++++++++++++----------- src/utilities/subprocess.py | 25 ++++++++++++++++ 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 709d9c975..142a27266 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -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" diff --git a/src/tests/test_subprocess.py b/src/tests/test_subprocess.py index 53b87d899..96af63649 100644 --- a/src/tests/test_subprocess.py +++ b/src/tests/test_subprocess.py @@ -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, @@ -235,30 +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/CogWorksBWSI/GitPracticeRepo", tmp_path) + 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, *, tmp_path: Path) -> None: - git_clone( - "https://github.com/CogWorksBWSI/GitPracticeRepo", tmp_path, branch="branch" - ) - assert (tmp_path / ".git").is_dir() + 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 @@ -1205,8 +1227,8 @@ def test_args(self) -> None: class TestYieldGitRepo: @throttle(delta=5 * MINUTE) - def test_main(self) -> None: - with yield_git_repo("https://github.com/CogWorksBWSI/GitPracticeRepo") as temp: + def test_main(self, *, git_repo_url: str) -> None: + with yield_git_repo(git_repo_url) as temp: assert (temp / "README.md").is_file() diff --git a/src/utilities/subprocess.py b/src/utilities/subprocess.py index 91538051f..5cad95afe 100644 --- a/src/utilities/subprocess.py +++ b/src/utilities/subprocess.py @@ -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" @@ -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: @@ -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", @@ -1194,6 +1217,8 @@ def yield_ssh_temp_dir( "cp_cmd", "echo_cmd", "expand_path", + "git_checkout", + "git_checkout_cmd", "git_clone", "git_clone_cmd", "git_hard_reset_cmd", From c0e7c40e2238b975c8cf04b7b77a387fc7586f8c Mon Sep 17 00:00:00 2001 From: Derek Wan Date: Wed, 31 Dec 2025 19:59:04 +0900 Subject: [PATCH 4/4] 2025-12-31 19:59:04 (Wed) > DW-Mac > derekwan --- src/utilities/subprocess.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utilities/subprocess.py b/src/utilities/subprocess.py index 5cad95afe..744f55cb0 100644 --- a/src/utilities/subprocess.py +++ b/src/utilities/subprocess.py @@ -1217,6 +1217,7 @@ def yield_ssh_temp_dir( "cp_cmd", "echo_cmd", "expand_path", + "git_branch_current", "git_checkout", "git_checkout_cmd", "git_clone",