def test_overwrite_git_abbreviation(self, mock_load_file: Mock) -> None: mock_load_file.return_value = { "git_abbreviations": { "gh": "https://---FAKE---.github.com/{0}" } } user_config = config.get_user_config() assert user_config.git_abbreviations == { "gh": "https://---FAKE---.github.com/{0}", "gl": "https://gitlab.com/{0}", "bb": "https://bitbucket.org/{0}", }
def test_unknown_config_key(self, mock_logger: Mock, mock_load_file: Mock) -> None: mock_load_file.return_value = {"unknown_config": "fake-value"} assert config.get_user_config() == DEFAULT_CONFIG mock_logger.warning.assert_called_once()
def test_empty_config_file(self, mock_load_file: Mock) -> None: mock_load_file.return_value = {} assert config.get_user_config() == DEFAULT_CONFIG
def test_override_repo_cache(self, mock_load_file: Mock) -> None: mock_load_file.return_value = {"repo_cache": "fake/path/to/cache"} user_config = config.get_user_config() assert user_config.repo_cache == "fake/path/to/cache"
from contextlib import contextmanager from dataclasses import dataclass from pathlib import Path from typing import Any, Dict, Iterator, Optional from unittest.mock import MagicMock, Mock, patch import pytest from qwikstart.config import get_user_config from qwikstart.exceptions import RepoLoaderError from qwikstart.repository import git CACHE_DIR = get_user_config().repo_cache_path TEST_URL = "https://github.com/user/repo" class TestParseGitUrl: def test_https_url(self) -> None: git_url = self.parse_git_url("https://github.com/tonysyu/qwikstart") assert git_url.prefix == "https" assert git_url.separator == "://" assert git_url.path == "github.com/tonysyu/qwikstart" def test_git_ssh(self) -> None: git_url = self.parse_git_url("[email protected]:tonysyu/qwikstart.git") assert git_url.prefix == "git" assert git_url.separator == "@" assert git_url.path == "github.com/tonysyu/qwikstart.git" def parse_git_url(self, url: str) -> git.GitUrl: # Ensure that we get a non-None value to avoid mypy errors about non-checking.