summaryrefslogtreecommitdiff
path: root/creole/tests/test_macros.py
blob: 2a036be0b4a2130103d16c2ef40dce907ed6fbcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding: utf-8


"""
    Creole unittest macros
    ~~~~~~~~~~~~~~~~~~~~~~

    Note: all mecro functions must return unicode!

    :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""




import json

def unittest_macro1(**kwargs):
    """
    >>> unittest_macro1(foo="bar")
    '[test macro1 - kwargs: foo="bar"]'

    >>> unittest_macro1()
    '[test macro1 - kwargs: ]'

    >>> unittest_macro1(a=1,b=2)
    '[test macro1 - kwargs: a=1,b=2]'
    """
    kwargs = ','.join(['%s=%s' % (k, json.dumps(v)) for k, v in sorted(kwargs.items())])
    return "[test macro1 - kwargs: %s]" % kwargs


def unittest_macro2(char, text):
    """
    >>> unittest_macro2(char="|", text="a\\nb")
    'a|b'
    """
    return char.join(text.split())

if __name__ == '__main__':
    import doctest
    print(doctest.testmod())