def test_validate_rule_conf(self): class Rule(object): ID = 'fake' self.assertFalse(config.validate_rule_conf(Rule, False)) self.assertFalse(config.validate_rule_conf(Rule, 'disable')) self.assertEqual(config.validate_rule_conf(Rule, {}), {'level': 'error'}) self.assertEqual(config.validate_rule_conf(Rule, 'enable'), {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'warning'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'level': 'warn'}) Rule.CONF = {'length': int} config.validate_rule_conf(Rule, {'length': 8}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'height': 8}) Rule.CONF = {'a': bool, 'b': int} config.validate_rule_conf(Rule, {'a': True, 'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'a': True}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'a': 1, 'b': 0}) Rule.CONF = {'choice': (True, 88, 'str')} config.validate_rule_conf(Rule, {'choice': True}) config.validate_rule_conf(Rule, {'choice': 88}) config.validate_rule_conf(Rule, {'choice': 'str'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 99}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'}) Rule.CONF = {'choice': (int, 'hardcoded')} config.validate_rule_conf(Rule, {'choice': 42}) config.validate_rule_conf(Rule, {'choice': 'hardcoded'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'})
def test_validate_rule_conf(self): class Rule(object): ID = 'fake' self.assertFalse(config.validate_rule_conf(Rule, False)) self.assertEqual(config.validate_rule_conf(Rule, {}), {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'warning'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'level': 'warn'}) Rule.CONF = {'length': int} Rule.DEFAULT = {'length': 80} config.validate_rule_conf(Rule, {'length': 8}) config.validate_rule_conf(Rule, {}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'height': 8}) Rule.CONF = {'a': bool, 'b': int} Rule.DEFAULT = {'a': True, 'b': -42} config.validate_rule_conf(Rule, {'a': True, 'b': 0}) config.validate_rule_conf(Rule, {'a': True}) config.validate_rule_conf(Rule, {'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, { 'a': 1, 'b': 0 }) Rule.CONF = {'choice': (True, 88, 'str')} Rule.DEFAULT = {'choice': 88} config.validate_rule_conf(Rule, {'choice': True}) config.validate_rule_conf(Rule, {'choice': 88}) config.validate_rule_conf(Rule, {'choice': 'str'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 99}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'}) Rule.CONF = {'choice': (int, 'hardcoded')} Rule.DEFAULT = {'choice': 1337} config.validate_rule_conf(Rule, {'choice': 42}) config.validate_rule_conf(Rule, {'choice': 'hardcoded'}) config.validate_rule_conf(Rule, {}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'}) Rule.CONF = {'multiple': ['item1', 'item2', 'item3']} Rule.DEFAULT = {'multiple': ['item1']} config.validate_rule_conf(Rule, {'multiple': []}) config.validate_rule_conf(Rule, {'multiple': ['item2']}) config.validate_rule_conf(Rule, {'multiple': ['item2', 'item3']}) config.validate_rule_conf(Rule, {}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'multiple': 'item1'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'multiple': ['']}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'multiple': ['item1', 4]}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'multiple': ['item4']})
def test_validate_rule_conf(self): class Rule(object): ID = 'fake' self.assertEqual(config.validate_rule_conf(Rule, False), False) self.assertEqual(config.validate_rule_conf(Rule, 'disable'), False) self.assertEqual(config.validate_rule_conf(Rule, {}), {'level': 'error'}) self.assertEqual(config.validate_rule_conf(Rule, 'enable'), {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'error'}) config.validate_rule_conf(Rule, {'level': 'warning'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'level': 'warn'}) Rule.CONF = {'length': int} config.validate_rule_conf(Rule, {'length': 8}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'height': 8}) Rule.CONF = {'a': bool, 'b': int} config.validate_rule_conf(Rule, {'a': True, 'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'a': True}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'b': 0}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'a': 1, 'b': 0}) Rule.CONF = {'choice': (True, 88, 'str')} config.validate_rule_conf(Rule, {'choice': True}) config.validate_rule_conf(Rule, {'choice': 88}) config.validate_rule_conf(Rule, {'choice': 'str'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 99}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'}) Rule.CONF = {'choice': (int, 'hardcoded')} config.validate_rule_conf(Rule, {'choice': 42}) config.validate_rule_conf(Rule, {'choice': 'hardcoded'}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': False}) self.assertRaises(config.YamlLintConfigError, config.validate_rule_conf, Rule, {'choice': 'abc'})