8000 rewrite `args with spaces` test to not require python by m-rsha · Pull Request #2798 · pre-commit/pre-commit · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
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
29 changes: 13 additions & 16 deletions tests/repository_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os.path
import shlex
import shutil
import sys
from typing import Any
Expand All @@ -17,6 +18,7 @@
from pre_commit.clientlib import load_manifest
from pre_commit.hook import Hook
from pre_commit.languages import python
from pre_commit.languages import system
from pre_commit.prefix import Prefix
from pre_commit.repository import _hook_installed
from pre_commit.repository import all_hooks
Expand Down Expand Up @@ -99,22 +101,6 @@ def test_python_hook_default_version(tempdir_factory, store):
test_python_hook(tempdir_factory, store)


def test_python_hook_args_with_spaces(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'python_hooks_repo',
'foo',
[],
b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
b'Hello World\n',
config_kwargs={
'hooks': [{
'id': 'foo',
'args': ['i have spaces', 'and"\'quotes', '$and !this'],
}],
},
)


def test_python_hook_weird_setup_cfg(in_git_dir, tempdir_factory, store):
in_git_dir.join('setup.cfg').write('[install]\ninstall_scripts=/usr/sbin')

Expand Down Expand Up @@ -583,3 +569,14 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
'using language `system` which does not install an environment. '
'Perhaps you meant to use a specific language?'
)


def test_args_with_spaces_and_quotes(tmp_path):
ret = run_language(
tmp_path, system,
f"{shlex.quote(sys.executable)} -c 'import sys; print(sys.argv[1:])'",
('i have spaces', 'and"\'quotes', '$and !this'),
)

expected = b"['i have spaces', 'and\"\\'quotes', '$and !this']\n"
assert ret == (0, expected)
0