Esempio n. 1
0
 def test_valid_datestring_parse(self):
     """If we pass in a date in a standard form, it should get parsed"""
     answer = self.datetime_utc
     in_dates = ("2018 Mar 27 16:00:00 UTC", "2018-03-27 16:00:00 UTC",
                 "Tue Mar 27 16:00:00 UTC 2018")
     for in_date in in_dates:
         self.assertEqual(TimeUtils.parse_datetime(in_date, utc=True),
                          answer)
 def test_valid_datestring_parse(self):
     """If we pass in a date in a standard form, it should get parsed"""
     answer = self.datetime_utc
     in_dates = ("2018 Mar 27 16:00:00 UTC",
                 "2018-03-27 16:00:00 UTC", 
                 "Tue Mar 27 16:00:00 UTC 2018")
     for in_date in in_dates:
         self.assertEqual(TimeUtils.parse_datetime(
             in_date, utc=True), answer)
    def test_units(self):
        """If we specify a valid unit, the correct conversion
        should take place"""
        answer = self.datetime_time.replace(
            tzinfo=tz.tzlocal()).astimezone(tz=tz.tzutc())
        conversions = {'second': 1, 'millisecond': 1e3, 'microsecond': 1e6}
        units_inputs = {}

        for unit, factor in conversions.iteritems():
            units_inputs[unit] = self.epoch_time * factor

        for unit_name, value in units_inputs.iteritems():
            self.assertEqual(TimeUtils.epoch_to_datetime(value, unit=unit_name), answer)
Esempio n. 4
0
    def test_units(self):
        """If we specify a valid unit, the correct conversion
        should take place"""
        answer = self.datetime_time.replace(tzinfo=tz.tzlocal()).astimezone(
            tz=tz.tzutc())
        conversions = {'second': 1, 'millisecond': 1e3, 'microsecond': 1e6}
        units_inputs = {}

        for unit, factor in conversions.iteritems():
            units_inputs[unit] = self.epoch_time * factor

        for unit_name, value in units_inputs.iteritems():
            self.assertEqual(
                TimeUtils.epoch_to_datetime(value, unit=unit_name), answer)
def main():
    args = ReportUtils.get_report_parser().parse_args()
    logfile_fname = args.logfile if args.logfile is not None else LOGFILE

    if args.end is not None:
        try:
            assert [d.date() for d in
                monthrange(TimeUtils.parse_datetime(args.start))] ==\
                [d.date() for d in
                monthrange(TimeUtils.parse_datetime(args.end))]
        except AssertionError:
            raise ValueError("Currently, the OSG Per Site Reporter only supports running over"\
                " a month time range (e.g. 2017-03-01 to 2017-03-31).  Please"\
                " either specify -s <start> -e <end> with both <start> and <end>"\
                " within the same month, or only specify a start time with the -s"\
                " flag.")

    start, end = monthrange(TimeUtils.parse_datetime(args.start))

    try:
        osgreport = OSGPerSiteReporter(config_file=args.config,
                                       start=start,
                                       end=end,
                                       template=args.template,
                                       verbose=args.verbose,
                                       is_test=args.is_test,
                                       no_email=args.no_email,
                                       logfile=logfile_fname)

        osgreport.run_report()
        print 'OSG Per Site Report Execution finished'
        sys.exit(0)
    except Exception as e:
        ReportUtils.runerror(args.config, e, traceback.format_exc(),
                             logfile_fname)
        sys.exit(1)
Esempio n. 6
0
 def test_control_epoch(self):
     """If we pass in self.epoch_time, we should get self.datetime_time"""
     answer = self.datetime_time.replace(tzinfo=tz.tzlocal()).astimezone(
         tz=tz.tzutc())
     self.assertEqual(TimeUtils.epoch_to_datetime(self.epoch_time), answer)
 def test_none(self):
     """If we pass in None, we should get None back"""
     self.assertIsNone(TimeUtils.parse_datetime(None))
Esempio n. 8
0
 def test_return_none(self):
     """If we pass in None, we should get back None"""
     self.assertIsNone(TimeUtils.epoch_to_datetime(None))
Esempio n. 9
0
 def test_local_time_control(self):
     """Take our local time, transform it to UTC"""
     answer = self.datetime_local.replace(tzinfo=tz.tzlocal()).astimezone(
         tz.tzutc())
     self.assertEqual(TimeUtils.parse_datetime(self.datetime_local), answer)
Esempio n. 10
0
 def test_date_parse(self):
     """Parse a datetime.date object into a datetime.datetime object"""
     answer = datetime(2018, 3, 27, 00, 00,
                       00).replace(tzinfo=tz.tzlocal()).astimezone(
                           tz.tzutc())
     self.assertEqual(TimeUtils.parse_datetime(self.date_local), answer)
Esempio n. 11
0
 def test_none(self):
     """If we pass in None, we should get None back"""
     self.assertIsNone(TimeUtils.parse_datetime(None))
Esempio n. 12
0
 def test_utc_time_control(self):
     """This should just return itself"""
     answer = self.datetime_utc
     self.assertEqual(TimeUtils.parse_datetime(self.datetime_utc, utc=True),
                      answer)
 def test_control_epoch_range(self):
     """Return epoch time range in ms for valid input range"""
     answer = (1522166929000, 1522253329000)
     self.assertTupleEqual(TimeUtils.get_epoch_time_range_utc_ms(self.start, self.end), answer)
Esempio n. 14
0
 def test_control_epoch_range(self):
     """Return epoch time range in ms for valid input range"""
     answer = (1522166929000, 1522253329000)
     self.assertTupleEqual(
         TimeUtils.get_epoch_time_range_utc_ms(self.start, self.end),
         answer)
 def test_control_epoch(self):
     """If we pass in self.epoch_time, we should get self.datetime_time"""
     answer = self.datetime_time.replace(
         tzinfo=tz.tzlocal()).astimezone(tz=tz.tzutc())
     self.assertEqual(TimeUtils.epoch_to_datetime(self.epoch_time), answer)
 def test_return_none(self):
     """If we pass in None, we should get back None"""
     self.assertIsNone(TimeUtils.epoch_to_datetime(None))
 def test_utc_time_control(self):
     """This should just return itself"""
     answer = self.datetime_utc
     self.assertEqual(TimeUtils.parse_datetime(self.datetime_utc, utc=True), 
         answer)
 def test_date_parse(self): 
     """Parse a datetime.date object into a datetime.datetime object"""
     answer = datetime(2018, 3, 27, 00, 00, 00).replace(
         tzinfo=tz.tzlocal()).astimezone(tz.tzutc())
     self.assertEqual(TimeUtils.parse_datetime(self.date_local), answer)
 def test_local_time_control(self):
     """Take our local time, transform it to UTC"""
     answer = self.datetime_local.replace(tzinfo=tz.tzlocal()).astimezone(
         tz.tzutc())
     self.assertEqual(TimeUtils.parse_datetime(self.datetime_local), answer)