def test_render_string_template_bug_1(): #Looks like string templates can't contain dollar signs. We need some kind of escaping with pytest.raises(ValueError): template = { 'template': 'Car Insurance Premiums ($)', 'tooltip': { 'content': 'expect_column_to_exist', 'placement': 'top' } } DefaultJinjaPageView.render_string_template(template)
def test_render_string_template(): template = { "template": "$column Kullback-Leibler (KL) divergence with respect to the following distribution must be lower than $threshold: $sparklines_histogram", "params": { "column": "categorical_fixed", "partition_object": { "weights": [0.54, 0.32, 0.14], "values": ["A", "B", "C"] }, "threshold": 0.1, "sparklines_histogram": u"\u2588\u2584\u2581" }, "styling": { "default": { "classes": ["badge", "badge-secondary"] }, "params": { "sparklines_histogram": { "styles": { "font-family": "serif" } } } } } res = DefaultJinjaPageView.render_string_template(template).replace( " ", "").replace("\t", "").replace("\n", "") expected = u"""<span> <span class="badge badge-secondary" >categorical_fixed</span> Kullback-Leibler (KL) divergence with respect to the following distribution must be lower than <span class="badge badge-secondary" >0.1</span>: <span style="font-family:serif;" >█▄▁</span> </span>""".replace(" ", "").replace("\t", "").replace("\n", "") assert res == expected template = { "template": "$column Kullback-Leibler (KL) divergence with respect to the following distribution must be lower than $threshold: $sparklines_histogram", "params": { "column": "categorical_fixed", "partition_object": { "weights": [0.54, 0.32, 0.14], "values": ["A", "B", "C"] }, "threshold": 0.1, "sparklines_histogram": u"▃▆▁█" }, "styling": { "default": { "classes": ["badge", "badge-secondary"] }, "params": { "sparklines_histogram": { "styles": { "font-family": "serif" } } } } } res = DefaultJinjaPageView.render_string_template(template).replace( " ", "").replace("\t", "").replace("\n", "") expected = u"""<span> <span class="badge badge-secondary" >categorical_fixed</span> Kullback-Leibler (KL) divergence with respect to the following distribution must be lower than <span class="badge badge-secondary" >0.1</span>: <span style="font-family:serif;" >▃▆▁█</span> </span>""".replace(" ", "").replace("\t", "").replace("\n", "") assert res == expected
def test_render_template(): assert DefaultJinjaPageView.render_string_template({ "template": "It was the $first_adj of times; it was the $second_adj of times.", "params": { "first_adj": "best", "second_adj": "worst", } }).replace(" ", "").replace("\t", "").replace("\n", "") == "<span>It was the best of times; it was the worst of times.</span>".replace(" ", "").replace("\t", "").replace("\n", "") assert DefaultJinjaPageView.render_string_template({ "template": "It was the $first_adj of times; it was the $second_adj of times.", "params": { "first_adj": "best", "second_adj": "worst", }, "styling": { "default": { "classes": ["badge", "badge-warning"], } } }).replace(" ", "").replace("\t", "").replace("\n", "") == '<span>It was the <span class="badge badge-warning" >best</span> of times; it was the <span class="badge badge-warning" >worst</span> of times.</span>'.replace(" ", "").replace("\t", "").replace("\n", "") assert DefaultJinjaPageView.render_string_template({ "template": "It was the $first_adj of times; it was the $second_adj of times.", "params": { "first_adj": "best", "second_adj": "worst", }, "styling": { "default": { "classes": ["badge", "badge-warning"], }, "params": { "first_adj": { "classes": ["badge-error"], } } } }).replace(" ", "").replace("\t", "").replace("\n", "") == '<span>It was the <span class="badge-error" >best</span> of times; it was the <span class="badge badge-warning" >worst</span> of times.</span>'.replace(" ", "").replace("\t", "").replace("\n", "") assert DefaultJinjaPageView.render_string_template({ "template": "It was the $first_adj of times; it was the $second_adj of times.", "params": { "first_adj": "best", "second_adj": "worst", }, "styling": { "params": { "first_adj": { "classes": ["badge", "badge-warning"], } } } }).replace(" ", "").replace("\t", "").replace("\n", "") == '<span>It was the <span class="badge badge-warning" >best</span> of times; it was the worst of times.</span>'.replace(" ", "").replace("\t", "").replace("\n", "") assert DefaultJinjaPageView.render_string_template({ "template": "It was the $first_adj of times; it was the $second_adj of times.", "params": { "first_adj": "best", "second_adj": "worst", }, "styling": { "params": { "first_adj": { "classes": ["badge", "badge-warning"], "attributes": { "role": "alert" }, "styles": { "padding": "5px" } } } } }).replace(" ", "").replace("\t", "").replace("\n", "") == '<span>It was the <span class="badge badge-warning" role="alert" style="padding:5px;" >best</span> of times; it was the worst of times.</span>'.replace(" ", "").replace("\t", "").replace("\n", "")