11"""tests parameters things"""
22
3- # import pytest
4- # import pvoutput
5-
6-
7- # def test_parameters_copying():
8- # """checks if the copied values are different"""
9- # assert pvoutput.ADDSTATUS_PARAMETERS["t"] != pvoutput.DELETESTATUS_PARAMETERS["t"]
10-
3+ import copy
114from datetime import datetime
12-
13- from pvoutput . parameters import ADDSTATUS_PARAMETERS
5+ from typing import Any , Dict
6+ import pytest
147from pvoutput import PVOutput
8+ from pvoutput .base import PVOutputBase
9+ from pvoutput .parameters import ADDSTATUS_PARAMETERS
1510
1611
1712def test_addstatus_default_date () -> None :
@@ -32,3 +27,91 @@ def testit(test: PVOutput) -> None:
3227 assert test_data ["d" ] == "20370111"
3328
3429 testit (test )
30+
31+ def test_parameters_copying () -> None :
32+ """checks if the copied values are different"""
33+ # This test is commented out but kept for reference
34+ # assert pvoutput.ADDSTATUS_PARAMETERS["t"] != pvoutput.DELETESTATUS_PARAMETERS["t"]
35+ pass
36+
37+
38+ class TestC1V3Validation :
39+ """Test cases for c1 flag and v3 validation logic"""
40+
41+ def setup_method (self ) -> None :
42+ """Setup test fixtures"""
43+ self .pvo_base = PVOutputBase (apikey = "test" , systemid = 123 )
44+
45+ def test_v3_exceeds_maxval_without_c1_flag_should_fail (self ) -> None :
46+ """Test that v3 values > 200000 fail validation when c1 is not set"""
47+ data = {"v3" : 250000 } # Exceeds maxval of 200000
48+
49+ with pytest .raises (ValueError , match = "v3 cannot be higher than 200000" ):
50+ self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
51+
52+ def test_v3_exceeds_maxval_with_c1_flag_should_pass (self ) -> None :
53+ """Test that v3 values > 200000 pass validation when c1 is set"""
54+ data = {"v3" : 250000 , "c1" : 1 } # c1 flag set, should bypass maxval check
55+
56+ # Should not raise an exception
57+ result = self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
58+ assert result is True
59+
60+ def test_v3_exceeds_maxval_with_c1_flag_value_2_should_pass (self ) -> None :
61+ """Test that v3 values > 200000 pass validation when c1=2"""
62+ data = {"v3" : 300000 , "c1" : 2 } # c1=2, should bypass maxval check
63+
64+ result = self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
65+ assert result is True
66+
67+ def test_v3_exceeds_maxval_with_c1_flag_value_3_should_pass (self ) -> None :
68+ """Test that v3 values > 200000 pass validation when c1=3"""
69+ data = {"v3" : 500000 , "c1" : 3 } # c1=3, should bypass maxval check
70+
71+ result = self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
72+ assert result is True
73+
74+ def test_v3_within_maxval_without_c1_flag_should_pass (self ) -> None :
75+ """Test that v3 values <= 200000 pass validation without c1 flag"""
76+ data = {"v3" : 150000 } # Within maxval limit
77+
78+ result = self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
79+ assert result is True
80+
81+ def test_v3_within_maxval_with_c1_flag_should_pass (self ) -> None :
82+ """Test that v3 values <= 200000 pass validation with c1 flag"""
83+ data = {"v3" : 150000 , "c1" : 1 } # Within limit, c1 set
84+
85+ result = self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
86+ assert result is True
87+
88+ def test_other_fields_maxval_validation_unaffected_by_c1 (self ) -> None :
89+ """Test that c1 flag doesn't affect maxval validation of other fields"""
90+ # Create a modified parameter set with maxval for testing
91+ test_params : Dict [str , Any ] = copy .deepcopy (ADDSTATUS_PARAMETERS )
92+ test_params ["v2" ] = {"maxval" : 1000 , "type" : int }
93+
94+ data = {"v2" : 1500 , "c1" : 1 } # v2 exceeds maxval, c1 set
95+
96+ with pytest .raises (ValueError , match = "v2 cannot be higher than 1000" ):
97+ self .pvo_base .validate_data (data , test_params )
98+
99+ def test_v3_minval_validation_still_applies_with_c1 (self ) -> None :
100+ """Test that minval validation for v3 still applies even when c1 is set"""
101+ # Create a deep copy of parameters and modify v3 to have minval
102+ test_params : Dict [str , Any ] = copy .deepcopy (ADDSTATUS_PARAMETERS )
103+ test_params ["v3" ]["minval" ] = 0
104+
105+ data = {"v3" : - 100 , "c1" : 1 } # Negative value, c1 set
106+
107+ with pytest .raises (ValueError , match = "v3 cannot be lower than 0" ):
108+ self .pvo_base .validate_data (data , test_params )
109+
110+ def test_c1_flag_zero_does_not_bypass_v3_maxval (self ) -> None :
111+ """Test that c1=0 (if somehow passed) doesn't bypass v3 maxval validation"""
112+ data = {"v3" : 250000 , "c1" : 0 } # c1=0 is not a valid flag value
113+
114+ # This should fail because c1=0 is not considered "set" for our logic
115+ # Note: This would also fail format validation, but testing the maxval logic specifically
116+ with pytest .raises (ValueError ):
117+ self .pvo_base .validate_data (data , ADDSTATUS_PARAMETERS )
0 commit comments