/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-03 13:19:47 UTC
  • Revision ID: teddy@recompile.se-20190303131947-s7pwice2hi8l2hyv
mandos-ctl: Improve a test when running Python older than 3.4.

* mandos-ctl
  (Test_string_to_delta.test_falls_back_to_pre_1_6_1_with_warning):
  When assertLogs() is not present, implement alternative.

Show diffs side-by-side

added added

removed removed

Lines of Context:
742
742
            with self.assertLogs(log, logging.WARNING):
743
743
                value = string_to_delta("2h")
744
744
        else:
745
 
            value = string_to_delta("2h")
 
745
            class WarningFilter(logging.Filter):
 
746
                """Don't show, but record the presence of, warnings"""
 
747
                def filter(self, record):
 
748
                    is_warning = record.levelno >= logging.WARNING
 
749
                    self.found = is_warning or getattr(self, "found",
 
750
                                                       False)
 
751
                    return not is_warning
 
752
            warning_filter = WarningFilter()
 
753
            log.addFilter(warning_filter)
 
754
            try:
 
755
                value = string_to_delta("2h")
 
756
            finally:
 
757
                log.removeFilter(warning_filter)
 
758
            self.assertTrue(getattr(warning_filter, "found", False))
746
759
        self.assertEqual(value, datetime.timedelta(0, 7200))
747
760
 
748
761
class Test_TableOfClients(unittest.TestCase):