@@ -74,38 +74,40 @@ def test_resolve_env_vars(self):
7474 "DB_PORT" : "5432"
7575 }
7676
77- # Test with direct variable
77+ # Test with direct variable using Jinja2 syntax
7878 result = resolver .resolve_env_vars (
79- "postgresql://${ DB_HOST}:${ DB_PORT}/mydb" ,
79+ "postgresql://{{ DB_HOST}}:{{ DB_PORT} }/mydb" ,
8080 env_vars
8181 )
8282 assert result == "postgresql://localhost:5432/mydb"
8383
84- # Test with default value
84+ # Test with direct variable using ${} syntax
8585 result = resolver .resolve_env_vars (
86- "postgresql://${DB_HOST:127.0.0.1 }:${DB_PORT:5432 }/mydb" ,
87- {}
86+ "postgresql://${DB_HOST}:${DB_PORT}/mydb" ,
87+ env_vars
8888 )
89- assert result == "postgresql://127.0.0.1 :5432/mydb"
89+ assert result == "postgresql://localhost :5432/mydb"
9090
9191 def test_check_required_env_vars (self ):
9292 """Test required environment variable validation."""
9393 resolver = ConfigResolver ()
9494
95- # Test with all required vars present
96- env_vars = {
97- "REQUIRED_VAR_1" : "value1" ,
98- "REQUIRED_VAR_2" : "value2"
99- }
100- resolver .check_required_env_vars (["REQUIRED_VAR_1" , "REQUIRED_VAR_2" ], env_vars )
95+ # Set up environment variables
96+ os .environ ["REQUIRED_VAR_1" ] = "value1"
97+ os .environ ["REQUIRED_VAR_2" ] = "value2"
10198
102- # Test with missing required var
103- with pytest .raises (ValueError ) as exc_info :
104- resolver .check_required_env_vars (
105- ["REQUIRED_VAR_1" , "MISSING_VAR" ],
106- env_vars
107- )
108- assert "Missing required environment variable: MISSING_VAR" in str (exc_info .value )
99+ try :
100+ # Test with all required vars present
101+ missing = resolver .check_required_env_vars (["REQUIRED_VAR_1" , "REQUIRED_VAR_2" ])
102+ assert missing == [], "Expected no missing variables"
103+
104+ # Test with missing required var
105+ missing = resolver .check_required_env_vars (["REQUIRED_VAR_1" , "MISSING_VAR" ])
106+ assert missing == ["MISSING_VAR" ], "Expected MISSING_VAR to be missing"
107+ finally :
108+ # Clean up
109+ os .environ .pop ("REQUIRED_VAR_1" , None )
110+ os .environ .pop ("REQUIRED_VAR_2" , None )
109111
110112
111113class TestConfigValidator :
@@ -114,41 +116,48 @@ class TestConfigValidator:
114116 def test_validate_uri (self ):
115117 """Test URI validation."""
116118 # Test valid RTSP URI
117- assert ConfigValidator .validate_uri ("rtsp://camera1:554/stream" , "sources" ) is None
119+ errors = ConfigValidator .validate_uri ("rtsp://camera1:554/stream" , "sources" )
120+ assert not errors , f"Expected no errors, got: { errors } "
118121
119122 # Test invalid scheme
120- with pytest . raises ( ValueError ) as exc_info :
121- ConfigValidator . validate_uri ( " invalid://test" , " sources")
122- assert "Unsupported scheme 'invalid' for source" in str ( exc_info . value )
123+ errors = ConfigValidator . validate_uri ( "invalid://test" , "sources" )
124+ assert any ( "Unsupported scheme ' invalid' for sources" in e for e in errors ), \
125+ f"Expected unsupported scheme error, got: { errors } "
123126
124127 # Test invalid destination
125- with pytest . raises ( ValueError ) as exc_info :
126- ConfigValidator . validate_uri ( " rtsp://test" , " destinations")
127- assert "Unsupported scheme 'rtsp' for destination" in str ( exc_info . value )
128+ errors = ConfigValidator . validate_uri ( "rtsp://test" , "destinations" )
129+ assert any ( "Unsupported scheme ' rtsp' for destinations" in e for e in errors ), \
130+ f"Expected unsupported scheme error for destination, got: { errors } "
128131
129132 def test_validate_processor (self ):
130133 """Test processor configuration validation."""
131134 # Test valid processor
132135 valid_processor = {
133136 "type" : "filter" ,
134- "config " : { "min_confidence" : 0.5 }
137+ "condition " : "some_condition"
135138 }
136- assert ConfigValidator .validate_processor (valid_processor ) is None
139+ errors = ConfigValidator .validate_processor (valid_processor )
140+ assert not errors , f"Expected no errors, got: { errors } "
137141
138142 # Test missing type
139- with pytest . raises ( ValueError ) as exc_info :
140- ConfigValidator . validate_processor ({ "config" : {}})
141- assert "Processor config missing ' type' field" in str ( exc_info . value )
143+ errors = ConfigValidator . validate_processor ({ "config" : {}})
144+ assert any ( "Unsupported processor type 'None'" in e for e in errors ), \
145+ f"Expected missing type error, got: { errors } "
142146
143147 # Test invalid type
144- with pytest . raises ( ValueError ) as exc_info :
145- ConfigValidator . validate_processor ({ " type" : " invalid" })
146- assert "Unsupported processor type: invalid" in str ( exc_info . value )
148+ errors = ConfigValidator . validate_processor ({ "type" : "invalid" })
149+ assert any ( "Unsupported processor type ' invalid'" in e for e in errors ), \
150+ f"Expected unsupported type error, got: { errors } "
147151
148- # Test missing config
149- with pytest .raises (ValueError ) as exc_info :
150- ConfigValidator .validate_processor ({"type" : "filter" })
151- assert "Processor config missing 'config' field" in str (exc_info .value )
152+ # Test missing required fields for filter type
153+ errors = ConfigValidator .validate_processor ({"type" : "filter" })
154+ assert any ("Filter processor requires 'condition' field" in e for e in errors ), \
155+ f"Expected missing condition error, got: { errors } "
156+
157+ # Test external processor validation
158+ errors = ConfigValidator .validate_processor ({"type" : "external" })
159+ assert any ("External processor requires 'command' field" in e for e in errors ), \
160+ f"Expected missing command error, got: { errors } "
152161
153162
154163def test_config_loading_from_file (tmp_path ):
0 commit comments