def setUp(self):
     NagiosLogger.reset()
     self.mock_status = self.patch_object(NagiosLogger, 'status',
                                          autospec=True)
     self.mock_status.add_error.return_value = sentinel.with_error
     self.mock_status.add_warning.return_value = sentinel.with_warning
     self.mock_status.add_important.return_value = sentinel.with_important
 def setUp(self):
     NagiosLogger.reset()
     self.mock_status = self.patch_object(NagiosLogger,
                                          'status',
                                          autospec=True)
     self.mock_status.add_error.return_value = sentinel.with_error
     self.mock_status.add_warning.return_value = sentinel.with_warning
     self.mock_status.add_important.return_value = sentinel.with_important
 def test_exits_unknown(self):
     err = _guarded_run(lambda: NagiosLogger.unknown_stop('reason'))
     self.assertEqual(err.code, 3)
 def test_exits_critical(self):
     err = _guarded_run(lambda: NagiosLogger.error('An error'))
     self.assertEqual(err.code, 2)
 def test_exits_warning(self):
     err = _guarded_run(lambda: NagiosLogger.warning('A warning'))
     self.assertEqual(err.code, 1)
def _guarded_run(func=lambda: None, **kwargs):
    try:
        NagiosLogger.run(func, **kwargs)
    except SystemExit as err:
        return err
def _guarded_run(func=lambda: None, **kwargs):
    try:
        NagiosLogger.run(func, **kwargs)
    except SystemExit as err:
        return err
    def test_warn(self):
        NagiosLogger.warn(sentinel.message)

        self.mock_status.add_warning.assert_called_once_with(
            sentinel.message)
        self.assertEqual(NagiosLogger.status, sentinel.with_warning)
    def test_crit(self):
        NagiosLogger.crit(sentinel.message)

        self.mock_status.add_error.assert_called_once_with(sentinel.message)
        self.assertEqual(NagiosLogger.status, sentinel.with_error)
 def run():
     NagiosLogger.important("important\n")
     for x in xrange(10):
         print()
 def test_unknown_stop_reaches_stdout(self):
     _guarded_run(lambda: NagiosLogger.unknown_stop('<stop_reason>'))
     self.assertIn('<stop_reason>', self.stdout.getvalue())
 def test_exits_unknown(self):
     err = _guarded_run(lambda: NagiosLogger.unknown_stop('reason'))
     self.assertEqual(err.code, 3)
 def test_exits_critical(self):
     err = _guarded_run(lambda: NagiosLogger.error('An error'))
     self.assertEqual(err.code, 2)
 def test_exits_warning(self):
     err = _guarded_run(lambda: NagiosLogger.warning('A warning'))
     self.assertEqual(err.code, 1)
 def run():
     NagiosLogger.important("important\n")
     for x in xrange(10):
         print()
    def test_warn(self):
        NagiosLogger.warn(sentinel.message)

        self.mock_status.add_warning.assert_called_once_with(sentinel.message)
        self.assertEqual(NagiosLogger.status, sentinel.with_warning)
 def test_unknown_stop_reaches_stdout(self):
     _guarded_run(lambda: NagiosLogger.unknown_stop('<stop_reason>'))
     self.assertIn('<stop_reason>', self.stdout.getvalue())
    def test_info(self):
        NagiosLogger.info(sentinel.message)

        self.mock_status.add_important.assert_called_once_with(
            sentinel.message)
        self.assertEqual(NagiosLogger.status, sentinel.with_important)
    def test_crit(self):
        NagiosLogger.crit(sentinel.message)

        self.mock_status.add_error.assert_called_once_with(
            sentinel.message)
        self.assertEqual(NagiosLogger.status, sentinel.with_error)
 def test_status_is_reset(self):
     NagiosLogger.reset()
     self.assertEqual(NagiosLogger.status, sentinel.initial)
     self.mock_initial.assert_called_once_with()
    def test_info(self):
        NagiosLogger.info(sentinel.message)

        self.mock_status.add_important.assert_called_once_with(
            sentinel.message)
        self.assertEqual(NagiosLogger.status, sentinel.with_important)
 def test_status_is_reset(self):
     NagiosLogger.reset()
     self.assertEqual(NagiosLogger.status, sentinel.initial)
     self.mock_initial.assert_called_once_with()