mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 11:16:53 +00:00
Refactor jinja usage
Moved out templates to root dir and start using only jinja template instead of the complete Environment class. Requirements here are quite simple.
This commit is contained in:
parent
ac248b5011
commit
51e5b74f80
4 changed files with 21 additions and 25 deletions
|
|
@ -3,10 +3,10 @@ from __future__ import annotations
|
|||
import pytest
|
||||
|
||||
from pre_commit_hooks.prepare_commit_msg import get_current_branch
|
||||
from pre_commit_hooks.prepare_commit_msg import get_jinja_env
|
||||
from pre_commit_hooks.prepare_commit_msg import main
|
||||
from pre_commit_hooks.prepare_commit_msg import update_commit_file
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
from testing.util import get_template_path
|
||||
|
||||
|
||||
def test_current_branch(temp_git_dir):
|
||||
|
|
@ -30,37 +30,37 @@ TESTS = (
|
|||
b'',
|
||||
b'[1.0.0] ',
|
||||
'release/1.0.0', # but this should
|
||||
'prepare_commit_msg_prepend.j2',
|
||||
get_template_path('prepare_commit_msg_prepend.j2'),
|
||||
),
|
||||
(
|
||||
b'',
|
||||
b'[TT-01] ',
|
||||
'feature/TT-01',
|
||||
'prepare_commit_msg_prepend.j2',
|
||||
get_template_path('prepare_commit_msg_prepend.j2'),
|
||||
),
|
||||
(
|
||||
b'[TT-02] Some message',
|
||||
b'[TT-02] Some message',
|
||||
'feature/TT-02',
|
||||
'prepare_commit_msg_prepend.j2',
|
||||
get_template_path('prepare_commit_msg_prepend.j2'),
|
||||
),
|
||||
(
|
||||
b'Initial message',
|
||||
b'[TT-03] Initial message',
|
||||
'feature/TT-03',
|
||||
'prepare_commit_msg_prepend.j2',
|
||||
get_template_path('prepare_commit_msg_prepend.j2'),
|
||||
),
|
||||
(
|
||||
b'',
|
||||
b'\n\nRelates: AA-01',
|
||||
'feature/AA-01',
|
||||
'prepare_commit_msg_append.j2',
|
||||
get_template_path('prepare_commit_msg_append.j2'),
|
||||
),
|
||||
(
|
||||
b'Initial message',
|
||||
b'Initial message\n\nRelates: AA-02',
|
||||
'feature/AA-02',
|
||||
'prepare_commit_msg_append.j2',
|
||||
get_template_path('prepare_commit_msg_append.j2'),
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -77,9 +77,12 @@ def test_update_commit_file(
|
|||
path = temp_git_dir.join('COMMIT_EDITMSG')
|
||||
path.write_binary(input_s)
|
||||
parts = branch_name.split('/')
|
||||
ticket = parts[1] if len(parts) > 1 else parts[0]
|
||||
jinja = get_jinja_env()
|
||||
update_commit_file(jinja, path, template, ticket)
|
||||
ticket = str(parts[1]) if len(parts) > 1 else str(parts[0])
|
||||
update_commit_file(path, template, ticket)
|
||||
|
||||
# here the filtering is still not in place
|
||||
if branch_name == 'test':
|
||||
expected_val = b''
|
||||
|
||||
assert path.read_binary() == expected_val
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue