Exemple #1
0
    def test_past_log_expired(self):
        """Ensures an old log is expired."""

        logger = BeaconLogger(logfolder, "test past log expired")

        # possible past times (past by a day and hr, just a day, just an hr)
        past = logger._log_datetime
        present = datetime.now()
        past_hr = present - timedelta(hours=1)
        past_day = present - timedelta(days=1)

        logger._log_datetime = past
        self.assertEqual(logger._log_expired(present.date(), present.hour), True)
        logger._log_datetime = past_hr
        self.assertEqual(logger._log_expired(present.date(), present.hour), True)
        logger._log_datetime = past_day
        self.assertEqual(logger._log_expired(present.date(), present.hour), True)
Exemple #2
0
    def test_present_log_expired(self):
        """Ensures a log from the present is not expired."""

        logger = BeaconLogger(logfolder, 'test if present log expired')
        present = datetime.now()

        logger._log_datetime = present
        self.assertEqual(logger._log_expired(present.date(), present.hour), False)
    def test_present_log_expired(self):
        """Ensures a log from the present is not expired."""

        logger = BeaconLogger(logfolder, 'test if present log expired')
        present = datetime.now()

        logger._log_datetime = present
        self.assertEqual(logger._log_expired(present.date(), present.hour),
                         False)
    def test_past_log_expired(self):
        """Ensures an old log is expired."""

        logger = BeaconLogger(logfolder, "test past log expired")

        # possible past times (past by a day and hr, just a day, just an hr)
        past = logger._log_datetime
        present = datetime.now()
        past_hr = present - timedelta(hours=1)
        past_day = present - timedelta(days=1)

        logger._log_datetime = past
        self.assertEqual(logger._log_expired(present.date(), present.hour),
                         True)
        logger._log_datetime = past_hr
        self.assertEqual(logger._log_expired(present.date(), present.hour),
                         True)
        logger._log_datetime = past_day
        self.assertEqual(logger._log_expired(present.date(), present.hour),
                         True)
Exemple #5
0
    def test_assign_handler(self):
        """Ensures the correct file handler is assigned."""

        logger = BeaconLogger(logfolder, 'test assign handler')

        # Calculate expected handler path
        now = datetime.now()
        log_path = logfolder + '/' + str(now.date()) + '/' + str(now.hour) + '.txt'
        expected_path = os.getcwd() + '/' + log_path

        # Execute method
        logger._assign_handler(now.date(), now.hour)

        self.assertEqual(logger._log.handlers[0].baseFilename, expected_path)

        # check if we can remove and add a filehandler  
        logger._log_datetime = logger._log_datetime - timedelta(hours=2)
        logger._assign_handler(now.date(), now.hour)

        self.assertEqual(len(logger._log.handlers), 1)
        self.assertEqual(logger._log.handlers[0].baseFilename, expected_path)
    def test_assign_handler(self):
        """Ensures the correct file handler is assigned."""

        logger = BeaconLogger(logfolder, 'test assign handler')

        # Calculate expected handler path
        now = datetime.now()
        log_path = logfolder + '/' + str(now.date()) + '/' + str(
            now.hour) + '.txt'
        expected_path = os.getcwd() + '/' + log_path

        # Execute method
        logger._assign_handler(now.date(), now.hour)

        self.assertEqual(logger._log.handlers[0].baseFilename, expected_path)

        # check if we can remove and add a filehandler
        logger._log_datetime = logger._log_datetime - timedelta(hours=2)
        logger._assign_handler(now.date(), now.hour)

        self.assertEqual(len(logger._log.handlers), 1)
        self.assertEqual(logger._log.handlers[0].baseFilename, expected_path)