forked from catherinedevlin/ipython-sql
-
Notifications
You must be signed in to change notification settings - Fork 76
/
noxfile.py
166 lines (134 loc) Β· 3.97 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from pathlib import Path
from os import environ
import nox
# list non-setup sessions here
nox.options.sessions = ["test_postgres"]
# GitHub actions does not have conda installed
VENV_BACKEND = "conda" if "CI" not in environ else None
DEV_ENV_NAME = "jupysql-env"
if VENV_BACKEND == "conda":
CONDA_PREFIX = environ.get("CONDA_PREFIX")
if CONDA_PREFIX:
nox.options.envdir = str(Path(CONDA_PREFIX).parent)
else:
print("CONDA_PREFIX not found, creating envs in default location...")
INTEGRATION_CONDA_DEPENDENCIES = [
"pyarrow",
"psycopg2",
"pymysql",
"oracledb",
"pip",
]
INTEGRATION_PIP_DEPENDENCIES = [
"dockerctx",
"pgspecial==2.0.1",
"pyodbc==4.0.34",
"sqlalchemy-pytds",
"python-tds",
"pyspark>=3.4.1",
"grpcio-status",
]
def _install(session, integration):
session.install("--editable", ".[dev]")
if integration:
session.install(*INTEGRATION_PIP_DEPENDENCIES)
session.install(*INTEGRATION_CONDA_DEPENDENCIES)
def _check_sqlalchemy(session, version):
session.run(
"python",
"-c",
(
"import sqlalchemy; "
f"assert int(sqlalchemy.__version__.split('.')[0]) == {version}"
),
)
def _run_unit(session, skip_image_tests):
args = [
"pytest",
"src/tests/",
"--ignore",
"src/tests/integration",
]
if skip_image_tests:
args.extend(
[
"--ignore",
"src/tests/test_ggplot.py",
"--ignore",
"src/tests/test_magic_plot.py",
]
)
session.run(*args)
@nox.session(
venv_backend=VENV_BACKEND,
name=DEV_ENV_NAME,
python=environ.get("PYTHON_VERSION", "3.11"),
)
def setup(session):
print("Installing requirements...")
_install(session, integration=False)
@nox.session(
venv_backend=VENV_BACKEND,
python=environ.get("PYTHON_VERSION", "3.11"),
)
def test_unit(session):
"""Run unit tests (SQLAlchemy 2.x)"""
SKIP_IMAGE_TEST = "--skip-image-tests" in session.posargs
_install(session, integration=False)
session.install("sqlalchemy>=2")
_check_sqlalchemy(session, version=2)
_run_unit(session, skip_image_tests=SKIP_IMAGE_TEST)
@nox.session(
venv_backend=VENV_BACKEND,
python=environ.get("PYTHON_VERSION", "3.11"),
)
def test_unit_sqlalchemy_one(session):
"""Run unit tests (SQLAlchemy 1.x)"""
SKIP_IMAGE_TEST = "--skip-image-tests" in session.posargs
_install(session, integration=False)
session.install("sqlalchemy<2")
_check_sqlalchemy(session, version=1)
_run_unit(session, skip_image_tests=SKIP_IMAGE_TEST)
@nox.session(
venv_backend=VENV_BACKEND,
python=environ.get("PYTHON_VERSION", "3.11"),
)
def test_integration_cloud(session):
"""
Run integration tests on cloud databases (currently snowflake and redshift)
(NOTE: the sqlalchemy-snowflake and sqlalchemy-redshift driver only work with
SQLAlchemy 1.x)
This is disabled currently, refer: https://github.com/ploomber/jupysql/issues/984
If it is required to enable these tests add a job in
.github/workflows/ci.yaml file.
"""
# TODO: do not require integration test dependencies if only running snowflake
# tests
_install(session, integration=True)
session.install(
"snowflake-sqlalchemy",
"redshift-connector",
"sqlalchemy-redshift",
"clickhouse-sqlalchemy",
)
session.run(
"pytest",
"src/tests/integration",
"-k",
"snowflake or redshift or clickhouse",
"-v",
)
@nox.session(
venv_backend=VENV_BACKEND,
python=environ.get("PYTHON_VERSION", "3.11"),
)
def test_integration(session):
"""Run integration tests (to check compatibility with databases)"""
_install(session, integration=True)
session.run(
"pytest",
"src/tests/integration",
"-k",
"not (snowflake or redshift or clickhouse)",
"-v",
)