Exemple #1
0
 def test_has_arg(self):
     t = Template('{{t|a|b=c}}')
     self.assertEqual(True, t.has_arg('1'))
     self.assertEqual(True, t.has_arg('1', 'a'))
     self.assertEqual(True, t.has_arg('b'))
     self.assertEqual(True, t.has_arg('b', 'c'))
     self.assertEqual(False, t.has_arg('2'))
     self.assertEqual(False, t.has_arg('1', 'b'))
     self.assertEqual(False, t.has_arg('c'))
     self.assertEqual(False, t.has_arg('b', 'd'))
Exemple #2
0
    def update_arguments(template: Template, args: dict, overwrite=False):
        """
        Updates the arguments of the given template with the values of the given dict (args)

        Args:
            template: Template that should be updated
            args(dict): Dict containing the arguments that should be set. key=argument name, value=argument value
            overwrite(bool): If True existing values will be overwritten

        Returns:
            Nothing
        """
        for key, value in args.items():
            if template.has_arg(key):
                # update argument
                if overwrite:
                    template.del_arg(key)
                    template.set_arg(key, value)
                else:
                    pass
            else:
                if value is not None:
                    template.set_arg(key, value, preserve_spacing=False)