File size: 1,083 Bytes
e6404d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os
import tempfile

from src.session_history import HistoryEntry, SessionHistory
from src.image_tagger import _to_pil_image


def test_history_toggle_like_persists_to_disk():
    fd, path = tempfile.mkstemp(suffix='.json')
    os.close(fd)
    try:
        hist = SessionHistory(file_path=path)
        hist.add(HistoryEntry('prompt', ['one', 'two']))
        assert hist.toggle_like(0, 1) is True
        with open(path, encoding='utf-8') as f:
            data = json.load(f)
        assert data[0]['liked_indices'] == [1]
    finally:
        if os.path.exists(path):
            os.remove(path)


def test_to_pil_image_accepts_rgba_numpy():
    import numpy as np

    rgba = np.zeros((4, 4, 4), dtype=np.uint8)
    rgba[..., 0] = 255
    rgba[..., 3] = 255
    img = _to_pil_image(rgba)
    assert img.mode == 'RGB'
    assert img.size == (4, 4)


def test_to_pil_image_accepts_grayscale_numpy():
    import numpy as np

    gray = np.ones((3, 5), dtype=np.uint8) * 127
    img = _to_pil_image(gray)
    assert img.mode == 'RGB'
    assert img.size == (5, 3)