Implement sjnetpkg 0.1.0, a Git-based package manager
Packages are ordinary Git repositories carrying a sjnetpkg.toml, so sjnetpkg only needs to resolve, clone, track and run them instead of inventing an archive format or build system. This adds the v0.1 CLI (install from registry or Git URL, remove, list/inspect, registry update, run) on top of the Python standard library, together with a test suite. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from sjnetpkg import config
|
||||
|
||||
|
||||
class DefaultHomeTests(unittest.TestCase):
|
||||
def test_env_override_is_used(self) -> None:
|
||||
with mock.patch.dict(os.environ, {"SJNETPKG_HOME": "/tmp/custom-home"}):
|
||||
self.assertEqual(config.default_home(), Path("/tmp/custom-home"))
|
||||
|
||||
def test_falls_back_to_home_directory(self) -> None:
|
||||
env = {k: v for k, v in os.environ.items() if k != "SJNETPKG_HOME"}
|
||||
with mock.patch.dict(os.environ, env, clear=True):
|
||||
self.assertEqual(config.default_home(), Path.home() / ".sjnetpkg")
|
||||
|
||||
|
||||
class PathsTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
self.home = Path(self._tmp.name) / ".sjnetpkg"
|
||||
self.paths = config.get_paths(self.home)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self._tmp.cleanup()
|
||||
|
||||
def test_layout(self) -> None:
|
||||
self.assertEqual(self.paths.config, self.home / "config.toml")
|
||||
self.assertEqual(self.paths.registry, self.home / "registry.toml")
|
||||
self.assertEqual(self.paths.pkg, self.home / "pkg")
|
||||
self.assertEqual(self.paths.package("cool-tool"), self.home / "pkg" / "cool-tool")
|
||||
|
||||
def test_ensure_home_creates_directories_and_config(self) -> None:
|
||||
config.ensure_home(self.paths)
|
||||
self.assertTrue(self.paths.pkg.is_dir())
|
||||
self.assertTrue(self.paths.config.is_file())
|
||||
self.assertEqual(config.registry_url(self.paths), config.DEFAULT_REGISTRY_URL)
|
||||
|
||||
def test_ensure_home_keeps_existing_config(self) -> None:
|
||||
self.home.mkdir(parents=True)
|
||||
self.paths.config.write_text('registry = "https://example.org/r.toml"\n')
|
||||
config.ensure_home(self.paths)
|
||||
self.assertEqual(config.registry_url(self.paths), "https://example.org/r.toml")
|
||||
|
||||
def test_missing_config_uses_default_registry(self) -> None:
|
||||
self.assertEqual(config.registry_url(self.paths), config.DEFAULT_REGISTRY_URL)
|
||||
|
||||
def test_invalid_config_raises(self) -> None:
|
||||
self.home.mkdir(parents=True)
|
||||
self.paths.config.write_text("this is = not toml\n")
|
||||
with self.assertRaises(config.ConfigError):
|
||||
config.registry_url(self.paths)
|
||||
|
||||
def test_empty_registry_value_raises(self) -> None:
|
||||
self.home.mkdir(parents=True)
|
||||
self.paths.config.write_text('registry = ""\n')
|
||||
with self.assertRaises(config.ConfigError):
|
||||
config.registry_url(self.paths)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user