class ChainLoaderTestCase(unittest.TestCase): """ Test the ``ChainLoader``. """ def setUp(self): from wheezy.template.loader import ChainLoader from wheezy.template.loader import DictLoader self.loader = ChainLoader(loaders=[ DictLoader(templates={ 'tmpl1.html': 'x1', }), DictLoader(templates={'shared/master.html': 'x2'}) ]) def test_list_names(self): """ Tests list_names. """ assert ('shared/master.html', 'tmpl1.html') == self.loader.list_names() def test_load_existing(self): """ Tests load. """ assert 'x1' == self.loader.load('tmpl1.html') assert 'x2' == self.loader.load('shared/master.html') def test_load_missing(self): """ Tests load not found. """ assert not self.loader.load('missing')
def setUp(self) -> None: self.loader = ChainLoader(loaders=[ DictLoader(templates={ "tmpl1.html": "x1", }), DictLoader(templates={"shared/master.html": "x2"}), ])
def setUp(self): from wheezy.template.loader import ChainLoader from wheezy.template.loader import DictLoader self.loader = ChainLoader(loaders=[ DictLoader(templates={ 'tmpl1.html': 'x1', }), DictLoader(templates={'shared/master.html': 'x2'}) ])
def ensure_runtime_engine(self, key: str) -> Engine: self.lock.acquire(True) try: engines = self.runtime_engines if key in engines: # pragma: nocover return engines[key] engine = engines[key] = self.runtime_engine_factory( ChainLoader([DictLoader({}), self.engine.loader]) ) def render( name: str, ctx: typing.Mapping[str, typing.Any], local_defs: typing.Mapping[str, typing.Any], super_defs: typing.Mapping[str, typing.Any], ) -> str: try: return engine.renders[name](ctx, local_defs, super_defs) except KeyError: self.preprocess_template(engine, name, ctx) return engine.renders[name](ctx, local_defs, super_defs) engine.global_vars["_r"] = render return engine finally: self.lock.release()
class ChainLoaderTestCase(unittest.TestCase): """Test the ``ChainLoader``.""" def setUp(self) -> None: self.loader = ChainLoader(loaders=[ DictLoader(templates={ "tmpl1.html": "x1", }), DictLoader(templates={"shared/master.html": "x2"}), ]) def test_list_names(self) -> None: """Tests list_names.""" assert ("shared/master.html", "tmpl1.html") == self.loader.list_names() def test_load_existing(self) -> None: """Tests load.""" assert "x1" == self.loader.load("tmpl1.html") assert "x2" == self.loader.load("shared/master.html") def test_load_missing(self) -> None: """Tests load not found.""" assert not self.loader.load("missing")
def ensure_runtime_engine(self, key): self.lock.acquire(1) try: engines = self.runtime_engines if key in engines: # pragma: nocover return engines[key] engine = engines[key] = self.runtime_engine_factory( loader=ChainLoader([DictLoader({}), self.engine.loader])) def render(name, ctx, local_defs, super_defs): try: return engine.renders[name](ctx, local_defs, super_defs) except KeyError: self.preprocess_template(engine, name, ctx) return engine.renders[name](ctx, local_defs, super_defs) engine.global_vars['_r'] = render return engine finally: self.lock.release()