File tree Expand file tree Collapse file tree 2 files changed +4
-13
lines changed Expand file tree Collapse file tree 2 files changed +4
-13
lines changed Original file line number Diff line number Diff line change 11from  typing  import  TYPE_CHECKING 
22
3- import  chromadb 
43from  requests  import  ConnectionError , get 
54
65from  testcontainers .core .container  import  DockerContainer 
@@ -49,17 +48,6 @@ def __init__(
4948        self .with_exposed_ports (self .port )
5049        # self.with_command(f"server /data --address :{self.port}") 
5150
52-     def  get_client (self , ** kwargs ) ->  chromadb .ClientAPI :
53-         """Returns a Chroma HttpClient to connect to the container. 
54- 
55-         Returns: 
56-             HttpClient: Chroma HttpClient according to 
57-                    https://docs.trychroma.com/reference/Client#httpclient 
58-         """ 
59-         host_ip  =  self .get_container_host_ip ()
60-         exposed_port  =  self .get_exposed_port (self .port )
61-         return  chromadb .HttpClient (host = host_ip , port = int (exposed_port ))
62- 
6351    def  get_config (self ) ->  dict :
6452        """This method returns the configuration of the Chroma container, 
6553        including the endpoint. 
@@ -71,6 +59,8 @@ def get_config(self) -> dict:
7159        exposed_port  =  self .get_exposed_port (self .port )
7260        return  {
7361            "endpoint" : f"{ host_ip } { exposed_port }  ,
62+             "host" : host_ip ,
63+             "port" : exposed_port ,
7464        }
7565
7666    @wait_container_is_ready (ConnectionError ) 
Original file line number Diff line number Diff line change 11from  testcontainers .chroma  import  ChromaContainer 
2+ import  chromadb 
23
34
45def  test_docker_run_chroma ():
56    with  ChromaContainer (image = "chromadb/chroma:0.4.24" ) as  chroma :
6-         client  =  chroma .get_client ( )
7+         client  =  chromadb . HttpClient ( host = chroma .get_config ()[ "host" ],  port = chroma . get_config ()[ "port" ] )
78        col  =  client .get_or_create_collection ("test" )
89        assert  col .name  ==  "test" 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments