|
@@ -1,12 +1,14 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
import pytest
|
|
import pytest
|
|
|
|
|
|
-import pytz
|
|
|
|
-import ioex.datetimeex
|
|
|
|
|
|
+import copy
|
|
import datetime
|
|
import datetime
|
|
|
|
+import ioex.datetimeex
|
|
|
|
+import pytz
|
|
yaml = pytest.importorskip('yaml')
|
|
yaml = pytest.importorskip('yaml')
|
|
|
|
|
|
-@pytest.mark.parametrize(('period', 'yaml_string'), [
|
|
|
|
|
|
+@pytest.mark.parametrize(('loader'), [yaml.Loader, yaml.SafeLoader])
|
|
|
|
+@pytest.mark.parametrize(('expected_period', 'yaml_string'), [
|
|
[
|
|
[
|
|
ioex.datetimeex.Period(
|
|
ioex.datetimeex.Period(
|
|
start = datetime.datetime(2016, 7, 24, 12, 21, 0),
|
|
start = datetime.datetime(2016, 7, 24, 12, 21, 0),
|
|
@@ -31,16 +33,24 @@ yaml = pytest.importorskip('yaml')
|
|
[
|
|
[
|
|
ioex.datetimeex.Period(
|
|
ioex.datetimeex.Period(
|
|
start = datetime.datetime(2016, 7, 24, 12, 20, 0, microsecond = 25500),
|
|
start = datetime.datetime(2016, 7, 24, 12, 20, 0, microsecond = 25500),
|
|
- end = datetime.datetime(2016, 7, 24, 12, 21, 0, microsecond = 13, tzinfo = pytz.utc),
|
|
|
|
|
|
+ end = pytz.utc.localize(datetime.datetime(2016, 7, 24, 12, 21, 0, microsecond = 13)),
|
|
),
|
|
),
|
|
'!period\nstart: 2016-07-24T12:20:00.025500\nend: 2016-07-24T12:21:00.000013Z',
|
|
'!period\nstart: 2016-07-24T12:20:00.025500\nend: 2016-07-24T12:21:00.000013Z',
|
|
],
|
|
],
|
|
|
|
+ [
|
|
|
|
+ ioex.datetimeex.Period(
|
|
|
|
+ start = pytz.timezone('Europe/London').localize(datetime.datetime(2016, 1, 24, 12, 20, 0, microsecond = 25500)),
|
|
|
|
+ end = pytz.timezone('Europe/London').localize(datetime.datetime(2016, 7, 24, 12, 21, 0, microsecond = 13)),
|
|
|
|
+ ),
|
|
|
|
+ '!period\nstart: 2016-01-24T12:20:00.025500Z\nend: 2016-07-24T12:21:00.000013+01:00',
|
|
|
|
+ ],
|
|
])
|
|
])
|
|
-def test_from_yaml(period, yaml_string):
|
|
|
|
- if period.start.tzinfo or period.end.tzinfo:
|
|
|
|
- pytest.xfail('pyyaml ignores timezones when loading timestamps')
|
|
|
|
- assert period == yaml.load(yaml_string)
|
|
|
|
- assert period == yaml.safe_load(yaml_string)
|
|
|
|
|
|
+def test_from_yaml(expected_period, yaml_string, loader):
|
|
|
|
+ loader_copy = copy.deepcopy(loader)
|
|
|
|
+ loaded_period = yaml.load(yaml_string, Loader = loader_copy)
|
|
|
|
+ assert expected_period == loaded_period
|
|
|
|
+ assert expected_period.start.utcoffset() == loaded_period.start.utcoffset()
|
|
|
|
+ assert expected_period.end.utcoffset() == loaded_period.end.utcoffset()
|
|
|
|
|
|
@pytest.mark.parametrize(('period', 'yaml_string'), [
|
|
@pytest.mark.parametrize(('period', 'yaml_string'), [
|
|
[
|
|
[
|