def test__attach_function(self): """ Test that it works to attach a function to the global namespace that jinja will later use. """ global _local_env c = Core({}) def foo_func(): pass c._attach_function("globals", foo_func, "func") assert "func" in _local_env["globals"] assert _local_env["globals"]["func"] == foo_func # Test that exception is raised if we try to attach to wrong jinja namespace with pytest.raises(KeyError) as ex: c._attach_function("foobar", foo_func, "func") assert str(ex.value).startswith("'foobar'")
def test__update_env(self, tmpdir): """ """ global _local_env i = tmpdir.join("Dockerfile.jinja") i.write("{{ func() }}") o = tmpdir.join("Dockerfile") c = Core({ "--dockerfile": str(i), "--outfile": str(o), }) def foo_func(): return "foobar" c._attach_function("globals", foo_func, "func") template = Template(i.read()) c._update_env(template.environment) rendered_template = template.render() assert rendered_template == "foobar"