Exemple #1
0
 def test_duration_to_relativedelta_months(self):
     delta = duration_to_relativedelta("7M")
     self.assertEqual(delta, relativedelta(months=7))
     delta = duration_to_relativedelta("1 month")
     self.assertEqual(delta, relativedelta(months=1))
     delta = duration_to_relativedelta("7 months")
     self.assertEqual(delta, relativedelta(months=7))
Exemple #2
0
 def test_duration_to_relativedelta_hours(self):
     delta = duration_to_relativedelta("7h")
     self.assertEqual(delta, relativedelta(hours=7))
     delta = duration_to_relativedelta("1 hour")
     self.assertEqual(delta, relativedelta(hours=1))
     delta = duration_to_relativedelta("7 hours")
     self.assertEqual(delta, relativedelta(hours=7))
Exemple #3
0
 def test_duration_to_relativedelta_days(self):
     delta = duration_to_relativedelta("7D")
     self.assertEqual(delta, relativedelta(days=7))
     delta = duration_to_relativedelta("1 day")
     self.assertEqual(delta, relativedelta(days=1))
     delta = duration_to_relativedelta("7 days")
     self.assertEqual(delta, relativedelta(days=7))
Exemple #4
0
 def test_duration_to_relativedelta_minutes(self):
     delta = duration_to_relativedelta("7m")
     self.assertEqual(delta, relativedelta(minutes=7))
     delta = duration_to_relativedelta("1 minute")
     self.assertEqual(delta, relativedelta(minutes=1))
     delta = duration_to_relativedelta("7 minutes")
     self.assertEqual(delta, relativedelta(minutes=7))
Exemple #5
0
 def test_duration_to_relativedelta_seconds(self):
     delta = duration_to_relativedelta("7s")
     self.assertEqual(delta, relativedelta(seconds=7))
     delta = duration_to_relativedelta("1 second")
     self.assertEqual(delta, relativedelta(seconds=1))
     delta = duration_to_relativedelta("7 seconds")
     self.assertEqual(delta, relativedelta(seconds=7))
Exemple #6
0
 def test_duration_to_relativedelta_years(self):
     delta = duration_to_relativedelta("7Y")
     self.assertEqual(delta, relativedelta(years=7))
     delta = duration_to_relativedelta("7Y")
     self.assertEqual(delta, relativedelta(years=7))
     delta = duration_to_relativedelta("1 year")
     self.assertEqual(delta, relativedelta(years=1))
     delta = duration_to_relativedelta("7 years")
     self.assertEqual(delta, relativedelta(years=7))
Exemple #7
0
 def test_TimeSeriesFixedResolution_to_database(self):
     values = numpy.array([3, 2, 4], dtype=float)
     resolution = [duration_to_relativedelta("1 months")]
     start = datetime(year=2007, month=6, day=1)
     value = TimeSeriesFixedResolution(start, resolution, values, True,
                                       True)
     as_json = value.to_database()
     releases = json.loads(as_json)
     self.assertEqual(
         releases,
         {
             "type": "time_series",
             "index": {
                 "start": "2007-06-01 00:00:00",
                 "resolution": "1M",
                 "ignore_year": True,
                 "repeat": True,
             },
             "data": [3, 2, 4],
         },
     )
Exemple #8
0
 def test_TimeSeriesFixedResolution_resolution_list_to_database(self):
     start = datetime(year=2007, month=1, day=1)
     resolutions = ["1 month", "1 year"]
     resolutions = [duration_to_relativedelta(r) for r in resolutions]
     values = numpy.array([3.0, 2.0, 4.0])
     value = TimeSeriesFixedResolution(start, resolutions, values, True,
                                       True)
     as_json = value.to_database()
     releases = json.loads(as_json)
     self.assertEqual(
         releases,
         {
             "type": "time_series",
             "index": {
                 "start": "2007-01-01 00:00:00",
                 "resolution": ["1M", "1Y"],
                 "ignore_year": True,
                 "repeat": True,
             },
             "data": [3.0, 2.0, 4.0],
         },
     )
Exemple #9
0
 def test_Duration_to_database(self):
     value = Duration(duration_to_relativedelta("8 years"))
     database_value = value.to_database()
     value_as_dict = json.loads(database_value)
     self.assertEqual(value_as_dict, {"type": "duration", "data": "8Y"})