-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_installation.py
More file actions
executable file
·162 lines (125 loc) · 4.62 KB
/
test_installation.py
File metadata and controls
executable file
·162 lines (125 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
"""
Quick test script to verify the Pashto Processing Pipeline installation.
"""
import sys
def test_imports():
"""Test that all core modules can be imported."""
print("Testing imports...")
try:
from pashto_pipeline import (
TextProcessingPipeline,
PashtoNormalizer,
PashtoTokenizer
)
print("✓ Core imports successful")
return True
except ImportError as e:
print(f"✗ Import failed: {e}")
return False
def test_normalizer():
"""Test the normalizer functionality."""
print("\nTesting PashtoNormalizer...")
try:
from pashto_pipeline import PashtoNormalizer
normalizer = PashtoNormalizer(normalize_whitespace=True)
# Test case 1: Whitespace normalization
text1 = "سلام دنیا"
result1 = normalizer.normalize(text1)
assert " " not in result1, "Multiple spaces not normalized"
# Test case 2: Digit normalization
normalizer2 = PashtoNormalizer(normalize_digits='western')
text2 = "۱۲۳"
result2 = normalizer2.normalize(text2)
assert "123" == result2, f"Digits not normalized correctly: {result2}"
print("✓ Normalizer tests passed")
return True
except Exception as e:
print(f"✗ Normalizer test failed: {e}")
return False
def test_tokenizer():
"""Test the tokenizer functionality."""
print("\nTesting PashtoTokenizer...")
try:
from pashto_pipeline import PashtoTokenizer
tokenizer = PashtoTokenizer(preserve_punctuation=True)
# Test case 1: Basic tokenization
text1 = "سلام دنیا"
tokens1 = tokenizer.tokenize(text1)
assert len(tokens1) == 2, f"Expected 2 tokens, got {len(tokens1)}"
# Test case 2: Punctuation preservation
text2 = "سلام دنیا!"
tokens2 = tokenizer.tokenize(text2)
assert '!' in tokens2, "Punctuation not preserved"
# Test case 3: Sentence tokenization
text3 = "سلام دنیا. دا یو ټیسټ دی."
sentences = tokenizer.tokenize_sentences(text3)
assert len(sentences) == 2, f"Expected 2 sentences, got {len(sentences)}"
print("✓ Tokenizer tests passed")
return True
except Exception as e:
print(f"✗ Tokenizer test failed: {e}")
return False
def test_pipeline():
"""Test the pipeline orchestration."""
print("\nTesting TextProcessingPipeline...")
try:
from pashto_pipeline import (
TextProcessingPipeline,
PashtoNormalizer,
PashtoTokenizer
)
# Create pipeline
pipeline = TextProcessingPipeline()
normalizer = PashtoNormalizer()
tokenizer = PashtoTokenizer()
# Add steps
pipeline.add_step('normalize', normalizer.normalize)
pipeline.add_step('tokenize', tokenizer.tokenize)
# Test single processing
text = "سلام دنیا"
result = pipeline.process(text, verbose=False)
assert isinstance(result, list), "Pipeline should return list from tokenizer"
# Test batch processing
texts = ["سلام", "دنیا"]
results = pipeline.process_batch(texts, verbose=False)
assert len(results) == 2, f"Expected 2 results, got {len(results)}"
# Test step management
assert 'normalize' in pipeline.get_steps(), "normalize step not found"
assert 'tokenize' in pipeline.get_steps(), "tokenize step not found"
print("✓ Pipeline tests passed")
return True
except Exception as e:
print(f"✗ Pipeline test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests."""
print("="*60)
print("Pashto Processing Pipeline - Test Suite")
print("="*60)
tests = [
test_imports,
test_normalizer,
test_tokenizer,
test_pipeline,
]
passed = 0
failed = 0
for test in tests:
if test():
passed += 1
else:
failed += 1
print("\n" + "="*60)
print(f"Test Results: {passed} passed, {failed} failed")
print("="*60)
if failed == 0:
print("\n🎉 All tests passed! The pipeline is working correctly.")
return 0
else:
print(f"\n⚠️ {failed} test(s) failed. Please check the errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())