1
0
Fork 0
mirror of synced 2024-11-04 17:08:56 -05:00
yadm/test/test_unit_is_valid_branch_name.py
2019-10-08 17:28:53 -05:00

40 lines
1.1 KiB
Python

"""Unit tests: is_valid_branch_name"""
import pytest
# Git branches do not allow:
# * path component that begins with "."
# * double dot
# * "~", "^", ":", "\", space
# * end with a "/"
# * end with ".lock"
@pytest.mark.parametrize(
'branch, expected', [
('master', 'valid'),
('path/branch', 'valid'),
('path/.branch', 'invalid'),
('path..branch', 'invalid'),
('path~branch', 'invalid'),
('path^branch', 'invalid'),
('path:branch', 'invalid'),
('path\\branch', 'invalid'),
('path branch', 'invalid'),
('path/branch/', 'invalid'),
('branch.lock', 'invalid'),
])
def test_is_valid_branch_name(runner, yadm, branch, expected):
"""Test function is_valid_branch_name()"""
script = f"""
YADM_TEST=1 source {yadm}
if is_valid_branch_name "{branch}"; then
echo valid
else
echo invalid
fi
"""
run = runner(command=['bash'], inp=script)
assert run.success
assert run.err == ''
assert run.out.strip() == expected