Beispiel #1
0
def insertTokensIntoTemplate(template, **kwargs):
    neededTokenValues = extractTokensFromTemplates(template)

    for key, value in kwargs.items():
        if key in neededTokenValues:
            neededTokenValues.remove(key)
            template = template.replace("<" + key + ">", value)

    if len(neededTokenValues) > 0:
        raise ValueError

    return template
Beispiel #2
0
def test_simpleTemplate():
    assert extractTokensFromTemplates("<test>") == {"test"}
Beispiel #3
0
def test_brackets():
    assert extractTokensFromTemplates("<bracket>") == set(["bracket"])
    assert extractTokensFromTemplates("no_bracket") == set()
Beispiel #4
0
def test_characters():
    assert extractTokensFromTemplates("<@>") == set()
    assert extractTokensFromTemplates("<*>") == set()
Beispiel #5
0
def test_noTemplate():
    assert extractTokensFromTemplates("") == set()
Beispiel #6
0
def test_words():
    assert extractTokensFromTemplates("word<words>") == set(["words"])
Beispiel #7
0
def test_number():
    assert extractTokensFromTemplates("<1>") == set("1")
Beispiel #8
0
def test_NestTemplate():
    assert extractTokensFromTemplates("<<test>>") == {"test"}

    assert extractTokensFromTemplates("<!<test!><>") == set()
Beispiel #9
0
def test_complexTemplate():
    assert extractTokensFromTemplates("<1> <2> <3> <4>") == {
        "1", "2", "3", "4"
    }
Beispiel #10
0
 def extractPageTokens(self):
     tokens = set()
     for template in self.templates:
         [tokens.add(t) for t in extractTokensFromTemplates(template)]
     return tokens