Tests refactoring: test_abbreviation_expansion tests replaced by parametrization, docstrings added
@@ -9,48 +9,41 @@ from cookiecutter.config import BUILTIN_ABBREVIATIONS
from cookiecutter.repository import expand_abbreviations
-def test_abbreviation_expansion():
- input_dir = expand_abbreviations(
- 'foo', {'foo': 'bar'}
+@pytest.mark.parametrize(
+ ('template', 'abbreviations', 'expected_result'),
+ [
+ ('foo', {'foo': 'bar'}, 'bar'),
+ ('baz', {'foo': 'bar'}, 'baz'),
+ ('xx:a', {'xx': '<{0}>'}, '<a>'),
+ ('gh:a', {'gh': '<{0}>'}, '<a>'),
+ ('xx:a', {'xx': '<>'}, '<>'),
+ ('gh:pydanny/cookiecutter-django',
+ BUILTIN_ABBREVIATIONS,
+ 'https://github.com/pydanny/cookiecutter-django.git'),
+ ('gl:pydanny/cookiecutter-django',
+ BUILTIN_ABBREVIATIONS,
+ 'https://gitlab.com/pydanny/cookiecutter-django.git'),
+ ('bb:pydanny/cookiecutter-django',
+ BUILTIN_ABBREVIATIONS,
+ 'https://bitbucket.org/pydanny/cookiecutter-django'),
+ ], ids=(
+ 'Simple expansion',
+ 'Skip expansion (expansion not an abbreviation)',
+ 'Expansion prefix',
+ 'expansion_override_builtin',
+ 'expansion_prefix_ignores_suffix',
+ 'Correct expansion for builtin abbreviations (github)',
+ 'Correct expansion for builtin abbreviations (gitlab)',
+ 'Correct expansion for builtin abbreviations (bitbucket)',
)
- assert input_dir == 'bar'
-
-
-def test_abbreviation_expansion_not_an_abbreviation():
- input_dir = expand_abbreviations(
- 'baz', {'foo': 'bar'}
- )
- assert input_dir == 'baz'
-
-
-def test_abbreviation_expansion_prefix():
- input_dir = expand_abbreviations(
- 'xx:a', {'xx': '<{0}>'}
- )
- assert input_dir == '<a>'
-
-
-def test_abbreviation_expansion_builtin():
- input_dir = expand_abbreviations(
- 'gh:pydanny/cookiecutter-django', BUILTIN_ABBREVIATIONS
- )
- assert input_dir == 'https://github.com/pydanny/cookiecutter-django.git'
-
-
-def test_abbreviation_expansion_override_builtin():
- input_dir = expand_abbreviations(
- 'gh:a', {'gh': '<{0}>'}
- )
- assert input_dir == '<a>'
-
-
-def test_abbreviation_expansion_prefix_ignores_suffix():
- input_dir = expand_abbreviations(
- 'xx:a', {'xx': '<>'}
)
- assert input_dir == '<>'
+def test_abbreviation_expansion(template, abbreviations, expected_result):
+ """Verify abbreviation unpacking."""
+ expanded = expand_abbreviations(template, abbreviations)
+ assert expanded == expected_result
def test_abbreviation_expansion_prefix_not_0_in_braces():
+ """Verify abbreviation unpacking raises error on incorrect index."""
with pytest.raises(IndexError):
expand_abbreviations('xx:a', {'xx': '{1}'})
