def test_load_templates_custom(self): """Test to load custom templates using an existing directory """ with TempDir() as temp: # prepare directory with path("dakara_player.resources.templates", "idle.ass") as file: Path(file).copy(temp) with path("dakara_player.resources.templates", "transition.ass") as file: Path(file).copy(temp) # create object text_generator = TextGenerator( package="dakara_player.resources.templates", directory=temp, filenames={ "idle": "idle.ass", "transition": "transition.ass" }, ) # call the method text_generator.load_templates() # assert there are templates defined loader_custom, loader_default = text_generator.environment.loader.loaders self.assertIn("idle.ass", loader_custom.list_templates()) self.assertIn("transition.ass", loader_custom.list_templates())
def test_load_templates( self, mocked_environment_class, mocked_file_system_loader_class, mocked_package_loader_class, mocked_choice_loader_class, mocked_check_template, ): """Test to load templates for text """ mocked_environment_class.return_value.filters = {} # create object text_generator = TextGenerator("package.templates", Path("directory"), filenames={"text": "text.ass"}) # pre assert there are no templates self.assertIsNone(text_generator.environment) # call the method text_generator.load_templates() # assert there are templates defined self.assertIsNotNone(text_generator.environment) mocked_file_system_loader_class.assert_called_with(Path("directory")) mocked_package_loader_class.assert_called_with("package", "templates") mocked_choice_loader_class.assert_called_with([ mocked_file_system_loader_class.return_value, mocked_package_loader_class.return_value, ]) mocked_environment_class.assert_called_with( loader=mocked_choice_loader_class.return_value) mocked_check_template.assert_called_once_with(text_generator, "text", "text.ass")
def test_load_templates_default(self): """Test to load default templates using an existing directory Integration test. """ with TempDir() as temp: # create object text_generator = TextGenerator( package="dakara_player.resources.templates", directory=temp, filenames={ "idle": "idle.ass", "transition": "transition.ass" }, ) # call the method text_generator.load_templates() # assert there are templates defined loader_custom, loader_default = text_generator.environment.loader.loaders self.assertNotIn("idle.ass", loader_custom.list_templates()) self.assertNotIn("transition.ass", loader_custom.list_templates()) self.assertIn("idle.ass", loader_default.list_templates()) self.assertIn("transition.ass", loader_default.list_templates())