Browse Source

Transportation.arrival_time: accept datetimeex periods

Fabian Peter Hammerle 7 years ago
parent
commit
b62fc3caf2
3 changed files with 53 additions and 8 deletions
  1. 2 1
      finoex/__init__.py
  2. 1 1
      setup.py
  3. 50 6
      tests/test_yaml.py

+ 2 - 1
finoex/__init__.py

@@ -469,7 +469,8 @@ class Transportation(Item):
                  ):
         super(Transportation, self).__init__(**kwargs)
         if arrival_time is not None:
-            assert isinstance(arrival_time, datetime.datetime)
+            assert isinstance(arrival_time, datetime.datetime) \
+                    or isinstance(arrival_time, ioex.datetimeex.Period)
             self.arrival_time = arrival_time
         if departure_point is not None:
             assert type(departure_point) is str

+ 1 - 1
setup.py

@@ -4,7 +4,7 @@ import glob
 
 setup(
     name = 'finoex',
-    version = '0.11.1',
+    version = '0.11.2',
     # description = '',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',

+ 50 - 6
tests/test_yaml.py

@@ -151,7 +151,15 @@ def get_article():
         )
 
 
-def get_transportation():
+def get_transportation(period=False):
+    arrival_time = pytz.timezone('Europe/Vienna').localize(
+        datetime.datetime(2016, 7, 24, 23, 47, 35)
+    )
+    if period:
+        arrival_time = ioex.datetimeex.Period(
+            start=arrival_time,
+            end=arrival_time + datetime.timedelta(days=2),
+        )
     return finoex.Transportation(
         name = u'ticket',
         price_brutto = get_sum_a(),
@@ -166,9 +174,7 @@ def get_transportation():
             start = pytz.timezone('Europe/Vienna').localize(datetime.datetime(2016, 7, 24, 23, 47, 2)),
             end = pytz.utc.localize(datetime.datetime(2016, 7, 24, 23, 48, 5)),
             ),
-        arrival_time = pytz.timezone('Europe/Vienna').localize(
-            datetime.datetime(2016, 7, 24, 23, 47, 35)
-        ),
+        arrival_time=arrival_time,
     )
 
 
@@ -429,7 +435,7 @@ shipper: shipper
 state: goood
 width: !distance '1.23 m'
 """],
-    [get_transportation(), u"""!transportation
+    [get_transportation(period=False), u"""!transportation
 arrival_time: 2016-07-24 23:47:35+02:00
 departure_point: home
 destination_point: city
@@ -445,6 +451,25 @@ price_brutto: !sum '1.23 EUR'
 ticket_url: https://www.example.com
 valid_from: 2016-07-14 13:50:04+01:05
 valid_until: 2016-07-14 18:50:04+00:00
+"""],
+    [get_transportation(period=True), u"""!transportation
+arrival_time: !period
+  end: 2016-07-26 23:47:35+02:00
+  start: 2016-07-24 23:47:35+02:00
+departure_point: home
+destination_point: city
+distance: !distance '3.21 km'
+estimated_arrival_time: !period
+  end: 2016-07-24 23:48:05+00:00
+  start: 2016-07-24 23:47:02+02:00
+name: ticket
+passenger: !person
+  first_name: Fabian Peter
+  last_name: Hammerle
+price_brutto: !sum '1.23 EUR'
+ticket_url: https://www.example.com
+valid_from: 2016-07-14 13:50:04+01:05
+valid_until: 2016-07-14 18:50:04+00:00
 """],
     [get_shipping(), u"""!shipping
 destination_point: home
@@ -581,7 +606,7 @@ reward: product
 - !person
   first_name: 名字
   last_name: 贵姓"""],
-    [get_transportation(), u"""!transportation
+    [get_transportation(period=False), u"""!transportation
 arrival_time: 2016-07-24 23:47:35+02:00
 departure_point: home
 destination_point: city
@@ -598,6 +623,25 @@ valid_until: 2016-07-14 18:50:04+00:00
 estimated_arrival_time: !period
   end: 2016-07-24T23:48:05+00:00
   start: 2016-07-24T23:47:02+02:00
+"""],
+    [get_transportation(period=True), u"""!transportation
+arrival_time: !period
+  end: 2016-07-26 23:47:35+02:00
+  start: 2016-07-24 23:47:35+02:00
+departure_point: home
+destination_point: city
+distance: !distance '3.21 km'
+estimated_arrival_time: !period
+  end: 2016-07-24 23:48:05+00:00
+  start: 2016-07-24 23:47:02+02:00
+name: ticket
+passenger: !person
+  first_name: Fabian Peter
+  last_name: Hammerle
+price_brutto: !sum '1.23 EUR'
+ticket_url: https://www.example.com
+valid_from: 2016-07-14 13:50:04+01:05
+valid_until: 2016-07-14 18:50:04+00:00
 """],
     [get_shipping(), u"""!shipping
 destination_point: home