From ae285899e56001581c34e89e15ac9ea359aa4ca7 Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Mon, 5 Aug 2024 01:03:44 -0700 Subject: [PATCH] Switch from tab to 4 spaces in baseline (#152) Co-authored-by: jsh9 <25124332+jsh9@users.noreply.github.com> --- CHANGELOG.md | 5 +++++ pydoclint/baseline.py | 4 +++- tests/test_baseline.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24cc83d..6a71bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pydoclint/baseline.py b/pydoclint/baseline.py index 9814e46..427d0d5 100644 --- a/pydoclint/baseline.py +++ b/pydoclint/baseline.py @@ -5,6 +5,8 @@ from pydoclint.utils.violation import Violation SEPARATOR = '--------------------\n' +LEN_INDENT = 4 +INDENT = ' ' * LEN_INDENT def generateBaseline( @@ -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}') diff --git a/tests/test_baseline.py b/tests/test_baseline.py index c823d5d..6f9eb26 100644 --- a/tests/test_baseline.py +++ b/tests/test_baseline.py @@ -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