File size: 2,131 Bytes
1a12965
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""End-to-end integration tests running the full pipeline against the real bundled assets."""

from __future__ import annotations

import json

import numpy as np

from src.config.loader import load_config
from src.generator import GeneratorContext


def _make_context(tmp_path, seed: int = 123):
    overrides = [
        f"paths.output_dir={tmp_path.as_posix()}",
        "generation.count=1",
    ]
    config = load_config(overrides=[f"seed={seed}"] + overrides)
    return config, GeneratorContext(config)


def test_run_sample_produces_complete_metadata(tmp_path):
    config, ctx = _make_context(tmp_path)
    metadata, final_image, validation_report = ctx.run_sample(1)

    assert isinstance(final_image, np.ndarray)
    assert final_image.ndim == 3 and final_image.shape[2] == 3
    assert final_image.dtype == np.uint8

    for key in ("document_id", "template", "signer", "difficulty", "quality", "augmentation", "geometry", "metrics"):
        assert key in metadata

    assert validation_report is not None
    assert validation_report.passed, [i.message for i in validation_report.issues]


def test_run_sample_is_fully_reproducible(tmp_path):
    config, ctx = _make_context(tmp_path, seed=555)
    metadata1, image1, _ = ctx.run_sample(42)
    metadata2, image2, _ = ctx.run_sample(42)

    assert np.array_equal(image1, image2)
    metadata1.pop("provenance", None)
    metadata2.pop("provenance", None)
    assert json.dumps(metadata1, sort_keys=True, default=str) == json.dumps(metadata2, sort_keys=True, default=str)


def test_different_sample_indices_produce_different_documents(tmp_path):
    config, ctx = _make_context(tmp_path, seed=555)
    metadata1, image1, _ = ctx.run_sample(1)
    metadata2, image2, _ = ctx.run_sample(2)

    assert not np.array_equal(image1, image2) or metadata1["signer"] != metadata2["signer"]


def test_difficulty_tier_is_one_of_expected_values(tmp_path):
    config, ctx = _make_context(tmp_path, seed=7)
    metadata, _, _ = ctx.run_sample(1)
    assert metadata["difficulty"]["tier"] in ("easy", "medium", "hard")
    assert 0.0 <= metadata["difficulty"]["score"] <= 1.0