Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
bootstrap.py52 linesDownload Raw Back to plugin
1# testing/plugin/bootstrap.py
2# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: https://www.opensource.org/licenses/mit-license.php
7# mypy: ignore-errors
8
9"""
10Bootstrapper for test framework plugins.
11
12The entire rationale for this system is to get the modules in plugin/
13imported without importing all of the supporting library, so that we can
14set up things for testing before coverage starts.
15
16The rationale for all of plugin/ being *in* the supporting library in the
17first place is so that the testing and plugin suite is available to other
18libraries, mainly external SQLAlchemy and Alembic dialects, to make use
19of the same test environment and standard suites available to
20SQLAlchemy/Alembic themselves without the need to ship/install a separate
21package outside of SQLAlchemy.
22
23
24"""
25
26import importlib.util
27import os
28import sys
29
30
31bootstrap_file = locals()["bootstrap_file"]
32to_bootstrap = locals()["to_bootstrap"]
33
34
35def load_file_as_module(name):
36    path = os.path.join(os.path.dirname(bootstrap_file), "%s.py" % name)
37
38    spec = importlib.util.spec_from_file_location(name, path)
39    assert spec is not None
40    assert spec.loader is not None
41    mod = importlib.util.module_from_spec(spec)
42    spec.loader.exec_module(mod)
43    return mod
44
45
46if to_bootstrap == "pytest":
47    sys.modules["sqla_plugin_base"] = load_file_as_module("plugin_base")
48    sys.modules["sqla_plugin_base"].bootstrapped_as_sqlalchemy = True
49    sys.modules["sqla_pytestplugin"] = load_file_as_module("pytestplugin")
50else:
51    raise Exception("unknown bootstrap: %s" % to_bootstrap)  # noqa
52 
codekingpro/portable-devtools · Team Ai