File size: 2,469 Bytes
b31f748
8ef3a6b
b31f748
 
8ef3a6b
 
 
 
b31f748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ef3a6b
b31f748
 
 
 
 
8ef3a6b
 
 
b31f748
 
 
 
 
8ef3a6b
 
 
b31f748
 
 
 
 
 
8ef3a6b
 
 
b31f748
 
 
 
 
73ab668
8ef3a6b
73ab668
b31f748
 
 
 
 
8ef3a6b
 
 
b31f748
 
8ef3a6b
 
 
 
 
 
 
 
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
import subprocess
import sys
import pytest


def get_sct_command():
    """Get the command to run the SCT CLI"""
    return [sys.executable, "-m", "iscc_sct.cli"]


@pytest.fixture
def sample_text_file(tmp_path):
    file_path = tmp_path / "sample.txt"
    file_path.write_text("This is a sample text for testing.")
    return file_path


@pytest.fixture
def empty_text_file(tmp_path):
    file_path = tmp_path / "empty.txt"
    file_path.write_text(" ")
    return file_path


@pytest.fixture
def non_utf8_text_file(tmp_path):
    file_path = tmp_path / "non_utf8.txt"
    file_path.write_text("Iñtërnâtiônàlizætiøn☃", encoding="utf-16")
    return file_path


def test_cli_no_args():
    result = subprocess.run(get_sct_command(), capture_output=True, text=True)
    assert result.returncode == 0
    assert "Generate Semantic" in result.stdout


def test_cli_empty_file(empty_text_file):
    result = subprocess.run(
        [*get_sct_command(), str(empty_text_file), "-d"], capture_output=True, text=True
    )
    assert result.returncode == 0
    assert "SKIPPED" in result.stderr


def test_cli_non_utf8_file(non_utf8_text_file):
    result = subprocess.run(
        [*get_sct_command(), str(non_utf8_text_file), "-d"], capture_output=True, text=True
    )
    assert result.returncode == 0
    assert "Could not decode" in result.stderr
    assert "ISCC:" in result.stdout


def test_cli_generate_sct(sample_text_file):
    result = subprocess.run(
        [*get_sct_command(), str(sample_text_file)], capture_output=True, text=True
    )
    assert result.returncode == 0
    assert "ISCC:" in result.stdout


def test_cli_generate_sct_granular(sample_text_file):
    result = subprocess.run(
        [*get_sct_command(), str(sample_text_file), "--granular"], capture_output=True, text=True
    )
    assert result.returncode == 0
    assert "features" in result.stdout


def test_cli_debug_mode(sample_text_file):
    result = subprocess.run(
        [*get_sct_command(), str(sample_text_file), "--debug"], capture_output=True, text=True
    )
    assert result.returncode == 0
    assert "DEBUG" in result.stderr


def test_cli_doctor():
    # The test environment has a working CPU runtime, so doctor reports OK and exits cleanly
    # without prompting (no stdin, no pip call).
    result = subprocess.run([*get_sct_command(), "doctor"], capture_output=True, text=True)
    assert result.returncode == 0
    assert "ONNX runtime" in result.stdout