Пример #1
0
def test_render_missing_key(examples):
    target_dir, fs_examples = examples
    with raises(KeyError):
        render_template(path.join(fs_examples,
                'unbound/usr/local/etc/unbound/unbound.conf.tmpl'),
            target_dir,
            dict(),
            python_formatting_renderer)
Пример #2
0
def test_rendered_permissions_preserved(examples):
    target_dir, fs_examples = examples
    fs_template = path.join(fs_examples,
        'unbound/usr/local/etc/unbound/unbound.conf.tmpl')
    chmod(fs_template, 0771)
    fs_rendered = render_template(fs_template,
        target_dir,
        dict(ip_addr='192.168.0.1', access_control='10.0.1.0/16 allow'),
        python_formatting_renderer)
    assert stat.S_IMODE(os.stat(fs_rendered).st_mode) == 0771
Пример #3
0
def test_render_copy(examples):
    """if the source is not a template, it is copied."""
    target_dir, fs_examples = examples
    fs_source = path.join(fs_examples, 'unbound/etc/rc.conf')
    fs_rendered = render_template(fs_source,
        target_dir,
        dict(ip_addr='192.168.0.1', access_control='10.0.1.0/16 allow'),
        python_formatting_renderer)
    assert fs_rendered.endswith('/rc.conf')
    assert (cmp(fs_source, fs_rendered))
Пример #4
0
def test_render_template(examples):
    """if the source is a template, it is rendered and the target file drops
    the `.tmpl` suffix."""
    target_dir, fs_examples = examples
    fs_rendered = render_template(path.join(fs_examples,
            'unbound/usr/local/etc/unbound/unbound.conf.tmpl'),
        target_dir,
        dict(ip_addr='192.168.0.1', access_control='10.0.1.0/16 allow'),
        python_formatting_renderer)
    assert fs_rendered.endswith('/unbound.conf')
    assert ('interface: 192.168.0.1' in open(fs_rendered).read())
Пример #5
0
    def call_FUT(self, template, variables, output_dir=None, verbose=False, renderer=None):
        from mrbob.rendering import render_template
        from mrbob.rendering import python_formatting_renderer

        if output_dir is None:
            output_dir = self.fs_tempdir

        if renderer is None:
            renderer = python_formatting_renderer

        return render_template(
            template,
            output_dir,
            variables,
            verbose,
            renderer,
        )