-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
68 lines (50 loc) · 2.32 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# coding: utf8
from preparechangelog import cmd
import pytest
import shutil
import sys
@pytest.fixture(scope='session')
def gitconfig(request):
config = cmd('git config --global --get-regexp changelog')
if not config:
return
cmd('git config --global --rename-section changelog changelogpytest')
def teardown():
cmd('git config --global --rename-section changelogpytest changelog')
request.addfinalizer(teardown)
@pytest.fixture
def repository(request, gitconfig, tmpdir):
cmd('cd {dir}; git init'.format(dir=tmpdir))
hook = '%s/.git/hooks/prepare-commit-msg' % tmpdir
shutil.copy('preparechangelog.py', hook)
cmd('sed -i -e "s+/usr/bin/env python+{}+" {}'.format(
sys.executable, hook))
return str(tmpdir)
def test_no_changelog_diff_has_no_effect(repository):
message = cmd('cd {dir}; echo "qux" > bar;'
'git add .; EDITOR=cat git commit'.format(dir=repository))
assert message.startswith('#')
def test_prefills_commit_message_from_changelog_diff(repository):
message = cmd('cd {dir}; echo "foo" > CHANGES; echo "qux" > bar;'
'git add .; EDITOR=cat git commit'.format(dir=repository))
assert message.startswith('foo\n')
assert 'qux' not in message
def test_normalizes_bullets(repository):
message = cmd('cd {dir}; echo "- One\\n Two\\n- Three\n" > CHANGES;'
'git add .; EDITOR=cat git commit'.format(dir=repository))
assert message.startswith('One\nTwo\nThree\n')
def test_changelog_filename_is_configurable(repository):
cmd('cd {dir}; git config changelog.filename qux'.format(dir=repository))
message = cmd('cd {dir}; echo "foo" > qux; git add .;'
'EDITOR=cat git commit'.format(dir=repository))
assert message.startswith('foo\n')
def test_handles_non_ascii(repository):
message = cmd('cd {dir}; echo "Ümläut" > CHANGES;'
'git add .; EDITOR=cat git commit'.format(dir=repository))
assert message.startswith(u'Ümläut')
def test_result_of_preprocess_is_used_as_message(repository):
cmd('cd {dir}; git config changelog.preprocess "lambda x: x.upper()"'
.format(dir=repository))
message = cmd('cd {dir}; echo "foo" > CHANGES;'
'git add .; EDITOR=cat git commit'.format(dir=repository))
assert message.startswith('FOO')