def test_config_connection(self): """Test connection section from config file.""" # Default connection setting from xknx.yaml (auto:) self.assertEqual( TestConfig.xknx.connection_config, ConnectionConfig(connection_type=ConnectionType.AUTOMATIC), ) # Replaces setting from xknx.yaml test_configs = [ ( """ connection: tunneling: local_ip: '192.168.1.2' gateway_ip: 192.168.1.15 gateway_port: 6000 """, ConnectionConfig( connection_type=ConnectionType.TUNNELING, local_ip="192.168.1.2", gateway_ip="192.168.1.15", gateway_port=6000, ), ), ( """ connection: tunneling: gateway_ip: '192.168.1.2' """, ConnectionConfig( connection_type=ConnectionType.TUNNELING, gateway_ip="192.168.1.2" ), ), ( """ connection: routing: local_ip: '192.168.1.2' """, ConnectionConfig( connection_type=ConnectionType.ROUTING, local_ip="192.168.1.2" ), ), ( """ connection: routing: """, ConnectionConfig(connection_type=ConnectionType.ROUTING), ), ] for yaml_string, expected_conn in test_configs: config = yaml.safe_load(yaml_string) ConfigV1(TestConfig.xknx).parse_connection(config) self.assertEqual(TestConfig.xknx.connection_config, expected_conn)
def test_config_invalid_connection(self): """Test invalid connection section from config file.""" test_configs = [( """ connection: tunneling: local_ip: '192.168.1.2' """, XKNXException, "`gateway_ip` is required for tunneling connection.", )] for yaml_string, expected_exception, exception_message in test_configs: with self.assertRaises(expected_exception, msg=exception_message): config = yaml.safe_load(yaml_string) ConfigV1(TestConfig.xknx).parse_connection(config)