def test16max_time_jump_seconds_exceeded(self):
     """
     Test if the start_year is not updated, when the next date exceeds the max_time_jump_seconds.
     A time inconsistency warning must occur.
     """
     log_stream = StringIO()
     logging.basicConfig(stream=log_stream, level=logging.INFO)
     max_time_jump_seconds = 86400
     start_year = 2020
     match_context = DummyMatchContext(b"31.12 23:59:00: it still works")
     date_time_model_element = DateTimeModelElement(
         "path",
         b"%d.%m %H:%M:%S",
         timezone.utc,
         start_year=start_year,
         max_time_jump_seconds=max_time_jump_seconds)
     self.assertEqual(
         date_time_model_element.get_match_element(
             "match1", match_context).get_match_object(), 1609459140)
     self.assertEqual(match_context.match_string, b"31.12 23:59:00")
     self.assertEqual(date_time_model_element.start_year, 2020)
     match_context = DummyMatchContext(b"01.01 23:59:01: it still works")
     self.assertEqual(
         date_time_model_element.get_match_element(
             "match1", match_context).get_match_object(), 1577923141)
     self.assertEqual(match_context.match_string, b"01.01 23:59:01")
     self.assertEqual(date_time_model_element.start_year, 2020)
     self.assertIn(
         "WARNING:DEBUG:DateTimeModelElement time inconsistencies parsing b'01.01 23:59:01', expecting value around "
         "1609459140. Check your settings!", log_stream.getvalue())
     for handler in logging.root.handlers[:]:
         logging.root.removeHandler(handler)
     initialize_loggers(self.aminer_config,
                        getpwnam("aminer").pw_uid,
                        getgrnam("aminer").gr_gid)
Пример #2
0
    def test15max_time_jump_seconds_in_time(self):
        """
        Test if the max_time_jump_seconds parameter works if the next date is in time.
        Warnings with unqualified timestamp year wraparound.
        """
        log_stream = StringIO()
        logging.basicConfig(stream=log_stream, level=logging.INFO)
        max_time_jump_seconds = 86400
        start_year = 2020
        match_context = DummyMatchContext(b"31.12 23:59:00: it still works")
        multi_locale_dtme = MultiLocaleDateTimeModelElement("path", [(b"%d.%m %H:%M:%S", None, None)], start_year=start_year,
                                                            max_time_jump_seconds=max_time_jump_seconds)
        self.assertEqual(multi_locale_dtme.get_match_element("match1", match_context).get_match_object(), 1609459140)
        self.assertEqual(match_context.match_string, b"31.12 23:59:00")
        self.assertEqual(multi_locale_dtme.start_year, 2020)

        match_context = DummyMatchContext(b"01.01 23:59:00: it still works")
        self.assertEqual(multi_locale_dtme.get_match_element("match1", match_context).get_match_object(), 1609545540)
        self.assertEqual(match_context.match_string, b"01.01 23:59:00")
        self.assertEqual(multi_locale_dtme.start_year, 2021)
        self.assertIn("WARNING:DEBUG:DateTimeModelElement unqualified timestamp year wraparound detected from 2021-01-01T23:59:00+00:00 to "
                      "2021-01-01T23:59:00+00:00", log_stream.getvalue())
        for handler in logging.root.handlers[:]:
            logging.root.removeHandler(handler)
        initialize_loggers(self.aminer_config, getpwnam("aminer").pw_uid, getgrnam("aminer").gr_gid)
    def test15max_time_jump_seconds_in_time(self):
        """
        Test if the max_time_jump_seconds parameter works if the next date is in time.
        Warnings with unqualified timestamp year wraparound.
        """
        log_stream = StringIO()
        logging.basicConfig(stream=log_stream, level=logging.INFO)
        max_time_jump_seconds = 86400
        start_year = 2020
        date_time_model_element = DateTimeModelElement(
            self.id_,
            b"%d.%m %H:%M:%S",
            timezone.utc,
            start_year=start_year,
            max_time_jump_seconds=max_time_jump_seconds)
        data = b"31.12 23:59:00: it still works"
        date = b"31.12 23:59:00"
        match_context = DummyMatchContext(data)
        match_element = date_time_model_element.get_match_element(
            self.path, match_context)
        self.compare_match_results(data, match_element, match_context,
                                   self.id_, self.path, date, 1609459140, None)
        self.assertEqual(date_time_model_element.start_year, start_year)

        data = b"01.01 23:59:00: it still works"
        date = b"01.01 23:59:00"
        match_context = DummyMatchContext(data)
        match_element = date_time_model_element.get_match_element(
            self.path, match_context)
        self.compare_match_results(data, match_element, match_context,
                                   self.id_, self.path, date, 1609545540, None)
        self.assertEqual(date_time_model_element.start_year, start_year + 1)
        self.assertIn(
            "WARNING:DEBUG:DateTimeModelElement unqualified timestamp year wraparound detected from 2021-01-01T23:59:00+00:00 to "
            "2021-01-01T23:59:00+00:00", log_stream.getvalue())
        for handler in logging.root.handlers[:]:
            logging.root.removeHandler(handler)
        initialize_loggers(self.aminer_config,
                           getpwnam("aminer").pw_uid,
                           getgrnam("aminer").gr_gid)
    def test16max_time_jump_seconds_exceeded(self):
        """
        Test if the start_year is not updated, when the next date exceeds the max_time_jump_seconds.
        A time inconsistency warning must occur.
        """
        log_stream = StringIO()
        logging.basicConfig(stream=log_stream, level=logging.INFO)
        max_time_jump_seconds = 86400
        start_year = 2020
        multi_locale_dtme = MultiLocaleDateTimeModelElement(
            self.id_, [(b"%d.%m %H:%M:%S", None, None)],
            start_year=start_year,
            max_time_jump_seconds=max_time_jump_seconds)
        data = b"31.12 23:59:00: it still works"
        date = b"31.12 23:59:00"
        match_context = DummyMatchContext(data)
        match_element = multi_locale_dtme.get_match_element(
            self.path, match_context)
        self.compare_match_results(data, match_element, match_context,
                                   self.id_ + "/format0", self.path, date,
                                   1609459140, None)
        self.assertEqual(multi_locale_dtme.start_year, start_year)

        data = b"01.01 23:59:01: it still works"
        date = b"01.01 23:59:01"
        match_context = DummyMatchContext(data)
        match_element = multi_locale_dtme.get_match_element(
            self.path, match_context)
        self.compare_match_results(data, match_element, match_context,
                                   self.id_ + "/format0", self.path, date,
                                   1577923141, None)
        self.assertEqual(multi_locale_dtme.start_year, start_year)
        self.assertIn(
            "WARNING:DEBUG:DateTimeModelElement time inconsistencies parsing b'01.01 23:59:01', expecting value around "
            "1609459140. Check your settings!", log_stream.getvalue())
        for handler in logging.root.handlers[:]:
            logging.root.removeHandler(handler)
        initialize_loggers(self.aminer_config,
                           getpwnam("aminer").pw_uid,
                           getgrnam("aminer").gr_gid)