| 328 | |
| 329 | |
| 330 | class Config: |
| 331 | def __init__(self, db, db_opts, options, file_config): |
| 332 | self._set_name(db) |
| 333 | self.db = db |
| 334 | self.db_opts = db_opts |
| 335 | self.options = options |
| 336 | self.file_config = file_config |
| 337 | self.test_schema = "test_schema" |
| 338 | self.test_schema_2 = "test_schema_2" |
| 339 | |
| 340 | self.is_async = db.dialect.is_async |
| 341 | |
| 342 | from . import provision |
| 343 | |
| 344 | self.is_default_dialect = provision.is_preferred_driver(self, db) |
| 345 | |
| 346 | _stack = collections.deque() |
| 347 | _configs = set() |
| 348 | |
| 349 | def __repr__(self): |
| 350 | return ( |
| 351 | f"sqlalchemy.testing.config.Config" |
| 352 | f"({self.db.name}+{self.db.driver}, " |
| 353 | f"{self.db.dialect.server_version_info})" |
| 354 | ) |
| 355 | |
| 356 | def _set_name(self, db): |
| 357 | suffix = "_async" if db.dialect.is_async else "" |
| 358 | if db.dialect.server_version_info: |
| 359 | svi = ".".join(str(tok) for tok in db.dialect.server_version_info) |
| 360 | self.name = "%s+%s%s_[%s]" % (db.name, db.driver, suffix, svi) |
| 361 | else: |
| 362 | self.name = "%s+%s%s" % (db.name, db.driver, suffix) |
| 363 | |
| 364 | @classmethod |
| 365 | def register(cls, db, db_opts, options, file_config): |
| 366 | """add a config as one of the global configs. |
| 367 | |
| 368 | If there are no configs set up yet, this config also |
| 369 | gets set as the "_current". |
| 370 | """ |
| 371 | global any_async |
| 372 | |
| 373 | cfg = Config(db, db_opts, options, file_config) |
| 374 | |
| 375 | # if any backends include an async driver, then ensure |
| 376 | # all setup/teardown and tests are wrapped in the maybe_async() |
| 377 | # decorator that will set up a greenlet context for async drivers. |
| 378 | any_async = any_async or cfg.is_async |
| 379 | |
| 380 | cls._configs.add(cfg) |
| 381 | return cfg |
| 382 | |
| 383 | @classmethod |
| 384 | def set_as_current(cls, config, namespace): |
| 385 | global db, _current, db_url, test_schema, test_schema_2, db_opts |
| 386 | _current = config |
| 387 | db_url = config.db.url |
no outgoing calls
no test coverage detected