Forráskód Böngészése

renamed class DatePeriod to Period

Fabian Peter Hammerle 9 éve
szülő
commit
247da28060
3 módosított fájl, 29 hozzáadás és 29 törlés
  1. 5 5
      ioex/__init__.py
  2. 17 17
      tests/test_period.py
  3. 7 7
      tests/test_period_yaml.py

+ 5 - 5
ioex/__init__.py

@@ -53,7 +53,7 @@ def int_input_with_default(prompt, default):
     else:
         return None
 
-class DatePeriod(object):
+class Period(object):
 
     yaml_tag = u'!period'
 
@@ -134,7 +134,7 @@ class DatePeriod(object):
             )
 
 if yaml:
-    yaml.add_representer(DatePeriod, DatePeriod.to_yaml)
-    yaml.SafeDumper.add_representer(DatePeriod, DatePeriod.to_yaml)
-    yaml.add_constructor(u'!period', DatePeriod.from_yaml)
-    yaml.SafeLoader.add_constructor(u'!period', DatePeriod.from_yaml)
+    yaml.add_representer(Period, Period.to_yaml)
+    yaml.SafeDumper.add_representer(Period, Period.to_yaml)
+    yaml.add_constructor(u'!period', Period.from_yaml)
+    yaml.SafeLoader.add_constructor(u'!period', Period.from_yaml)

+ 17 - 17
tests/test_dateperiod.py → tests/test_period.py

@@ -12,7 +12,7 @@ import datetime
     [None, None],
     ])
 def test_dateperiod_init_start_end(start, end):
-    p = ioex.DatePeriod(start = start, end = end)
+    p = ioex.Period(start = start, end = end)
     assert p.start == start
     assert p.end == end
 
@@ -22,7 +22,7 @@ def test_dateperiod_init_start_end(start, end):
     ])
 def test_dateperiod_init_start_end_fail(start, end):
     with pytest.raises(TypeError):
-        ioex.DatePeriod(start = start, end = end)
+        ioex.Period(start = start, end = end)
 
 @pytest.mark.parametrize(('start', 'end', 'iso'), [
     [
@@ -32,7 +32,7 @@ def test_dateperiod_init_start_end_fail(start, end):
         ],
     ])
 def test_dateperiod_init_isoformat(start, end, iso):
-    p = ioex.DatePeriod(isoformat = iso)
+    p = ioex.Period(isoformat = iso)
     assert p.start == start
     assert p.end == end
 
@@ -53,14 +53,14 @@ def test_dateperiod_init_isoformat(start, end, iso):
     ])
 def test_dateperiod_init_param_fail(params):
     with pytest.raises(StandardError):
-        ioex.DatePeriod(**params)
+        ioex.Period(**params)
 
 @pytest.mark.parametrize(('start'), [
     datetime.datetime(2016, 7, 24, 12, 21),
     None,
     ])
 def test_dateperiod_set_start(start):
-    p = ioex.DatePeriod()
+    p = ioex.Period()
     assert p.start is None
     p.start = start
     assert p.start == start
@@ -69,7 +69,7 @@ def test_dateperiod_set_start(start):
     ':-/',
     ])
 def test_dateperiod_set_start_fail(start):
-    p = ioex.DatePeriod()
+    p = ioex.Period()
     with pytest.raises(TypeError):
         p.start = start
 
@@ -78,7 +78,7 @@ def test_dateperiod_set_start_fail(start):
     None,
     ])
 def test_dateperiod_set_end(end):
-    p = ioex.DatePeriod()
+    p = ioex.Period()
     assert p.end is None
     p.end = end
     assert p.end == end
@@ -87,7 +87,7 @@ def test_dateperiod_set_end(end):
     ':-/',
     ])
 def test_dateperiod_set_end_fail(end):
-    p = ioex.DatePeriod()
+    p = ioex.Period()
     with pytest.raises(TypeError):
         p.end = end
 
@@ -119,7 +119,7 @@ def test_dateperiod_set_end_fail(end):
         ],
     ])
 def test_dateperiod_get_isoformat(start, end, iso):
-    p = ioex.DatePeriod(start = start, end = end)
+    p = ioex.Period(start = start, end = end)
     assert p.isoformat == iso
 
 @pytest.mark.parametrize(('start', 'end', 'iso'), [
@@ -155,7 +155,7 @@ def test_dateperiod_get_isoformat(start, end, iso):
         ],
     ])
 def test_dateperiod_set_isoformat(start, end, iso):
-    p = ioex.DatePeriod()
+    p = ioex.Period()
     p.isoformat = iso
     assert p.start == start
     assert p.end == end
@@ -164,37 +164,37 @@ def test_dateperiod_set_isoformat(start, end, iso):
     '2016-07-24T12:20:0<INVALID>0.0255/2016-07-24T12:21:00.13Z',
     ])
 def test_dateperiod_set_isoformat_fail(iso):
-    p = ioex.DatePeriod()
+    p = ioex.Period()
     with pytest.raises(ValueError):
         p.isoformat = iso
 
 @pytest.mark.parametrize(('a', 'b'), [
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 21, 0),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13),
             ),
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 21, 0, 0),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13, 0),
             ),
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = pytz.timezone('Europe/Vienna').localize(datetime.datetime(2016, 7, 24, 12, 21, 0)),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13),
             ),
-        ioex.DatePeriod(
+        ioex.Period(
             start = pytz.timezone('Europe/Vienna').localize(datetime.datetime(2016, 7, 24, 12, 21, 0)),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13),
             ),
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = pytz.timezone('Europe/Vienna').localize(datetime.datetime(2016, 7, 24, 12, 21, 0)),
             end = pytz.timezone('Europe/London').localize(datetime.datetime(2016, 7, 24, 12, 22, 13)),
             ),
-        ioex.DatePeriod(
+        ioex.Period(
             start = pytz.timezone('Europe/London').localize(datetime.datetime(2016, 7, 24, 11, 21, 0)),
             end = pytz.timezone('Europe/Vienna').localize(datetime.datetime(2016, 7, 24, 13, 22, 13)),
             ),

+ 7 - 7
tests/test_dateperiod_yaml.py → tests/test_period_yaml.py

@@ -8,28 +8,28 @@ yaml = pytest.importorskip('yaml')
 
 @pytest.mark.parametrize(('period', 'yaml_string'), [
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 21, 0),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13),
             ),
         '!period\nstart: 2016-07-24T12:21:00\nend: 2016-07-24T12:22:13',
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 21, 0),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13),
             ),
         '!period\nstart: 2016-07-24 12:21:00\nend: 2016-07-24 12:22:13',
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 20, 0, microsecond = 25500),
             end = datetime.datetime(2016, 7, 24, 12, 21, 0, microsecond = 13),
             ),
         '!period\nstart: 2016-07-24T12:20:00.025500\nend: 2016-07-24T12:21:00.000013',
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             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),
             ),
@@ -44,21 +44,21 @@ def test_dateperiod_from_yaml(period, yaml_string):
 
 @pytest.mark.parametrize(('period', 'yaml_string'), [
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 21, 0),
             end = datetime.datetime(2016, 7, 24, 12, 22, 13),
             ),
         '!period\nend: 2016-07-24 12:22:13\nstart: 2016-07-24 12:21:00\n',
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = datetime.datetime(2016, 7, 24, 12, 20, 0, microsecond = 25500),
             end = datetime.datetime(2016, 7, 24, 12, 21, 0, microsecond = 13),
             ),
         '!period\nend: 2016-07-24 12:21:00.000013\nstart: 2016-07-24 12:20:00.025500\n',
         ],
     [
-        ioex.DatePeriod(
+        ioex.Period(
             start = pytz.timezone('Europe/London').localize(datetime.datetime(2016, 7, 24, 12, 20, 0)),
             end = pytz.utc.localize(datetime.datetime(2016, 7, 24, 12, 21, 0, microsecond = 13)),
             ),