myanmar-ghost / test_verifier.py
amkyawdev's picture
Add tests
a14c2d1 verified
Raw
History Blame Contribute Delete
2.38 kB
"""Test verification module."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
from src.annotation.automatic_verifier import (
AutomaticVerifier,
TextLengthRule,
SentimentConsistencyRule,
)
def test_verifier_init():
"""Test verifier initialization."""
verifier = AutomaticVerifier()
assert len(verifier.rules) > 0
print("βœ“ Verifier init test passed")
def test_text_length_rule():
"""Test text length verification rule."""
rule = TextLengthRule(min_length=5, max_length=100)
# Test too short
passed, msg = rule.verify({"text": "Hi"})
assert not passed
# Test valid
passed, msg = rule.verify({"text": "Valid length text"})
assert passed
print("βœ“ Text length rule test passed")
def test_sentiment_consistency():
"""Test sentiment consistency rule."""
rule = SentimentConsistencyRule()
# Positive text with positive label
passed, msg = rule.verify({
"text": "ကျေးဇူးပါ",
"sentiment": "positive",
})
assert passed
print("βœ“ Sentiment consistency rule test passed")
def test_dataset_verification():
"""Test full dataset verification."""
verifier = AutomaticVerifier()
samples = [
{"id": "utt_001", "text": "ကျေးဇူးပါ", "sentiment": "positive"},
{"id": "utt_002", "text": "မကျေနပ်", "sentiment": "negative"},
]
results = verifier.verify_dataset(samples)
assert results["total_samples"] == 2
assert "statistics" in results
print("βœ“ Dataset verification test passed")
def test_sample_filtering():
"""Test sample filtering based on verification."""
verifier = AutomaticVerifier()
samples = [
{"id": "utt_001", "text": "ကျေးဇူးပါ", "sentiment": "positive"},
{"id": "utt_002", "text": "", "sentiment": "negative"}, # Invalid
]
kept, removed = verifier.filter_samples(samples)
assert len(kept) == 1
assert len(removed) == 1
print("βœ“ Sample filtering test passed")
if __name__ == "__main__":
test_verifier_init()
test_text_length_rule()
test_sentiment_consistency()
test_dataset_verification()
test_sample_filtering()
print("\nβœ… All verifier tests passed!")