Ticket #40: test-bug.py

File test-bug.py, 656 bytes (added by dvd@…, 7 years ago)

the test script

Line 
1class News(object): pass
2
3def news_representer(dumper, news):
4    # skip converting a news in a dict:
5    data = {
6        'date': '732638',
7        'fields': {
8            '': {},
9            'it': {'title': 'Hello World'}
10        },
11        'guid': '0000010f153544cf8a314808007f000000000001',
12        'expiration': None
13    }
14    return dumper.represent_mapping('!news', data)
15
16def news_constructor(loader, node):
17    nodes = loader.construct_mapping(node)
18    print nodes
19    return nodes
20
21import yaml
22
23yaml.add_representer(News, news_representer)
24yaml.add_constructor('!news', news_constructor)
25
26foo = News()
27
28bar = yaml.load(yaml.dump(foo))
29print bar