Initial upload: ErrorFix CLI with rule engine and pattern matching
Some checks are pending
CI / test (push) Has started running

This commit is contained in:
2026-02-01 03:56:32 +00:00
parent f603af464d
commit 1ca145b626

68
tests/unit/test_rules.py Normal file
View File

@@ -0,0 +1,68 @@
import pytest
from errorfix.rules import Rule
class TestRule:
def test_rule_creation(self):
rule = Rule(
id='test-rule',
name='Test Rule',
pattern='TestError: .*',
fix='Fix it',
description='A test rule',
)
assert rule.id == 'test-rule'
assert rule.name == 'Test Rule'
assert rule.pattern == 'TestError: .*'
assert rule.fix == 'Fix it'
assert rule.description == 'A test rule'
assert rule.severity.value == 'error'
def test_rule_from_dict(self):
data = {
'id': 'test-rule',
'name': 'Test Rule',
'pattern': 'TestError: .*',
'fix': 'Fix it',
'description': 'A test rule',
'severity': 'warning',
'language': 'python',
'tags': ['test', 'example'],
'priority': 10,
}
rule = Rule.from_dict(data)
assert rule.id == 'test-rule'
assert rule.severity.value == 'warning'
assert rule.language == 'python'
assert rule.tags == ['test', 'example']
assert rule.priority == 10
def test_rule_to_dict(self):
rule = Rule(
id='test-rule',
name='Test Rule',
pattern='TestError: .*',
fix='Fix it',
description='A test rule',
severity='warning',
)
data = rule.to_dict()
assert data['id'] == 'test-rule'
assert data['severity'] == 'warning'
def test_rule_with_all_fields(self):
rule = Rule(
id='full-rule',
name=' 'Full Rule',
pattern='FullError: (?P<msg>.*)',
fix='Fix {msg}',
description='A rule with all fields',
severity='suggestion',
language='javascript',
tool='node',
tags=['tag1', 'tag2'],
priority=7,
metadata={'extra': 'data'},
)
assert rule.tool == 'node'
assert rule.metadata == {'extra': 'data'}