"""Focused tests for pure URL resolution behavior in the executable module.""" import importlib.machinery import importlib.util import pathlib import sys import unittest SCRIPT_PATH = pathlib.Path(__file__).parents[1] / "git-tui" LOADER = importlib.machinery.SourceFileLoader("git_tui", str(SCRIPT_PATH)) SPEC = importlib.util.spec_from_loader(LOADER.name, LOADER) assert SPEC is not None git_tui = importlib.util.module_from_spec(SPEC) sys.modules[LOADER.name] = git_tui LOADER.exec_module(git_tui) class GiteaRemoteUrlTests(unittest.TestCase): def setUp(self) -> None: self.app = git_tui.GitTuiApp.__new__(git_tui.GitTuiApp) def test_resolves_ssh_url_from_https_base_url(self) -> None: remote_url = self.app.resolve_gitea_remote_url( "owner/project", "https://git.example.com", transport="ssh" ) self.assertEqual(remote_url, "git@git.example.com:owner/project.git") def test_resolves_custom_ssh_user_and_port(self) -> None: remote_url = self.app.resolve_gitea_remote_url( "owner/project", "https://git.example.com/gitea", transport="ssh", ssh_user="forge", ssh_port="2222", ) self.assertEqual( remote_url, "ssh://forge@git.example.com:2222/owner/project.git", ) def test_still_supports_https(self) -> None: remote_url = self.app.resolve_gitea_remote_url( "owner/project", "https://git.example.com", transport="https" ) self.assertEqual( remote_url, "https://git.example.com/owner/project.git", ) def test_rejects_invalid_ssh_port(self) -> None: remote_url = self.app.resolve_gitea_remote_url( "owner/project", "https://git.example.com", transport="ssh", ssh_port="not-a-port", ) self.assertEqual(remote_url, "") if __name__ == "__main__": unittest.main()