Mercurial > kallithea
changeset 6885:d22eb3c1797b
ini: introduce a bit of doctest for the new inifile module
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 14 Sep 2017 02:08:06 +0200 |
parents | e3cce237d77c |
children | 535c397ee90d |
files | kallithea/lib/inifile.py |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/inifile.py Thu Sep 14 02:08:06 2017 +0200 +++ b/kallithea/lib/inifile.py Thu Sep 14 02:08:06 2017 +0200 @@ -31,6 +31,46 @@ """Expand mako template and tweak it. Not entirely stable for random templates as input, but good enough for our single template. + + >>> template = ''' + ... [first-section] + ... + ... variable=${mako_variable} + ... variable2 =\tvalue after tab + ... ## This section had some whitespace and stuff + ... + ... + ... # ${mako_function()} + ... [second-section] + ... %if conditional_options == 'option-a': + ... # Kallithea - config file generated with kallithea-config # + ... %elif conditional_options == 'option-b': + ... some_variable = "never mind - option-b will not be used anyway ..." + ... %endif + ... ''' + >>> desc = 'Description\\nof this config file' + >>> selected_mako_conditionals = ["conditional_options == 'option-a'"] + >>> mako_variable_values = {'mako_variable': 'VALUE', 'mako_function()': 'FUNCTION RESULT'} + >>> settings = { # only partially used + ... '[first-section]': {'variable2': 'VAL2', 'first_extra': 'EXTRA'}, + ... '[third-section]': {'third_extra': ' 3'}, + ... '[fourth-section]': {'fourth_extra': '4', 'fourth': '"four"'}, + ... } + >>> print expand(template, desc, selected_mako_conditionals, mako_variable_values, settings) + <BLANKLINE> + [first-section] + <BLANKLINE> + variable=VALUE + variable2 = value after tab + ## This section had some whitespace and stuff + <BLANKLINE> + <BLANKLINE> + # FUNCTION RESULT + [second-section] + # Description # + # of this config file # + #some_variable = "never mind - option-b will not be used anyway ..." + <BLANKLINE> """ # select the right mako conditionals for the other less sophisticated formats def sub_conditionals(m):