def test_warning_no_color(capsys, mocker, warning_message): warning_message, expected_warning_message = warning_message mocker.patch('assible.utils.color.ASSIBLE_COLOR', False) d = Display() d.warning(warning_message) out, err = capsys.readouterr() assert d._warns == {expected_warning_message: 1} assert err == expected_warning_message
def test_warning(capsys, mocker, warning_message): warning_message, expected_warning_message = warning_message mocker.patch('assible.utils.color.ASSIBLE_COLOR', True) mocker.patch('assible.utils.color.parsecolor', return_value=u'1;35') # value for 'bright purple' d = Display() d.warning(warning_message) out, err = capsys.readouterr() assert d._warns == {expected_warning_message: 1} assert err == '\x1b[1;35m{0}\x1b[0m\n'.format( expected_warning_message.rstrip('\n'))
from jinja2 import __version__ as j2_version from jinja2 import Environment from jinja2.utils import concat as j2_concat USE_JINJA2_NATIVE = False if C.DEFAULT_JINJA2_NATIVE: try: from jinja2.nativetypes import NativeEnvironment from assible.template.native_helpers import assible_native_concat from assible.utils.native_jinja import NativeJinjaText USE_JINJA2_NATIVE = True except ImportError: from jinja2 import Environment from jinja2.utils import concat as j2_concat display.warning('jinja2_native requires Jinja 2.10 and above. ' 'Version detected: %s. Falling back to default.' % j2_version) JINJA2_BEGIN_TOKENS = frozenset( ('variable_begin', 'block_begin', 'comment_begin', 'raw_begin')) JINJA2_END_TOKENS = frozenset( ('variable_end', 'block_end', 'comment_end', 'raw_end')) RANGE_TYPE = type(range(0)) def generate_assible_template_vars(path, dest_path=None): b_path = to_bytes(path) try: template_uid = pwd.getpwuid(os.stat(b_path).st_uid).pw_name except (KeyError, TypeError):