From c77d8aad2097d149489c08a7d701928a06a86b26 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 24 Sep 2023 04:37:37 -0500 Subject: [PATCH 1/5] pyproject(ruff): Add ICN, N, D, PT - "ICN", # flake8-import-conventions - "N", # pep8-naming - "D", # pydocstyle - "PT", # flake8-pytest-style --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) 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"] From f9a8ed8cbc51e44ac86eb59a7c3a54b369681cf7 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 24 Sep 2023 04:39:21 -0500 Subject: [PATCH 2/5] chore(ruff): Run automated fixes (19 errors) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ruff . --show-fixes --fix-only warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`. warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`. Fixed 19 errors: - conftest.py: 2 × PT003 (pytest-extraneous-scope-function) 1 × PT025 (pytest-erroneous-use-fixtures-on-fixture) - docs/conf.py: 1 × D212 (multi-line-summary-first-line) 1 × D415 (ends-in-punctuation) 1 × D400 (ends-in-period) - src/vcspull/_internal/config_reader.py: 1 × D415 (ends-in-punctuation) 1 × D400 (ends-in-period) - src/vcspull/config.py: 1 × D415 (ends-in-punctuation) 1 × D400 (ends-in-period) - src/vcspull/exc.py: 1 × D211 (blank-line-before-class) - src/vcspull/log.py: 1 × D202 (no-blank-line-after-function) - src/vcspull/util.py: 1 × D212 (multi-line-summary-first-line) 1 × D202 (no-blank-line-after-function) - tests/test_config.py: 1 × PT001 (pytest-fixture-incorrect-parentheses-style) - tests/test_config_file.py: 2 × PT003 (pytest-extraneous-scope-function) - tests/test_sync.py: 2 × PT006 (pytest-parametrize-names-wrong-type) --- conftest.py | 5 ++--- docs/conf.py | 3 +-- src/vcspull/_internal/config_reader.py | 2 +- src/vcspull/config.py | 2 +- src/vcspull/exc.py | 1 - src/vcspull/log.py | 1 - src/vcspull/util.py | 4 +--- tests/test_config.py | 2 +- tests/test_config_file.py | 4 ++-- tests/test_sync.py | 4 ++-- 10 files changed, 11 insertions(+), 17 deletions(-) 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/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..6bd95c26 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() diff --git a/tests/test_sync.py b/tests/test_sync.py index 2b80f9bc..ec22fa25 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -63,7 +63,7 @@ def write_config_remote( @pytest.mark.parametrize( - "config_tpl,remote_list", + ("config_tpl", "remote_list"), [ [ """ @@ -132,7 +132,7 @@ def test_config_variations( @pytest.mark.parametrize( - "config_tpl,has_extra_remotes", + ("config_tpl", "has_extra_remotes"), [ [ """ From 99f1a676333f1e725de8b33a203384a3e4735ce2 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 24 Sep 2023 04:47:40 -0500 Subject: [PATCH 3/5] refactor(test_sync): Parametrize test_updating_remote --- tests/test_sync.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/tests/test_sync.py b/tests/test_sync.py index ec22fa25..dbb8dfac 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -131,39 +131,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: From 59d66dd966ecea197b51487ba291ad641dc694ce Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 24 Sep 2023 04:51:57 -0500 Subject: [PATCH 4/5] refactor(test_sync): Parametrize test_config_variations --- tests/test_sync.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/tests/test_sync.py b/tests/test_sync.py index dbb8dfac..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], From f5a4d0fd62cc0403ad5f53bf917e6b9c8e2cb531 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 24 Sep 2023 04:58:38 -0500 Subject: [PATCH 5/5] chore(ruff): Manual fix for test_config_file tests/test_config_file.py:197:5: PT012 `pytest.raises()` block should contain a single simple statement --- tests/test_config_file.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_config_file.py b/tests/test_config_file.py index 6bd95c26..fd507f87 100644 --- a/tests/test_config_file.py +++ b/tests/test_config_file.py @@ -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(