Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from tab to 4 spaces in baseline #152

Merged
merged 12 commits into from
Aug 5, 2024
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [unpublished] - 2024-08-05

- Changed
- Switched from tab to 4 spaces in baseline

## [0.5.6] - 2024-07-17

- Fixed
Expand Down
4 changes: 3 additions & 1 deletion pydoclint/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from pydoclint.utils.violation import Violation

SEPARATOR = '--------------------\n'
LEN_INDENT = 4
INDENT = ' ' * LEN_INDENT


def generateBaseline(
Expand All @@ -16,7 +18,7 @@ def generateBaseline(
if violations:
baseline.write(f'{file}\n')
for violation in violations:
baseline.write(f'\t{str(violation).strip()}\n')
baseline.write(f'{INDENT}{str(violation).strip()}\n')

baseline.write(f'{SEPARATOR}')

Expand Down
42 changes: 42 additions & 0 deletions tests/test_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,45 @@ def testBaselineRegenerationNeeded(baselineFile, tmpFile: Path):

assert baselineRegenerationNeeded is True
assert clearedViolations == {}


def testBaselineIndent(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""
Confirm round trip equality with a space or tab indent in the
baseline file.

Parameters
----------
tmp_path : Path
Temporary path.
monkeypatch : pytest.MonkeyPatch
Pytest monkeypatch fixture

Returns
-------
None
"""

codeFile = tmp_path / 'code.py'
baselineSpaces = tmp_path / 'baseline_spaces.txt'
baselineTabs = tmp_path / 'baseline_tabs.txt'

codeFile.write_text(badDocstringFunction)
violations = _checkPaths((str(codeFile),), exclude=EXCLUDE_PATTERN)

generateBaseline(violations, baselineSpaces)

monkeypatch.setattr('pydoclint.baseline.INDENT', '\t')
generateBaseline(violations, baselineTabs)

assert baselineSpaces.read_text().splitlines()[1].startswith(' ')
assert baselineTabs.read_text().splitlines()[1].startswith('\t')

key = codeFile.as_posix()
spaceParsed = sorted(parseBaseline(baselineSpaces)[key])
tabParsed = sorted(parseBaseline(baselineTabs)[key])
violationsStr = sorted(str(v) for v in violations[key])

assert spaceParsed == tabParsed == violationsStr
Loading