def test_define_config_option(self): define_config_option("foo", "a", "Description", required_option=True, convert_to=int) self.assertRaises(BadMonitorConfiguration, MonitorConfig, {"b": 1}, monitor_module="foo") config = MonitorConfig({"a": "5"}, monitor_module="foo") self.assertEquals(config.get("a"), 5) define_config_option( "foo", "b", "Description", min_value=5, max_value=10, default=7, convert_to=int, ) config = MonitorConfig({"a": 5}, monitor_module="foo") self.assertEquals(config.get("b"), 7) self.assertRaises( BadMonitorConfiguration, MonitorConfig, { "a": 5, "b": 1 }, monitor_module="foo", ) self.assertRaises( BadMonitorConfiguration, MonitorConfig, { "a": 5, "b": 11 }, monitor_module="foo", ) # Test case where no value in config for option with no default value should result in no value in # MonitorConfig object define_config_option("foo", "c", "Description", min_value=5, max_value=10, convert_to=int) config = MonitorConfig({"a": 5}, monitor_module="foo") self.assertTrue("c" not in config)
def test_required_field(self): config = MonitorConfig({"foo": 10}) self.assertEquals(config.get("foo", required_field=True), 10) self.assertRaises( BadMonitorConfiguration, config.get, "fo", required_field=True )
def test_define_config_option(self): define_config_option('foo', 'a', 'Description', required_option=True, convert_to=int) self.assertRaises(BadMonitorConfiguration, MonitorConfig, {'b': 1}, monitor_module='foo') config = MonitorConfig({'a': '5'}, monitor_module='foo') self.assertEquals(config.get('a'), 5) define_config_option('foo', 'b', 'Description', min_value=5, max_value=10, default=7, convert_to=int) config = MonitorConfig({'a': 5}, monitor_module='foo') self.assertEquals(config.get('b'), 7) self.assertRaises(BadMonitorConfiguration, MonitorConfig, { 'a': 5, 'b': 1 }, monitor_module='foo') self.assertRaises(BadMonitorConfiguration, MonitorConfig, { 'a': 5, 'b': 11 }, monitor_module='foo') # Test case where no value in config for option with no default value should result in no value in # MonitorConfig object define_config_option('foo', 'c', 'Description', min_value=5, max_value=10, convert_to=int) config = MonitorConfig({'a': 5}, monitor_module='foo') self.assertTrue('c' not in config)
def test_define_config_option(self): define_config_option('foo', 'a', 'Description', required_option=True, convert_to=int) self.assertRaises(BadMonitorConfiguration, MonitorConfig, {'b': 1}, monitor_module='foo') config = MonitorConfig({'a': '5'}, monitor_module='foo') self.assertEquals(config.get('a'), 5) define_config_option('foo', 'b', 'Description', min_value=5, max_value=10, default=7, convert_to=int) config = MonitorConfig({'a': 5}, monitor_module='foo') self.assertEquals(config.get('b'), 7) self.assertRaises(BadMonitorConfiguration, MonitorConfig, {'a': 5, 'b': 1}, monitor_module='foo') self.assertRaises(BadMonitorConfiguration, MonitorConfig, {'a': 5, 'b': 11}, monitor_module='foo') # Test case where no value in config for option with no default value should result in no value in # MonitorConfig object define_config_option('foo', 'c', 'Description', min_value=5, max_value=10, convert_to=int) config = MonitorConfig({'a': 5}, monitor_module='foo') self.assertTrue('c' not in config)
def get(self, original_value, convert_to=None, required_field=False, max_value=None, min_value=None): config = MonitorConfig({'foo': original_value}) return config.get('foo', convert_to=convert_to, required_field=required_field, max_value=max_value, min_value=min_value)
def test_default_value(self): config = MonitorConfig({"foo": 10}) self.assertEquals(config.get("foo", default=20), 10) self.assertEquals(config.get("fee", default=20), 20)
def test_default_value(self): config = MonitorConfig({'foo': 10}) self.assertEquals(config.get('foo', default=20), 10) self.assertEquals(config.get('fee', default=20), 20)
def test_required_field(self): config = MonitorConfig({'foo': 10}) self.assertEquals(config.get('foo', required_field=True), 10) self.assertRaises(BadMonitorConfiguration, config.get, 'fo', required_field=True)