File size: 1,886 Bytes
b31f748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess
import pytest
import shutil

sct = shutil.which("sct")


@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([sct], 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([sct, 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([sct, 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([sct, 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([sct, 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([sct, str(sample_text_file), "--debug"], capture_output=True, text=True)
    assert result.returncode == 0
    assert "DEBUG" in result.stderr