File size: 4,860 Bytes
a199cc3 | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | """Tests for CLI module."""
from __future__ import annotations
import json
import subprocess
import sys
def test_cli_exists():
"""Test that CLI module exists and is importable."""
from durak import cli
assert cli is not None
assert cli.cli is not None
def test_cli_clean_command():
"""Test clean command via subprocess."""
test_text = "İSTANBUL'da harika bir gün!"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "clean", "-"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "istanbul" in result.stdout.lower()
def test_cli_clean_with_json_format():
"""Test clean command with JSON output format."""
test_text = "İSTANBUL"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "clean", "-", "--format", "json"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
data = json.loads(result.stdout)
assert "text" in data
assert "char_count" in data
def test_cli_tokenize_command():
"""Test tokenize command via subprocess."""
test_text = "Merhaba dünya"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "tokenize", "-"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "merhaba" in result.stdout.lower()
assert "dünya" in result.stdout.lower()
def test_cli_tokenize_with_json_format():
"""Test tokenize command with JSON output format."""
test_text = "Merhaba dünya"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "tokenize", "-", "--format", "json"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
data = json.loads(result.stdout)
assert "tokens" in data
assert "count" in data
assert data["count"] == 2
def test_cli_lemmatize_command():
"""Test lemmatize command via subprocess."""
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "lemmatize", "kitaplar", "evler"],
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "kitap" in result.stdout
assert "ev" in result.stdout
def test_cli_stopwords_command():
"""Test stopwords command via subprocess."""
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "stopwords", "--format", "json"],
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
words = json.loads(result.stdout)
assert isinstance(words, list)
assert len(words) > 0
assert "ve" in words
def test_cli_version_command():
"""Test version command via subprocess."""
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "version"],
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "0.4.0" in result.stdout or "Durak" in result.stdout
def test_cli_normalize_command():
"""Test normalize command via subprocess."""
test_text = "İSTANBUL"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "normalize", "-"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "istanbul" in result.stdout.lower()
def test_cli_process_command():
"""Test process command via subprocess."""
test_text = "Merhaba dünya"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "process", "-"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "merhaba" in result.stdout.lower()
def test_cli_process_with_stopwords():
"""Test process command with stopword removal."""
test_text = "Bu bir test"
result = subprocess.run(
[sys.executable, "-m", "durak.cli", "process", "-", "--remove-stopwords"],
input=test_text,
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
assert "test" in result.stdout.lower()
def test_cli_lemmatize_with_strategy():
"""Test lemmatize command with specific strategy."""
result = subprocess.run(
[
sys.executable,
"-m",
"durak.cli",
"lemmatize",
"--strategy",
"lookup",
"kitaplar",
],
capture_output=True,
text=True,
encoding="utf-8",
)
assert result.returncode == 0
|