11import base64
22import logging
3+ import os
34from datetime import datetime , timezone
45from typing import Sequence , Tuple
56
2122from mcbackend .test_utils import CheckBehavior , CheckPerformance , make_runmeta
2223
2324try :
24- client = clickhouse_driver .Client ("localhost" )
25+ DB_HOST = os .environ .get ("CLICKHOUSE_HOST" , "localhost" )
26+ DB_PASS = os .environ .get ("CLICKHOUSE_PASS" , None )
27+ DB_PORT = os .environ .get ("CLICKHOUSE_PORT" , 9000 )
28+ DB_KWARGS = dict (host = DB_HOST , port = DB_PORT , password = DB_PASS )
29+ client = clickhouse_driver .Client (** DB_KWARGS )
2530 client .execute ("SHOW DATABASES;" )
2631 HAS_REAL_DB = True
2732except :
@@ -51,7 +56,7 @@ def fully_initialized(
5156
5257@pytest .mark .skipif (
5358 condition = not HAS_REAL_DB ,
54- reason = "Integration tests need a ClickHouse server on localhost:9000 without authentication ." ,
59+ reason = "Integration tests need a ClickHouse server." ,
5560)
5661class TestClickHouseBackendInitialization :
5762 """This is separate because ``TestClickHouseBackend.setup_method`` depends on these things."""
@@ -63,12 +68,12 @@ def test_exceptions(self):
6368
6469 def test_backend_from_client_object (self ):
6570 db = "testing_" + hagelkorn .random ()
66- _client_main = clickhouse_driver .Client ("localhost" )
71+ _client_main = clickhouse_driver .Client (** DB_KWARGS )
6772 _client_main .execute (f"CREATE DATABASE { db } ;" )
6873
6974 try :
7075 # When created from a client object, all chains share the client
71- backend = ClickHouseBackend (client = clickhouse_driver .Client ("localhost" , database = db ))
76+ backend = ClickHouseBackend (client = clickhouse_driver .Client (** DB_KWARGS , database = db ))
7277 assert callable (backend ._client_fn )
7378 run = backend .init_run (make_runmeta ())
7479 c1 = run .init_chain (0 )
@@ -81,11 +86,11 @@ def test_backend_from_client_object(self):
8186
8287 def test_backend_from_client_function (self ):
8388 db = "testing_" + hagelkorn .random ()
84- _client_main = clickhouse_driver .Client ("localhost" )
89+ _client_main = clickhouse_driver .Client (** DB_KWARGS )
8590 _client_main .execute (f"CREATE DATABASE { db } ;" )
8691
8792 def client_fn ():
88- return clickhouse_driver .Client ("localhost" , database = db )
93+ return clickhouse_driver .Client (** DB_KWARGS , database = db )
8994
9095 try :
9196 # When created from a client function, each chain has its own client
@@ -108,7 +113,7 @@ def client_fn():
108113
109114@pytest .mark .skipif (
110115 condition = not HAS_REAL_DB ,
111- reason = "Integration tests need a ClickHouse server on localhost:9000 without authentication ." ,
116+ reason = "Integration tests need a ClickHouse server." ,
112117)
113118class TestClickHouseBackend (CheckBehavior , CheckPerformance ):
114119 cls_backend = ClickHouseBackend
@@ -118,11 +123,11 @@ class TestClickHouseBackend(CheckBehavior, CheckPerformance):
118123 def setup_method (self , method ):
119124 """Initializes a fresh database just for this test method."""
120125 self ._db = "testing_" + hagelkorn .random ()
121- self ._client_main = clickhouse_driver .Client ("localhost" )
126+ self ._client_main = clickhouse_driver .Client (** DB_KWARGS )
122127 self ._client_main .execute (f"CREATE DATABASE { self ._db } ;" )
123- self ._client = clickhouse_driver .Client ("localhost" , database = self ._db )
128+ self ._client = clickhouse_driver .Client (** DB_KWARGS , database = self ._db )
124129 self .backend = ClickHouseBackend (
125- client_fn = lambda : clickhouse_driver .Client ("localhost" , database = self ._db )
130+ client_fn = lambda : clickhouse_driver .Client (** DB_KWARGS , database = self ._db )
126131 )
127132 return
128133
0 commit comments