Beispiel #1
0
    def testRegistration(self):
        """
        Test that the procedure registration works properly.
        """
        def myDummyTemplate(a, b):
            return '{}-{}'.format(a, b)

        with self.assertRaises(TemplateProcedureNotFoundError):
            Template.runProcedure("dummyRegistration")

        Template.registerProcedure("dummyRegistration", myDummyTemplate)
        self.assertIn("dummyRegistration", Template.registeredProcedureNames())
Beispiel #2
0
    def testAssignToToken(self):
        """
        Test that the template can assign the return of procedure to a token.
        """
        def __assignTokenResult(*args):
            return ' '.join(args)

        Template.registerProcedure('assigntokenresult', __assignTokenResult)

        self.assertEqual(
            Template(
                "/(assigntokenresult foo as <test>)/a/{someVar}/(assigntokenresult foo2 as <test2>)_<test>_x_{someVar}_x_<test2>/b/<test>/c/<test2>_{someVar}"
            ).value({'someVar': 'var'}),
            "/foo/a/var/foo2_foo_x_var_x_foo2/b/foo/c/foo2_var")
Beispiel #3
0
    def testSingleQuote(self):
        """
        Test that the template can return a value with single quote.
        """
        def __testSingleQuoteProcedure(*args):
            return ' '.join(args)

        Template.registerProcedure('testsinglequote',
                                   __testSingleQuoteProcedure)

        inputValue = "my 'random\' value'"
        self.assertEqual(
            Template("/(testsinglequote {foo} '2' 3)/").value(
                {'foo': inputValue}), "/{} 2 3/".format(inputValue))