Mike Frysinger | d03e6b5 | 2019-08-03 12:49:01 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2 |
Allen Li | e0bb760 | 2016-11-29 13:45:53 -0800 | [diff] [blame] | 2 | |
| 3 | import sys |
| 4 | import unittest |
| 5 | |
| 6 | from cStringIO import StringIO |
| 7 | |
| 8 | import common |
| 9 | from autotest_lib.tko import db |
| 10 | |
| 11 | |
| 12 | class 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 | |
| 30 | class 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 | |
| 39 | if __name__ == "__main__": |
| 40 | unittest.main() |