def test_patch_separator_suffix(self) -> None: patches = {"plugin1": "abcd", "plugin2": "efgh"} with patch.object(env.plugins, "iter_patches", return_value=patches.values()): rendered = env.render_str( {}, '{{ patch("location", separator=",\n", suffix=",") }}' ) self.assertEqual("abcd,\nefgh,", rendered)
def test_patch(self): patches = {"plugin1": "abcd", "plugin2": "efgh"} with unittest.mock.patch.object( env.plugins, "iter_patches", return_value=patches.items() ) as mock_iter_patches: rendered = env.render_str({}, '{{ patch("location") }}') mock_iter_patches.assert_called_once_with({}, "location") self.assertEqual("abcd\nefgh", rendered)
def test_common_domain(self): self.assertEqual( "mydomain.com", env.render_str( {"d1": "d1.mydomain.com", "d2": "d2.mydomain.com"}, "{{ d1|common_domain(d2) }}", ), )
def find_remote_image_tags(config: Config, filtre: hooks.filters.Filter, image: str) -> t.Iterator[str]: """ Iterate over all images to push or pull. If no corresponding image is found, raise exception. Yield: tag """ all_remote_images: t.Iterator[t.Tuple[str, str]] = filtre.iterate(config) found = False for name, tag in all_remote_images: if image in [name, "all"]: found = True yield tutor_env.render_str(config, tag) if not found: raise ImageNotFoundError(image)
def find_images_to_build( config: Config, image: str ) -> t.Iterator[t.Tuple[str, t.Tuple[str], str, t.List[str]]]: """ Iterate over all images to build. If no corresponding image is found, raise exception. Yield: (name, path, tag, build args) """ all_images_to_build: t.Iterator[ t.Tuple[str, t.Tuple[str], str, t.List[str]]] = hooks.Filters.IMAGES_BUILD.iterate(config) found = False for name, path, tag, args in all_images_to_build: if image in [name, "all"]: found = True tag = tutor_env.render_str(config, tag) yield (name, path, tag, args) if not found: raise ImageNotFoundError(image)
def test_render_str(self): self.assertEqual( "hello world", env.render_str({"name": "world"}, "hello {{ name }}") )