af9e394c8e
Currently, Loader.source_path is used for both error locations and as base for include directory. But, it is set to "<expanded j2-yaml>" by !j2-yaml: tag, which makes it unusable as base for include directory. Make separate source_dir attribute for this usage. Change-Id: I67669eb42f761e2d76e89992e6ad89480ddd3df0
22 lines
614 B
Python
22 lines
614 B
Python
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
from jenkins_jobs.config import JJBConfig
|
|
from jenkins_jobs.yaml_objects import J2String
|
|
|
|
|
|
cases = [
|
|
("{{ abc }}", {"abc"}),
|
|
("{% if cond %} {{ x }} {% else %} {{ y }} {% endif %}", {"cond", "x", "y"}),
|
|
("{# {{ abc }} #}", {}),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("format,expected_used_params", cases)
|
|
def test_jinja2_required_params(format, expected_used_params):
|
|
config = JJBConfig()
|
|
loader = Mock(source_dir=None)
|
|
template = J2String(config, loader, pos=None, template_text=format)
|
|
assert template.required_params == set(expected_used_params)
|