|
| 1 | +from pinecone.grpc import PineconeGRPC, GRPCClientConfig |
| 2 | + |
| 3 | +class TestGRPCIndexInitialization: |
| 4 | + def test_init_with_default_config(self): |
| 5 | + pc = PineconeGRPC(api_key='YOUR_API_KEY') |
| 6 | + index = pc.Index(name='my-index', host='host') |
| 7 | + |
| 8 | + assert index.grpc_client_config.secure == True |
| 9 | + assert index.grpc_client_config.timeout == 20 |
| 10 | + assert index.grpc_client_config.conn_timeout == 1 |
| 11 | + assert index.grpc_client_config.reuse_channel == True |
| 12 | + assert index.grpc_client_config.retry_config == None |
| 13 | + assert index.grpc_client_config.grpc_channel_options == None |
| 14 | + |
| 15 | + def test_init_with_grpc_config_from_dict(self): |
| 16 | + pc = PineconeGRPC(api_key='YOUR_API_KEY') |
| 17 | + config = GRPCClientConfig._from_dict({'timeout': 10}) |
| 18 | + index = pc.Index(name='my-index', host='host', grpc_config=config) |
| 19 | + |
| 20 | + assert index.grpc_client_config.timeout == 10 |
| 21 | + |
| 22 | + # Unset fields still get default values |
| 23 | + assert index.grpc_client_config.reuse_channel == True |
| 24 | + assert index.grpc_client_config.secure == True |
| 25 | + |
| 26 | + |
| 27 | + def test_init_with_grpc_config_non_dict(self): |
| 28 | + pc = PineconeGRPC(api_key='YOUR_API_KEY') |
| 29 | + config = GRPCClientConfig(timeout=10, secure=False) |
| 30 | + index = pc.Index(name='my-index', host='host', grpc_config=config) |
| 31 | + |
| 32 | + assert index.grpc_client_config.timeout == 10 |
| 33 | + assert index.grpc_client_config.secure == False |
| 34 | + |
| 35 | + # Unset fields still get default values |
| 36 | + assert index.grpc_client_config.reuse_channel == True |
| 37 | + assert index.grpc_client_config.conn_timeout == 1 |
| 38 | + |
| 39 | + def test_config_passed_when_target_by_name(self): |
| 40 | + pc = PineconeGRPC(api_key='YOUR_API_KEY') |
| 41 | + |
| 42 | + # Set this state in the host store to skip network call |
| 43 | + # to find host for name |
| 44 | + pc.index_host_store.set_host(pc.config, 'my-index', 'myhost') |
| 45 | + |
| 46 | + config = GRPCClientConfig(timeout=10, secure=False) |
| 47 | + index = pc.Index(name='my-index', grpc_config=config) |
| 48 | + |
| 49 | + assert index.grpc_client_config.timeout == 10 |
| 50 | + assert index.grpc_client_config.secure == False |
| 51 | + |
| 52 | + # Unset fields still get default values |
| 53 | + assert index.grpc_client_config.reuse_channel == True |
| 54 | + assert index.grpc_client_config.conn_timeout == 1 |
| 55 | + |
| 56 | + def test_config_passed_when_target_by_host(self): |
| 57 | + pc = PineconeGRPC(api_key='YOUR_API_KEY') |
| 58 | + config = GRPCClientConfig(timeout=5, secure=True) |
| 59 | + index = pc.Index(host='myhost', grpc_config=config) |
| 60 | + |
| 61 | + assert index.grpc_client_config.timeout == 5 |
| 62 | + assert index.grpc_client_config.secure == True |
| 63 | + |
| 64 | + # Unset fields still get default values |
| 65 | + assert index.grpc_client_config.reuse_channel == True |
| 66 | + assert index.grpc_client_config.conn_timeout == 1 |
0 commit comments