Skip to content

Commit

Permalink
Use pytest tmp_path fixture for creating temp file
Browse files Browse the repository at this point in the history
  • Loading branch information
nifadyev committed Oct 4, 2024
1 parent 77a6b9d commit a81dfda
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions tests/test_cli/test_lint_command.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import subprocess
from collections.abc import Callable
from pathlib import Path

from dotenv_linter.violations.values import InvalidEOLViolation

Expand Down Expand Up @@ -83,17 +82,13 @@ def test_lint_wrong_fixture(fixture_path, all_violations):
assert str(violation_class.code) in stderr


def test_lint_wrong_eol(fixture_path: Callable[[str], str]) -> None:
def test_lint_wrong_eol(tmp_path: Path) -> None:
"""Checks that `lint` command works for with with CRLF end-of-line."""
temp_file_path = fixture_path('.env.temp')
with open(temp_file_path, mode='w') as temp_file:
temp_file.write('VARIABLE_WITH_CRLF_EOL=123\r\n')
temp_file = tmp_path / '.env.temp'
temp_file.write_text('VARIABLE_WITH_CRLF_EOL=123\r\n')

process = subprocess.Popen(
[
'dotenv-linter',
fixture_path(temp_file_path),
],
['dotenv-linter', temp_file.absolute()],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
# It is important to set this to `False`, otherwise eol are normalized
Expand All @@ -105,5 +100,3 @@ def test_lint_wrong_eol(fixture_path: Callable[[str], str]) -> None:
assert process.returncode == 1

assert str(InvalidEOLViolation.code) in stderr

os.remove(temp_file_path)

0 comments on commit a81dfda

Please sign in to comment.