Mercurial > piecrust2
comparison tests/test_configuration.py @ 107:10fc9c8bf682
Better support for times in YAML interop.
* Use our own sexagesimal parser/dumper for YAML to properly parse times.
* Better name for the custom parser/dumper classes.
* Add unit tests.
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Wed, 15 Oct 2014 23:01:05 -0700 |
| parents | 563ce5dd02af |
| children | f98451237371 |
comparison
equal
deleted
inserted
replaced
| 106:5effaf1978d0 | 107:10fc9c8bf682 |
|---|---|
| 1 import copy | 1 import copy |
| 2 import datetime | |
| 2 import yaml | 3 import yaml |
| 3 import pytest | 4 import pytest |
| 4 from collections import OrderedDict | 5 from collections import OrderedDict |
| 5 from piecrust.configuration import (Configuration, OrderedDictYAMLLoader, | 6 from piecrust.configuration import (Configuration, ConfigurationLoader, |
| 6 merge_dicts) | 7 merge_dicts) |
| 7 | 8 |
| 8 | 9 |
| 9 @pytest.mark.parametrize('values, expected', [ | 10 @pytest.mark.parametrize('values, expected', [ |
| 10 (None, {}), | 11 (None, {}), |
| 116 two: | 117 two: |
| 117 a: yes | 118 a: yes |
| 118 b: no | 119 b: no |
| 119 c: null | 120 c: null |
| 120 """ | 121 """ |
| 121 data = yaml.load(sample, Loader=OrderedDictYAMLLoader) | 122 data = yaml.load(sample, Loader=ConfigurationLoader) |
| 122 assert type(data) is OrderedDict | 123 assert type(data) is OrderedDict |
| 123 assert list(data['one'].keys()) == ['two', 'red', 'blue'] | 124 assert list(data['one'].keys()) == ['two', 'red', 'blue'] |
| 124 | 125 |
| 126 | |
| 127 def test_load_time1(): | |
| 128 sample = """ | |
| 129 time: 21:35 | |
| 130 """ | |
| 131 data = yaml.load(sample, Loader=ConfigurationLoader) | |
| 132 assert type(data['time']) is int | |
| 133 assert data['time'] == (21 * 60 * 60 + 35 * 60) | |
| 134 | |
| 135 | |
| 136 def test_load_time2(): | |
| 137 sample = """ | |
| 138 time: 21:35:50 | |
| 139 """ | |
| 140 data = yaml.load(sample, Loader=ConfigurationLoader) | |
| 141 assert type(data['time']) is int | |
| 142 assert data['time'] == (21 * 60 * 60 + 35 * 60 + 50) | |
| 143 |
