Added correct e2e test and pypi mirror
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
This commit is contained in:
1
MIRRORS
1
MIRRORS
@@ -1,3 +1,4 @@
|
|||||||
git@github.com:kevinveenbirkenbach/package-manager.git
|
git@github.com:kevinveenbirkenbach/package-manager.git
|
||||||
ssh://git@git.veen.world:2201/kevinveenbirkenbach/pkgmgr.git
|
ssh://git@git.veen.world:2201/kevinveenbirkenbach/pkgmgr.git
|
||||||
ssh://git@code.infinito.nexus:2201/kevinveenbirkenbach/pkgmgr.git
|
ssh://git@code.infinito.nexus:2201/kevinveenbirkenbach/pkgmgr.git
|
||||||
|
https://pypi.org/project/kpmx/
|
||||||
|
|||||||
@@ -1,119 +1,70 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
|
||||||
import unittest
|
import unittest
|
||||||
from contextlib import redirect_stdout
|
|
||||||
from types import SimpleNamespace
|
|
||||||
|
|
||||||
from pkgmgr.cli.commands.publish import handle_publish
|
|
||||||
|
|
||||||
|
|
||||||
def _run(cmd: list[str], cwd: str) -> None:
|
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||||
subprocess.run(
|
|
||||||
|
|
||||||
|
def _run_help(cmd: list[str], label: str) -> str:
|
||||||
|
print(f"\n[TEST] Running ({label}): {' '.join(cmd)}")
|
||||||
|
proc = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
cwd=cwd,
|
cwd=PROJECT_ROOT,
|
||||||
check=True,
|
text=True,
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.STDOUT,
|
||||||
|
check=False,
|
||||||
|
env=os.environ.copy(),
|
||||||
)
|
)
|
||||||
|
print(proc.stdout.rstrip())
|
||||||
|
|
||||||
|
# For --help we expect success (0). Anything else is an error.
|
||||||
class TestIntegrationPublish(unittest.TestCase):
|
if proc.returncode != 0:
|
||||||
def setUp(self) -> None:
|
raise AssertionError(
|
||||||
if shutil.which("git") is None:
|
f"[TEST] Help command failed ({label}).\n"
|
||||||
self.skipTest("git is required for this integration test")
|
f"Command: {' '.join(cmd)}\n"
|
||||||
|
f"Exit code: {proc.returncode}\n"
|
||||||
self.tmp = tempfile.TemporaryDirectory()
|
f"--- output ---\n{proc.stdout}\n"
|
||||||
self.repo_dir = self.tmp.name
|
|
||||||
|
|
||||||
# Initialize git repository
|
|
||||||
_run(["git", "init"], cwd=self.repo_dir)
|
|
||||||
_run(["git", "config", "user.email", "ci@example.invalid"], cwd=self.repo_dir)
|
|
||||||
_run(["git", "config", "user.name", "CI"], cwd=self.repo_dir)
|
|
||||||
|
|
||||||
with open(os.path.join(self.repo_dir, "README.md"), "w", encoding="utf-8") as f:
|
|
||||||
f.write("test\n")
|
|
||||||
|
|
||||||
_run(["git", "add", "README.md"], cwd=self.repo_dir)
|
|
||||||
_run(["git", "commit", "-m", "init"], cwd=self.repo_dir)
|
|
||||||
_run(["git", "tag", "-a", "v1.2.3", "-m", "v1.2.3"], cwd=self.repo_dir)
|
|
||||||
|
|
||||||
# Create MIRRORS file with PyPI target
|
|
||||||
with open(os.path.join(self.repo_dir, "MIRRORS"), "w", encoding="utf-8") as f:
|
|
||||||
f.write("https://pypi.org/project/pkgmgr/\n")
|
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
|
||||||
self.tmp.cleanup()
|
|
||||||
|
|
||||||
def test_publish_preview_end_to_end(self) -> None:
|
|
||||||
ctx = SimpleNamespace(
|
|
||||||
repositories_base_dir=self.repo_dir,
|
|
||||||
all_repositories=[
|
|
||||||
{
|
|
||||||
"name": "pkgmgr",
|
|
||||||
"directory": self.repo_dir,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
selected = [
|
return proc.stdout
|
||||||
{
|
|
||||||
"name": "pkgmgr",
|
|
||||||
"directory": self.repo_dir,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
args = SimpleNamespace(
|
|
||||||
preview=True,
|
class TestPublishHelpE2E(unittest.TestCase):
|
||||||
non_interactive=False,
|
def test_pkgmgr_publish_help(self) -> None:
|
||||||
|
out = _run_help(["pkgmgr", "publish", "--help"], "pkgmgr publish --help")
|
||||||
|
self.assertIn("usage:", out)
|
||||||
|
self.assertIn("publish", out)
|
||||||
|
|
||||||
|
def test_pkgmgr_help_mentions_publish(self) -> None:
|
||||||
|
out = _run_help(["pkgmgr", "--help"], "pkgmgr --help")
|
||||||
|
self.assertIn("publish", out)
|
||||||
|
|
||||||
|
def test_nix_run_pkgmgr_publish_help(self) -> None:
|
||||||
|
if shutil.which("nix") is None:
|
||||||
|
self.skipTest("nix is not available in this environment")
|
||||||
|
|
||||||
|
out = _run_help(
|
||||||
|
["nix", "run", ".#pkgmgr", "--", "publish", "--help"],
|
||||||
|
"nix run .#pkgmgr -- publish --help",
|
||||||
)
|
)
|
||||||
|
self.assertIn("usage:", out)
|
||||||
|
self.assertIn("publish", out)
|
||||||
|
|
||||||
buf = io.StringIO()
|
def test_nix_run_pkgmgr_help_mentions_publish(self) -> None:
|
||||||
with redirect_stdout(buf):
|
if shutil.which("nix") is None:
|
||||||
handle_publish(args=args, ctx=ctx, selected=selected)
|
self.skipTest("nix is not available in this environment")
|
||||||
|
|
||||||
out = buf.getvalue()
|
out = _run_help(
|
||||||
|
["nix", "run", ".#pkgmgr", "--", "--help"],
|
||||||
self.assertIn("[pkgmgr] Publishing repository", out)
|
"nix run .#pkgmgr -- --help",
|
||||||
self.assertIn("[INFO] Publishing pkgmgr for tag v1.2.3", out)
|
|
||||||
self.assertIn("[PREVIEW] Would build and upload to PyPI.", out)
|
|
||||||
|
|
||||||
# Preview must not create dist/
|
|
||||||
self.assertFalse(os.path.isdir(os.path.join(self.repo_dir, "dist")))
|
|
||||||
|
|
||||||
def test_publish_skips_without_pypi_mirror(self) -> None:
|
|
||||||
with open(os.path.join(self.repo_dir, "MIRRORS"), "w", encoding="utf-8") as f:
|
|
||||||
f.write("git@github.com:example/example.git\n")
|
|
||||||
|
|
||||||
ctx = SimpleNamespace(
|
|
||||||
repositories_base_dir=self.repo_dir,
|
|
||||||
all_repositories=[
|
|
||||||
{
|
|
||||||
"name": "pkgmgr",
|
|
||||||
"directory": self.repo_dir,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
self.assertIn("publish", out)
|
||||||
|
|
||||||
selected = [
|
|
||||||
{
|
|
||||||
"name": "pkgmgr",
|
|
||||||
"directory": self.repo_dir,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
args = SimpleNamespace(
|
if __name__ == "__main__":
|
||||||
preview=True,
|
unittest.main()
|
||||||
non_interactive=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
buf = io.StringIO()
|
|
||||||
with redirect_stdout(buf):
|
|
||||||
handle_publish(args=args, ctx=ctx, selected=selected)
|
|
||||||
|
|
||||||
out = buf.getvalue()
|
|
||||||
self.assertIn("[INFO] No PyPI mirror found. Skipping publish.", out)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user