feat: add util.mako_renderer() function

This commit is contained in:
Lance Edgar 2024-11-20 10:29:31 -06:00
parent 4879887cb3
commit c41d364e03
6 changed files with 63 additions and 2 deletions

View file

@ -0,0 +1,4 @@
[files."baz"]
renderer = 'mako'
tags = ['baz']

1
tests/files/bar/baz Normal file
View file

@ -0,0 +1 @@
machine_is_live = ${machine_is_live}

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8; -*-
import os
from unittest import TestCase
from unittest.mock import MagicMock
@ -12,3 +13,14 @@ class TestExists(TestCase):
c = MagicMock()
mod.exists(c, '/foo')
c.run.assert_called_once_with('test -e /foo', warn=True)
class TestMakoRenderer(TestCase):
def test_basic(self):
c = MagicMock()
renderer = mod.mako_renderer(c, env={'machine_is_live': True})
here = os.path.dirname(__file__)
path = os.path.join(here, 'files', 'bar', 'baz')
rendered = renderer(path, vars={})
self.assertEqual(rendered, 'machine_is_live = True')