Skip to content
Snippets Groups Projects
Select Git revision
  • c0adadf70095e5336ea1134c91747953d10ab079
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

sec_struct.cc

Blame
  • test_log.py 1.45 KiB
    import unittest
    import ost
    
    # Altough the logging system might appear to be too simple to be worth writing a 
    # specific test case for, it actually isn't. The python export is very fragile 
    # and seemingly trivial changes can break the code in unexpected ways. So let's 
    # check for some invariants
    class TestLog(unittest.TestCase):
      def testGetLogSink(self):
        logsink=ost.GetCurrentLogSink()
        self.assertTrue(hasattr(logsink, 'LogMessage'))
        # Check if the return type of logsink is sane
        ost.PushLogSink(ost.GetCurrentLogSink())
      def testPushPopLogSink(self):
        class MyLogSink(ost.LogSink):
           def __init__(self):
             ost.LogSink.__init__(self)
        ls=MyLogSink()
        ost.PushLogSink(ls)
        self.assertEqual(ls, ost.GetCurrentLogSink())
        ost.PopLogSink()
        self.assertNotEqual(ls, ost.GetCurrentLogSink())
    
      def testLogMessage(self):
        class CapturingLogSink(ost.LogSink):
          def __init__(self):
            ost.LogSink.__init__(self)
          def LogMessage(self, message, severity):
            self.message=message
            self.severity=severity
            ost.PushLogSink(ls)
        ls=CapturingLogSink()
        ost.PushLogSink(ls)
        ost.LogError('error message')
        self.assertEqual(ls.message, 'error message\n')
        self.assertEqual(ls.severity, 0)
        ost.LogWarning(1, 2, 3)
        self.assertEqual(ls.message, '1 2 3\n')
        self.assertEqual(ls.severity, 1)
        ost.PopLogSink()
    if __name__ == "__main__":
      from ost import testutils
      testutils.RunTests()