Skip to content

Commit

Permalink
Switch from tab to 4 spaces in baseline (#152)
Browse files Browse the repository at this point in the history
Co-authored-by: jsh9 <[email protected]>
  • Loading branch information
cidrblock and jsh9 authored Aug 5, 2024
1 parent 1e80fd3 commit ae28589
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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

0 comments on commit ae28589

Please sign in to comment.