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

Always format modules.json after writing it #2074

Merged
merged 16 commits into from
Dec 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions tests/test_lint_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import shutil
import tempfile
import unittest
from pathlib import Path

import git
import pytest
Expand Down Expand Up @@ -59,7 +62,18 @@ def test_run_prettier_on_malformed_file(malformed_json):
assert malformed_json.read_text() == JSON_FORMATTED


def test_run_prettier_on_synthax_error_file(synthax_error_json):
with pytest.raises(ValueError) as exc_info:
nf_core.lint_utils.run_prettier_on_file(synthax_error_json)
assert exc_info.value.args[0].startswith(f"Can't format {synthax_error_json} because it has a synthax error.")
class TestPrettierLogging(unittest.TestCase):
fabianegli marked this conversation as resolved.
Show resolved Hide resolved
def test_run_prettier_on_synthax_error_file(self):
with tempfile.TemporaryDirectory() as tmp_git_dir:
repo = git.Repo.init(tmp_git_dir)
file = Path(tmp_git_dir) / "synthax-error.json"
with open(file, "w", encoding="utf-8") as f:
f.write(JSON_WITH_SYNTAX_ERROR)
repo.git.add(file)
with self.assertLogs(level="CRITICAL") as mocked_critical:
nf_core.lint_utils.run_prettier_on_file(file)
expected_error_message = (
"synthax-error.json: SyntaxError: Unexpected token (1:10)\n"
"[error] > 1 | {'a':1, 1}\n[error] | ^\n"
)
assert expected_error_message in mocked_critical.output[0]