MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / ClusterTestCase

Class ClusterTestCase

asyncpg/_testbase/__init__.py:298–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296
297
298class ClusterTestCase(TestCase):
299 @classmethod
300 def get_server_settings(cls):
301 settings = {
302 'log_connections': 'on'
303 }
304
305 if cls.cluster.get_pg_version() >= (11, 0):
306 # JITting messes up timing tests, and
307 # is not essential for testing.
308 settings['jit'] = 'off'
309
310 return settings
311
312 @classmethod
313 def new_cluster(cls, ClusterCls, *, cluster_kwargs={}, initdb_options={}):
314 cluster = _init_cluster(ClusterCls, cluster_kwargs,
315 _get_initdb_options(initdb_options))
316 cls._clusters.append(cluster)
317 return cluster
318
319 @classmethod
320 def start_cluster(cls, cluster, *, server_settings={}):
321 cluster.start(port='dynamic', server_settings=server_settings)
322
323 @classmethod
324 def setup_cluster(cls):
325 cls.cluster = _init_default_cluster()
326
327 if cls.cluster.get_status() != 'running':
328 cls.cluster.start(
329 port='dynamic', server_settings=cls.get_server_settings())
330
331 @classmethod
332 def setUpClass(cls):
333 super().setUpClass()
334 cls._clusters = []
335 cls.setup_cluster()
336
337 @classmethod
338 def tearDownClass(cls):
339 super().tearDownClass()
340 for cluster in cls._clusters:
341 if cluster is not _default_cluster:
342 cluster.stop()
343 cluster.destroy()
344 cls._clusters = []
345
346 @classmethod
347 def get_connection_spec(cls, kwargs={}):
348 conn_spec = cls.cluster.get_connection_spec()
349 if kwargs.get('dsn'):
350 conn_spec.pop('host')
351 conn_spec.update(kwargs)
352 if not os.environ.get('PGHOST') and not kwargs.get('dsn'):
353 if 'database' not in conn_spec:
354 conn_spec['database'] = 'postgres'
355 if 'user' not in conn_spec:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…