import unittest
import Monitors.monitor


class TestMonitor(unittest.TestCase):

    safe_config = {'partition': '/', 'limit': '10G'}

    one_KB = 1024
    one_MB = one_KB * 1024
    one_GB = one_MB * 1024
    one_TB = one_GB * 1024

    def test_MonitorInit(self):
        m = Monitors.monitor.Monitor(config_options={
            'depend': 'a, b',
            'urgent': 0,
            'tolerance': 2,
            'remote_alert': 1,
            'recover_command': 'true'
        })
        self.assertEqual(m.name, 'unnamed', 'Monitor did not set name')
        self.assertEqual(m.urgent, 0, 'Monitor did not set urgent')
        self.assertEqual(m.tolerance, 2, 'Monitor did not set tolerance')
        self.assertTrue(m.remote_alerting, 'Monitor did not set remote_alerting')
        self.assertEqual(m.recover_command, 'true', 'Monitor did not set recover_command')

    def test_MonitorSuccess(self):
        m = Monitors.monitor.Monitor()
        m.record_success('yay')
        self.assertEqual(m.get_error_count(), 0, 'Error count is not 0')
        self.assertEqual(m.get_success_count(), 1, 'Success count is not 1')
        self.assertEqual(m.tests_run, 1, 'Tests run is not 1')
        self.assertFalse(m.was_skipped, 'was_skipped is not false')
        self.assertEqual(m.last_result, 'yay', 'Last result is not correct')

    def test_MonitorFail(self):
        m = Monitors.monitor.Monitor()
        m.record_fail('boo')
        self.assertEqual(m.get_error_count(), 1, 'Error count is not 1')
        self.assertEqual(m.get_success_count(), 0, 'Success count is not 0')
        self.assertEqual(m.tests_run, 1, 'Tests run is not 1')
        self.assertFalse(m.was_skipped, 'was_skipped is not false')
        self.assertEqual(m.last_result, 'boo', 'Last result is not correct')

    def test_MonitorWindows(self):
        m = Monitors.monitor.Monitor()
        self.assertFalse(m.is_windows())

    def test_MonitorSkip(self):
        m = Monitors.monitor.Monitor()
        m.record_skip('a')
        self.assertEqual(m.get_success_count(), 1, 'Success count is not 1')
        self.assertTrue(m.was_skipped, 'was_skipped is not true')
        self.assertEqual(m.skip_dep, 'a', 'skip_dep is not correct')
        self.assertTrue(m.skipped(), 'skipped() is not true')


@@ -2274,12 +2274,1685 @@
 not true')%0A%0A
+    def test_MonitorConfig(self):%0A        config_options = %7B%0A            'test_string': 'a string',%0A            'test_int': '3',%0A            'test_%5Bint%5D': '1,2, 3',%0A            'test_%5Bstr%5D': 'a, b,c',%0A            'test_bool1': '1',%0A            'test_bool2': 'yes',%0A            'test_bool3': 'true',%0A            'test_bool4': '0'%0A        %7D%0A        self.assertEqual(%0A            Monitors.monitor.Monitor.get_config_option(%0A                config_options,%0A                'test_string'),%0A            'a string'%0A        )%0A        self.assertEqual(%0A            Monitors.monitor.Monitor.get_config_option(%0A                config_options,%0A                'test_int',%0A                required_type='int'),%0A            3%0A        )%0A        self.assertEqual(%0A            Monitors.monitor.Monitor.get_config_option(%0A                config_options,%0A                'test_%5Bint%5D',%0A                required_type='%5Bint%5D'),%0A            %5B1, 2, 3%5D%0A        )%0A        self.assertEqual(%0A            Monitors.monitor.Monitor.get_config_option(%0A                config_options,%0A                'test_%5Bstr%5D',%0A                required_type='%5Bstr%5D'),%0A            %5B'a', 'b', 'c'%5D%0A        )%0A        for bool_test in list(range(1, 4)):%0A            self.assertEqual(%0A                Monitors.monitor.Monitor.get_config_option(%0A                    config_options,%0A                    'test_bool%7B0%7D'.format(bool_test),%0A                    required_type='bool'),%0A                True%0A            )%0A        self.assertEqual(%0A            Monitors.monitor.Monitor.get_config_option(%0A                config_options,%0A                'test_bool4',%0A                required_type='bool'),%0A            False%0A        )%0A

Add tests for get_config_option