File size: 1,319 Bytes
529c3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest
import sys
import os

# Add the parent directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app import clear_conversation, update_chat_info, cancel_inference, respond, custom_css, demo

def test_clear_conversation():
    result = clear_conversation()
    assert result is None

def test_update_chat_info_empty():
    history = None
    message_count, word_count = update_chat_info(history)
    assert message_count == 0
    assert word_count == 0

def test_cancel_inference():
    cancel_inference()
    from app import stop_inference
    assert stop_inference == True

def test_respond_input_types():
    message = "Test message"
    history = [("User", "Hello"), ("Bot", "Hi")]
    system_message = "You are a test bot"
    max_tokens = 100
    temperature = 0.7
    top_p = 0.9
    use_local_model = False

    generator = respond(message, history, system_message, max_tokens, temperature, top_p, use_local_model)
    
    assert hasattr(generator, '__next__')  # Check if it's a generator

def test_custom_css_exists():
    assert isinstance(custom_css, str)
    assert len(custom_css) > 0

def test_demo_object_creation():
    assert demo is not None
    assert hasattr(demo, 'launch')

if __name__ == "__main__":
    pytest.main([__file__])