Skip to content

Commit

Permalink
fix: files should not be deleted unless explicitly set in the style
Browse files Browse the repository at this point in the history
Fixes #71
  • Loading branch information
andreoliwa committed Aug 12, 2019
1 parent 7fb5062 commit b5953ff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/nitpick/files/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def check_exists(self) -> YieldFlake8Error:
"""
for _ in self.multiple_files:
config_data_exists = bool(self.file_dict or self.nitpick_file_dict)
should_exist = self.config.files.get(self.toml_key, config_data_exists) # type: bool
should_exist = self.config.files.get(self.toml_key, True) # type: bool
file_exists = self.file_path.exists()

if should_exist and not file_exists:
if config_data_exists and not file_exists:
suggestion = self.suggest_initial_contents()
phrases = [" was not found"]
missing_message = self.nitpick_file_dict.get("missing_message", "")
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def raise_assertion_error(self, expected_error: str, assertion_message: str = No
print("\nProject root:", self.root_dir)
raise AssertionError(assertion_message or expected_error)

def assert_error_count(self, expected_error: str, expected_count: int = None) -> "ProjectMock":
def _assert_error_count(self, expected_error: str, expected_count: int = None) -> "ProjectMock":
"""Assert the error count is correct."""
if expected_count is not None:
actual = len(self._errors)
Expand All @@ -169,7 +169,7 @@ def assert_errors_contain(self, raw_error: str, expected_count: int = None) -> "
expected_error = dedent(raw_error).strip()
if expected_error not in self._errors:
self.raise_assertion_error(expected_error)
self.assert_error_count(expected_error, expected_count)
self._assert_error_count(expected_error, expected_count)
return self

def assert_errors_contain_unordered(self, raw_error: str, expected_count: int = None) -> "ProjectMock":
Expand All @@ -184,7 +184,7 @@ def assert_errors_contain_unordered(self, raw_error: str, expected_count: int =
expected_error_lines = set(expected_error.split("\n"))
for actual_error in self._errors:
if set(actual_error.replace("\x1b[0m", "").split("\n")) == expected_error_lines:
self.assert_error_count(raw_error, expected_count)
self._assert_error_count(raw_error, expected_count)
return self

self.raise_assertion_error(original_expected_error)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from tests.helpers import ProjectMock


def test_pre_commit_should_be_deleted(request):
"""File should be deleted."""
ProjectMock(request).style("").pre_commit("").lint().assert_errors_contain(
"NIP332 File .pre-commit-config.yaml should be deleted"
def test_pre_commit_has_no_configuration(request):
"""File should not be deleted unless explicitly asked."""
ProjectMock(request).style("").pre_commit("").lint().assert_single_error(
"NIP331 File .pre-commit-config.yaml doesn't have the 'repos' root key"
)


Expand Down
8 changes: 3 additions & 5 deletions tests/test_pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from tests.helpers import ProjectMock


def test_pyproject_should_be_deleted(request):
"""File should be deleted."""
ProjectMock(request).style("").pyproject_toml("").lint().assert_errors_contain(
"NIP312 File {} should be deleted".format(PyProjectTomlFile.file_name)
)
def test_pyproject_has_no_configuration(request):
"""File should not be deleted unless explicitly asked."""
ProjectMock(request).style("").pyproject_toml("").lint().assert_no_errors()


def test_suggest_initial_contents(request):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_setup_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from tests.helpers import ProjectMock


def test_setup_cfg_should_be_deleted(request):
"""File should be deleted."""
ProjectMock(request).style("").setup_cfg("").lint().assert_single_error("NIP322 File setup.cfg should be deleted")
def test_setup_cfg_has_no_configuration(request):
"""File should not be deleted unless explicitly asked."""
ProjectMock(request).style("").setup_cfg("").lint().assert_no_errors()


def test_comma_separated_keys_on_style_file(request):
Expand Down

0 comments on commit b5953ff

Please sign in to comment.