Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_errors():
with pytest.raises(InvalidRuleDefinition):
RulesManager([()])
with pytest.raises(InvalidRuleDefinition):
RulesManager([None])
with pytest.raises(InvalidRuleDefinition):
RulesManager([10])
with pytest.raises(InvalidRuleLevel):
RulesManager([('rule', SimpleRule, 'WRONG LEVEL')])
with pytest.raises(InvalidRuleDefinition):
RulesManager([('rule', SimpleRule, settings.LEVEL_NORMAL, None)])
def _get_rule(self, rule, test_case):
if isinstance(rule, Rule):
return rule
elif hasattr(rule, '__call__'):
if test_case:
return TestCaseRule(rule, test_case)
else:
return CallableRule(rule)
elif isinstance(rule, six.string_types):
return PythonExpressionRule(rule)
else:
raise InvalidRuleDefinition('Wrong Rule definition, rules should be:\n'
'- an instance of Rule/TestCase objects.\n'
def _add_definition_from_tuple(self, tuple_definition):
level = None
if len(tuple_definition) == 2:
name, rule = tuple_definition
elif len(tuple_definition) == 3:
name, rule, level = tuple_definition
else:
raise InvalidRuleDefinition('Wrong Rule tuple definition, you should '
'either use (name, rule) or '
'(name, rule, level)')
self.add_rule(rule=rule, name=name, level=level)
def _add_definition_from_tuple(self, tuple_definition):
level = None
if len(tuple_definition) == 2:
name, rule = tuple_definition
elif len(tuple_definition) == 3:
name, rule, level = tuple_definition
else:
raise InvalidRuleDefinition('Wrong Rule tuple definition, you should '
'either use (name, rule) or '
'(name, rule, level)')
self.add_rule(rule=rule, name=name, level=level)
def _get_rule(self, rule, test_case):
if isinstance(rule, Rule):
return rule
elif hasattr(rule, '__call__'):
if test_case:
return TestCaseRule(rule, test_case)
else:
return CallableRule(rule)
elif isinstance(rule, six.string_types):
return PythonExpressionRule(rule)
else:
raise InvalidRuleDefinition('Wrong Rule definition, rules should be:\n'
'- an instance of Rule/TestCase objects.\n'