blob: deda51dd789b169f59db348a0863cbf43a5485e9 [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/python2
Allen Lie0bb7602016-11-29 13:45:53 -08002
3import sys
4import unittest
5
6from cStringIO import StringIO
7
8import common
9from autotest_lib.tko import db
10
11
12class LogErrorTestCase(unittest.TestCase):
13 """Tests for _log_error()."""
14
15 def setUp(self):
16 self._old_stderr = sys.stderr
17 sys.stderr = self.stderr = StringIO()
18
19
20 def tearDown(self):
21 sys.stderr = self._old_stderr
22
23
24 def test_log_error(self):
25 """Test _log_error()."""
26 db._log_error('error message')
27 self.assertEqual(self.stderr.getvalue(), 'error message\n')
28
29
30class FormatOperationalErrorTestCase(unittest.TestCase):
31 """Tests for _format_operational_error()."""
32
33 def test_format_operational_error(self):
34 """Test _format_operational_error()."""
35 got = db._format_operational_error(Exception())
36 self.assertIn('An operational error occurred', got)
37
38
39if __name__ == "__main__":
40 unittest.main()