Merge pull request #3093 from pre-commit/removeprefix

python 3.9+: use removeprefix
This commit is contained in:
Anthony Sottile 2023-12-09 16:13:25 -05:00 committed by GitHub
commit 7dc0a59ee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 8 deletions

View file

@ -349,8 +349,9 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store):
# We should run both the legacy and pre-commit hooks
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert output.startswith('legacy hook\n')
NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):])
legacy = 'legacy hook\n'
assert output.startswith(legacy)
NORMAL_PRE_COMMIT_RUN.assert_matches(output.removeprefix(legacy))
def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
@ -375,8 +376,9 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store):
# We should run both the legacy and pre-commit hooks
ret, output = _get_commit_output(tempdir_factory)
assert ret == 0
assert output.startswith('legacy hook\n')
NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):])
legacy = 'legacy hook\n'
assert output.startswith(legacy)
NORMAL_PRE_COMMIT_RUN.assert_matches(output.removeprefix(legacy))
def test_install_with_existing_non_utf8_script(tmpdir, store):

View file

@ -185,7 +185,7 @@ def test_db_repo_name(store):
def test_local_resources_reflects_reality():
on_disk = {
res[len('empty_template_'):]
res.removeprefix('empty_template_')
for res in os.listdir('pre_commit/resources')
if res.startswith('empty_template_')
}