1
1
import pytest
2
-
2
+ from unittest . mock import MagicMock
3
3
from guidellm .executor import (ProfileGenerator , FixedRateProfileGenerator , SweepProfileGenerator )
4
+ from src .guidellm .core .result import TextGenerationBenchmarkReport
5
+ from src .guidellm .scheduler .load_generator import LoadGenerationModes
4
6
5
7
def test_invalid_profile_generation_mode_error ():
6
8
rate = [1 ]
@@ -10,19 +12,45 @@ def test_invalid_profile_generation_mode_error():
10
12
ProfileGenerator .create_generator (profile_mode , ** ({ "rate" : rate , "rate_type" : rate_type }))
11
13
12
14
def test_sweep_profile_generator_creation ():
13
- profile = ProfileGenerator .create_generator ("sweep" , ** ({}))
14
- assert isinstance (profile , SweepProfileGenerator )
15
- assert profile ._sync_run == False
16
- assert profile ._max_found == False
17
- assert profile ._pending_rates == None
18
- assert profile ._pending_rates == None
15
+ profile_generator = ProfileGenerator .create_generator ("sweep" , ** ({}))
16
+ assert isinstance (profile_generator , SweepProfileGenerator )
17
+ assert profile_generator ._sync_run == False
18
+ assert profile_generator ._max_found == False
19
+ assert profile_generator ._pending_rates == None
20
+ assert profile_generator ._pending_rates == None
19
21
20
22
def test_fixed_rate_profile_generator_creation ():
21
23
rate = [1 ]
22
24
rate_type = "constant"
23
- profile = ProfileGenerator .create_generator ("fixed_rate" , ** ({ "rate" : rate , "rate_type" : rate_type }))
24
- assert isinstance (profile , FixedRateProfileGenerator )
25
- assert profile ._rates == rate
26
- assert profile ._rate_type == rate_type
27
- assert profile ._rate_index == 0
28
- assert profile ._rate_index == 0
25
+ profile_generator = ProfileGenerator .create_generator ("fixed_rate" , ** ({ "rate" : rate , "rate_type" : rate_type }))
26
+ assert isinstance (profile_generator , FixedRateProfileGenerator )
27
+ assert profile_generator ._rates == rate
28
+ assert profile_generator ._rate_type == rate_type
29
+ assert profile_generator ._rate_index == 0
30
+ assert profile_generator ._rate_index == 0
31
+
32
+ def test_synchronous_mode_rate_list_error ():
33
+ rate = [1 ]
34
+ rate_type = "synchronous"
35
+ with pytest .raises (ValueError , match = "custom rates are not supported in synchronous mode" ):
36
+ ProfileGenerator .create_generator ("fixed_rate" , ** ({ "rate" : rate , "rate_type" : rate_type }))
37
+
38
+ def test_next_profile_with_multiple_rates ():
39
+ rates = [1 , 2 ]
40
+ rate_type = "constant"
41
+ profile_generator = ProfileGenerator .create_generator ("fixed_rate" , ** ({ "rate" : rates , "rate_type" : rate_type }))
42
+ mock_report = MagicMock (spec = TextGenerationBenchmarkReport )
43
+ for rate in rates :
44
+ current_profile = profile_generator .next_profile (mock_report )
45
+ assert current_profile .load_gen_rate == rate
46
+ assert current_profile .load_gen_mode .name == LoadGenerationModes .CONSTANT .name
47
+ assert profile_generator .next_profile (mock_report ) == None
48
+
49
+ def test_next_profile_with_sync_mode ():
50
+ rate_type = "synchronous"
51
+ profile_generator = ProfileGenerator .create_generator ("fixed_rate" , ** ({ "rate_type" : rate_type }))
52
+ mock_report = MagicMock (spec = TextGenerationBenchmarkReport )
53
+ current_profile = profile_generator .next_profile (mock_report )
54
+ assert current_profile .load_gen_rate == None
55
+ assert current_profile .load_gen_mode .name == LoadGenerationModes .SYNCHRONOUS .name
56
+ assert profile_generator .next_profile (mock_report ) == None
0 commit comments