Home | History | Annotate | Download | only in bin
      1 """Tests for base_sysinfo."""
      2 
      3 import mock
      4 import unittest
      5 
      6 import common
      7 from autotest_lib.client.common_lib import autotemp
      8 from autotest_lib.client.bin import base_sysinfo
      9 
     10 
     11 class LoggableTestException(Exception):
     12     """An exception thrown by the loggable used for testing."""
     13 
     14 
     15 class BaseSysinfoTestCase(unittest.TestCase):
     16     """TestCase for free functions in the base_sysinfo module."""
     17 
     18     def setUp(self):
     19         self._output_dir = autotemp.tempdir()
     20         self.addCleanup(self._output_dir.clean)
     21 
     22     def test_run_loggables_with_no_exception(self):
     23         """Tests _run_loggables_ignoring_errors when no loggable throws"""
     24         loggables = {
     25                 mock.create_autospec(base_sysinfo.loggable),
     26                 mock.create_autospec(base_sysinfo.loggable),
     27         }
     28         base_sysinfo._run_loggables_ignoring_errors(loggables, self._output_dir)
     29         for log in loggables:
     30             log.run.assert_called_once_with(self._output_dir)
     31 
     32     def test_run_loggables_with_exception(self):
     33         """Tests _run_loggables_ignoring_errors when one loggable throws"""
     34         failing_loggable = mock.create_autospec(base_sysinfo.loggable)
     35         failing_loggable.run.side_effect = LoggableTestException
     36         loggables = {
     37                 mock.create_autospec(base_sysinfo.loggable),
     38                 failing_loggable,
     39                 mock.create_autospec(base_sysinfo.loggable),
     40         }
     41         base_sysinfo._run_loggables_ignoring_errors(loggables, self._output_dir)
     42         for log in loggables:
     43             log.run.assert_called_once_with(self._output_dir)
     44 
     45 
     46 if __name__ == '__main__':
     47     unittest.main()
     48