diff 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
line wrap: on
line diff
--- a/tests/test_configuration.py	Wed Oct 15 21:18:27 2014 -0700
+++ b/tests/test_configuration.py	Wed Oct 15 23:01:05 2014 -0700
@@ -1,8 +1,9 @@
 import copy
+import datetime
 import yaml
 import pytest
 from collections import OrderedDict
-from piecrust.configuration import (Configuration, OrderedDictYAMLLoader,
+from piecrust.configuration import (Configuration, ConfigurationLoader,
         merge_dicts)
 
 
@@ -118,7 +119,25 @@
     b: no
     c: null
 """
-    data = yaml.load(sample, Loader=OrderedDictYAMLLoader)
+    data = yaml.load(sample, Loader=ConfigurationLoader)
     assert type(data) is OrderedDict
     assert list(data['one'].keys()) == ['two', 'red', 'blue']
 
+
+def test_load_time1():
+    sample = """
+time: 21:35
+"""
+    data = yaml.load(sample, Loader=ConfigurationLoader)
+    assert type(data['time']) is int
+    assert data['time'] == (21 * 60 * 60 + 35 * 60)
+
+
+def test_load_time2():
+    sample = """
+time: 21:35:50
+"""
+    data = yaml.load(sample, Loader=ConfigurationLoader)
+    assert type(data['time']) is int
+    assert data['time'] == (21 * 60 * 60 + 35 * 60 + 50)
+