def test_clean_raises_for_yara_rule_without_same_rule_name(self):
        rule = ScannerRule(name='some_rule',
                           scanner=YARA,
                           definition='rule x {}')

        with pytest.raises(ValidationError, match=r'should match the name of'):
            rule.clean()
    def test_clean_raises_generic_error_when_yara_compile_failed(
            self, yara_compile_mock):
        rule = ScannerRule(name='some_rule',
                           scanner=YARA,
                           definition='rule some_rule { condition: true }')
        yara_compile_mock.side_effect = Exception()

        with pytest.raises(ValidationError, match=r'An error occurred'):
            rule.clean()
    def test_clean_raises_when_yara_rule_has_two_rules(self):
        rule = ScannerRule(
            name='some_rule',
            scanner=YARA,
            definition='rule some_rule {} rule foo {}',
        )

        with pytest.raises(ValidationError, match=r'Only one Yara rule'):
            rule.clean()
    def test_clean_raises_when_yara_rule_is_invalid(self):
        rule = ScannerRule(
            name='some_rule',
            scanner=YARA,
            # Invalid because there is no `condition`.
            definition='rule some_rule {}',
        )

        with pytest.raises(ValidationError,
                           match=r'The definition is not valid: line 1'):
            rule.clean()
    def test_clean_raises_for_yara_rule_without_a_definition(self):
        rule = ScannerRule(name='some_rule', scanner=YARA)

        with pytest.raises(ValidationError, match=r'should have a definition'):
            rule.clean()