Coverage for tests/test_lib.py: 100.00%
21 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-03-19 16:19 +0100
« prev ^ index » next coverage.py v7.7.0, created at 2025-03-19 16:19 +0100
1"""Tests for the `cli` module."""
3from __future__ import annotations
5from typing import TYPE_CHECKING
7import pytest
9from yore._internal import lib
11if TYPE_CHECKING:
12 from pathlib import Path
15@pytest.mark.parametrize(
16 ("block", "expected_size"),
17 [
18 (["a", "b", "c"], 3),
19 (["a", " b", "c"], 3),
20 ([" a", " b", "c"], 2),
21 (["a", "", "c"], 1),
22 (["a", " b", "", "d"], 2),
23 (["a", " b", "", " d"], 4),
24 (["a", " b", "", " d", "e"], 5),
25 ],
26)
27def test_block_size(block: list[str], expected_size: int) -> None:
28 """Assert that `_block_size` returns the expected size."""
29 assert lib._block_size(block, 0) == expected_size
32class _Match:
33 def __init__(self, lines: str) -> None:
34 self.lines = lines
36 def group(self, name: str) -> str: # noqa: ARG002
37 return self.lines
40@pytest.mark.parametrize(
41 ("lines", "expected_lines"),
42 [
43 ("1", [1]),
44 ("1 2", [1, 2]),
45 ("1,2", [1, 2]),
46 (",, ,1,, ,,,, 2 ,,", [1, 2]),
47 ("1-3", [1, 2, 3]),
48 ("1-2", [1, 2]),
49 ("1-1", [1]),
50 ("1-2, 3, 5-7", [1, 2, 3, 5, 6, 7]),
51 ],
52)
53def test_match_to_lines(lines: str, expected_lines: list[int]) -> None:
54 """Assert that `_match_to_lines` returns the expected lines."""
55 match = _Match(lines)
56 assert lib._match_to_lines(match) == expected_lines # type: ignore[arg-type]
59def test_removing_file(tmp_path: Path) -> None:
60 """Files are removed by "remove" comments and "file" scope."""
61 file = tmp_path / "file1.py"
62 file.write_text("# YORE: Bump 1: Remove file.")
63 next(lib.yield_file_comments(file)).fix(bump="1")
64 assert not file.exists()