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

Class ClusterTestCase

asyncpg/_testbase/__init__.py:301–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected