diff --git a/conftest.py b/conftest.py index 38dd516a..bc8e352b 100644 --- a/conftest.py +++ b/conftest.py @@ -33,14 +33,13 @@ def cwd_default(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None @pytest.fixture(autouse=True, scope="session") -@pytest.mark.usefixtures("set_home") def xdg_config_path(user_path: pathlib.Path) -> pathlib.Path: p = user_path / ".config" p.mkdir() return p -@pytest.fixture(scope="function") +@pytest.fixture() def config_path( xdg_config_path: pathlib.Path, request: pytest.FixtureRequest ) -> pathlib.Path: @@ -61,7 +60,7 @@ def set_xdg_config_path( monkeypatch.setenv("XDG_CONFIG_HOME", str(xdg_config_path)) -@pytest.fixture(scope="function") +@pytest.fixture() def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest) -> pathlib.Path: """Return temporary directory for repository checkout guaranteed unique.""" dir = user_path / "repos" diff --git a/docs/conf.py b/docs/conf.py index bae40738..a2f52eec 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -179,8 +179,7 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]: - """ - Determine the URL corresponding to Python object + """Determine the URL corresponding to Python object. Notes ----- diff --git a/pyproject.toml b/pyproject.toml index f830d2a6..9ccd6129 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -167,12 +167,16 @@ select = [ "E", # pycodestyle "F", # pyflakes "I", # isort + "ICN", # flake8-import-conventions "UP", # pyupgrade "B", # flake8-bugbear "C4", # flake8-comprehensions "Q", # flake8-quotes + "N", # pep8-naming + "D", # pydocstyle "PTH", # flake8-use-pathlib "SIM", # flake8-simplify + "PT", # flake8-pytest-style "TRY", # Trycertatops "PERF", # Perflint "RUF", # Ruff-specific rules @@ -186,6 +190,7 @@ combine-as-imports = true [tool.ruff.per-file-ignores] "*/__init__.py" = ["F401"] +"tests/*" = ["D"] [build-system] requires = ["poetry_core>=1.0.0", "setuptools>50"] diff --git a/src/vcspull/_internal/config_reader.py b/src/vcspull/_internal/config_reader.py index 965c07c8..793ca436 100644 --- a/src/vcspull/_internal/config_reader.py +++ b/src/vcspull/_internal/config_reader.py @@ -118,7 +118,7 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]: @classmethod def from_file(cls, path: pathlib.Path) -> "ConfigReader": - r"""Load data from file path + r"""Load data from file path. **YAML file** diff --git a/src/vcspull/config.py b/src/vcspull/config.py index 8b1c29bb..231a280a 100644 --- a/src/vcspull/config.py +++ b/src/vcspull/config.py @@ -1,6 +1,6 @@ """Config utility functions for vcspull. vcspull.config -~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~. A lot of these items are todo. diff --git a/src/vcspull/exc.py b/src/vcspull/exc.py index c221fbc1..69c2ab97 100644 --- a/src/vcspull/exc.py +++ b/src/vcspull/exc.py @@ -1,5 +1,4 @@ class VCSPullException(Exception): - """Standard exception raised by vcspull.""" diff --git a/src/vcspull/log.py b/src/vcspull/log.py index 5ea02457..89b7fa74 100644 --- a/src/vcspull/log.py +++ b/src/vcspull/log.py @@ -125,7 +125,6 @@ def template(self, record: logging.LogRecord) -> str: record : :class:`logging.LogRecord` Passed from inside the :py:meth:`logging.Formatter.format` record. """ - reset = [Style.RESET_ALL] levelname = [ LEVEL_COLORS.get(record.levelname, ""), diff --git a/src/vcspull/util.py b/src/vcspull/util.py index d894d0c3..2168fbde 100644 --- a/src/vcspull/util.py +++ b/src/vcspull/util.py @@ -13,8 +13,7 @@ def get_config_dir() -> pathlib.Path: - """ - Return vcspull configuration directory. + """Return vcspull configuration directory. ``VCSPULL_CONFIGDIR`` environmental variable has precedence if set. We also evaluate XDG default directory from XDG_CONFIG_HOME environmental variable @@ -26,7 +25,6 @@ def get_config_dir() -> pathlib.Path: str : absolute path to tmuxp config directory """ - paths: list[pathlib.Path] = [] if "VCSPULL_CONFIGDIR" in os.environ: paths.append(pathlib.Path(os.environ["VCSPULL_CONFIGDIR"])) diff --git a/tests/test_config.py b/tests/test_config.py index 49894d1c..114c128b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -21,7 +21,7 @@ def __call__( ... -@pytest.fixture +@pytest.fixture() def load_yaml(tmp_path: pathlib.Path) -> LoadYAMLFn: def fn( content: str, dir: str = "randomdir", filename: str = "randomfilename.yaml" diff --git a/tests/test_config_file.py b/tests/test_config_file.py index 7e1b169e..fd507f87 100644 --- a/tests/test_config_file.py +++ b/tests/test_config_file.py @@ -14,14 +14,14 @@ from .helpers import EnvironmentVarGuard, load_raw, write_config -@pytest.fixture(scope="function") +@pytest.fixture() def yaml_config(config_path: pathlib.Path) -> pathlib.Path: yaml_file = config_path / "repos1.yaml" yaml_file.touch() return yaml_file -@pytest.fixture(scope="function") +@pytest.fixture() def json_config(config_path: pathlib.Path) -> pathlib.Path: json_file = config_path / "repos2.json" json_file.touch() @@ -194,11 +194,11 @@ def test_multiple_config_files_raises_exception(tmp_path: pathlib.Path) -> None: json_conf_file.touch() yaml_conf_file = tmp_path / ".vcspull.yaml" yaml_conf_file.touch() - with EnvironmentVarGuard() as env, pytest.raises(exc.MultipleConfigWarning): - env.set("HOME", str(tmp_path)) - assert pathlib.Path.home() == tmp_path - config.find_home_config_files() + with EnvironmentVarGuard() as env: + env.set("HOME", str(tmp_path)) + with pytest.raises(exc.MultipleConfigWarning): + config.find_home_config_files() def test_in_dir( diff --git a/tests/test_sync.py b/tests/test_sync.py index 2b80f9bc..1232c883 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -62,39 +62,53 @@ def write_config_remote( ) -@pytest.mark.parametrize( - "config_tpl,remote_list", - [ - [ - """ +class ConfigVariationFixture(t.NamedTuple): + test_id: str + config_tpl: str + remote_list: list[str] + + +CONFIG_VARIATION_FIXTURES = [ + ConfigVariationFixture( + test_id="1", + config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: git+file://{dir} """, - ["origin"], - ], - [ - """ + remote_list=["origin"], + ), + ConfigVariationFixture( + test_id="2", + config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: repo: git+file://{dir} """, - ["repo"], - ], - [ - """ + remote_list=["repo"], + ), + ConfigVariationFixture( + test_id="3", + config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: repo: git+file://{dir} remotes: secondremote: git+file://{dir} """, - ["secondremote"], - ], - ], + remote_list=["secondremote"], + ), +] + + +@pytest.mark.parametrize( + list(ConfigVariationFixture._fields), + CONFIG_VARIATION_FIXTURES, + ids=[test.test_id for test in CONFIG_VARIATION_FIXTURES], ) def test_config_variations( tmp_path: pathlib.Path, create_git_remote_repo: CreateProjectCallbackFixtureProtocol, + test_id: str, config_tpl: str, capsys: pytest.CaptureFixture[str], remote_list: list[str], @@ -131,39 +145,53 @@ def test_config_variations( assert current_remote.fetch_url == repo_url -@pytest.mark.parametrize( - "config_tpl,has_extra_remotes", - [ - [ - """ +class UpdatingRemoteFixture(t.NamedTuple): + test_id: str + config_tpl: str + has_extra_remotes: bool + + +UPDATING_REMOTE_FIXTURES = [ + UpdatingRemoteFixture( + test_id="basic", + config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: git+file://{dir} """, - False, - ], - [ - """ + has_extra_remotes=False, + ), + UpdatingRemoteFixture( + test_id="basic2", + config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: repo: git+file://{dir} """, - False, - ], - [ - """ + has_extra_remotes=False, + ), + UpdatingRemoteFixture( + test_id="basic3", + config_tpl=""" {tmp_path}/study/myrepo: {CLONE_NAME}: repo: git+file://{dir} remotes: mirror_repo: git+file://{dir} """, - True, - ], - ], + has_extra_remotes=True, + ), +] + + +@pytest.mark.parametrize( + list(UpdatingRemoteFixture._fields), + UPDATING_REMOTE_FIXTURES, + ids=[test.test_id for test in UPDATING_REMOTE_FIXTURES], ) def test_updating_remote( tmp_path: pathlib.Path, create_git_remote_repo: CreateProjectCallbackFixtureProtocol, + test_id: str, config_tpl: str, has_extra_remotes: bool, ) -> None: