-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpython_version_test.rs
More file actions
428 lines (341 loc) · 16.4 KB
/
python_version_test.rs
File metadata and controls
428 lines (341 loc) · 16.4 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
use crate::python_version::{
DEFAULT_PYTHON_FULL_VERSION, DEFAULT_PYTHON_VERSION, LATEST_PYTHON_3_10, LATEST_PYTHON_3_11,
LATEST_PYTHON_3_12, LATEST_PYTHON_3_13, LATEST_PYTHON_3_14,
NEWEST_SUPPORTED_PYTHON_3_MINOR_VERSION, PythonVersion,
};
use crate::tests::default_build_config;
use indoc::{formatdoc, indoc};
use libcnb_test::{PackResult, TestRunner, assert_contains, assert_empty};
#[test]
#[ignore = "integration test"]
fn python_version_unspecified() {
let config = default_build_config("tests/fixtures/python_version_unspecified");
TestRunner::default().build(config, |context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
No Python version specified, using the current default of Python {DEFAULT_PYTHON_VERSION}.
We recommend setting an explicit version. In the root of your app create
a '.python-version' file, containing a Python version like '{DEFAULT_PYTHON_VERSION}'.
[Installing Python]
Installing Python {DEFAULT_PYTHON_FULL_VERSION}
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_3_10() {
builds_with_python_version("tests/fixtures/python_3.10", &LATEST_PYTHON_3_10);
}
#[test]
#[ignore = "integration test"]
fn python_3_11() {
builds_with_python_version("tests/fixtures/python_3.11", &LATEST_PYTHON_3_11);
}
#[test]
#[ignore = "integration test"]
fn python_3_12() {
builds_with_python_version("tests/fixtures/python_3.12", &LATEST_PYTHON_3_12);
}
#[test]
#[ignore = "integration test"]
fn python_3_13() {
builds_with_python_version("tests/fixtures/python_3.13", &LATEST_PYTHON_3_13);
}
#[test]
#[ignore = "integration test"]
fn python_3_14() {
builds_with_python_version("tests/fixtures/python_3.14", &LATEST_PYTHON_3_14);
}
fn builds_with_python_version(fixture_path: &str, python_version: &PythonVersion) {
let &PythonVersion {
major,
minor,
patch,
} = python_version;
TestRunner::default().build(default_build_config(fixture_path), |context| {
assert_empty!(context.pack_stderr);
if major == 3 && minor == 10 {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
Using Python version {major}.{minor} specified in .python-version
[Warning: Support for Python 3.10 is deprecated]
Python 3.10 will reach its upstream end-of-life in October 2026,
at which point it will no longer receive security updates:
https://devguide.python.org/versions/#supported-versions
As such, support for Python 3.10 will be removed from this
buildpack on 6th January 2027.
Upgrade to a newer Python version as soon as possible, by
changing the version in your .python-version file.
For more information, see:
https://devcenter.heroku.com/articles/python-support#supported-python-versions
[Installing Python]
Installing Python {major}.{minor}.{patch}
"}
);
} else {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
Using Python version {major}.{minor} specified in .python-version
[Installing Python]
Installing Python {major}.{minor}.{patch}
"}
);
}
// There's no sensible default process type we can set for Python apps.
assert_contains!(context.pack_stdout, "no default process type");
// Validate that the Python install works as expected at run-time.
let command_output = context.run_shell_command(
indoc! {r#"
set -euo pipefail
# Check that we installed the correct Python version, and that the command
# 'python' works (since it's a symlink to the actual 'python3' binary).
python --version
# Check that the Python binary is using its own 'libpython' and not the system one:
# https://github.com/docker-library/python/issues/784
libpython_path=$(ldd /layers/heroku_python/python/bin/python | grep libpython)
if [[ "${libpython_path}" != *"=> /layers/"* ]]; then
echo "The Python binary is not using the correct libpython!"
echo "${libpython_path}"
exit 1
fi
# Check all required dynamically linked libraries can be found in the run image.
ldd_output=$(find /layers -type f,l \( -name 'python3' -o -name '*.so*' \) -exec ldd '{}' +)
if grep 'not found' <<<"${ldd_output}" | sort --unique; then
echo "The above dynamically linked libraries were not found!"
exit 1
fi
"#}
);
assert_empty!(command_output.stderr);
assert_eq!(
command_output.stdout,
format!("Python {major}.{minor}.{patch}\n")
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_file_io_error() {
let mut config = default_build_config("tests/fixtures/python_version_file_invalid_unicode");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
indoc! {"
[Determining Python version]
[Error: Unable to read .python-version]
An I/O error occurred while reading the file:
/workspace/.python-version
Details: stream did not contain valid UTF-8
Check the file's permissions and that it contains valid UTF-8.
Then try building again.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_file_invalid_version() {
let mut config = default_build_config("tests/fixtures/python_version_file_invalid_version");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
[Error: Invalid Python version in .python-version]
The Python version specified in your .python-version file
isn't in the correct format.
The following version was found:
3.12.0�
However, the Python version must be specified as either:
1. The major version only, for example: {DEFAULT_PYTHON_VERSION} (recommended)
2. An exact patch version, for example: {DEFAULT_PYTHON_VERSION}.999
Don't include quotes, a 'python-' prefix or wildcards. Any
code comments must be on a separate line prefixed with '#'.
For example, to request the latest version of Python {DEFAULT_PYTHON_VERSION},
update your .python-version file so it contains exactly:
{DEFAULT_PYTHON_VERSION}
We strongly recommend that you don't specify the Python patch
version number, since it will pin your app to an exact Python
version and so stop your app from receiving security updates
each time it builds.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_file_multiple_versions() {
let mut config = default_build_config("tests/fixtures/python_version_file_multiple_versions");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
[Error: Invalid Python version in .python-version]
Multiple versions were found in your .python-version file:
// invalid comment
3.12
2.7
Update the file so it contains only one Python version.
For example, to request the latest version of Python {DEFAULT_PYTHON_VERSION},
update your .python-version file so it contains exactly:
{DEFAULT_PYTHON_VERSION}
If you have added comments to the file, make sure that those
lines begin with a '#', so that they are ignored.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_file_no_version() {
let mut config = default_build_config("tests/fixtures/python_version_file_no_version");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
[Error: Invalid Python version in .python-version]
No Python version was found in your .python-version file.
Update the file so that it contains your app's major Python
version number. Don't include quotes or a 'python-' prefix.
For example, to request the latest version of Python {DEFAULT_PYTHON_VERSION},
update your .python-version file so it contains exactly:
{DEFAULT_PYTHON_VERSION}
If the file already contains a version, check the line doesn't
begin with a '#', otherwise it will be treated as a comment.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_eol() {
let mut config = default_build_config("tests/fixtures/python_version_eol");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
[Error: The requested Python version has reached end-of-life]
Python 3.9 has reached its upstream end-of-life, and is
therefore no longer receiving security updates:
https://devguide.python.org/versions/#supported-versions
As such, it's no longer supported by this buildpack:
https://devcenter.heroku.com/articles/python-support#supported-python-versions
Please upgrade to at least Python 3.10 by changing the
version in your .python-version file.
If possible, we recommend upgrading all the way to Python {DEFAULT_PYTHON_VERSION},
since it contains many performance and usability improvements.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_non_existent_major() {
let mut config = default_build_config("tests/fixtures/python_version_non_existent_major");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
[Error: The requested Python version isn't recognised]
The requested Python version 3.99 isn't recognised.
Check that this Python version has been officially released,
and that the Python buildpack has added support for it:
https://devguide.python.org/versions/#supported-versions
https://devcenter.heroku.com/articles/python-support#supported-python-versions
If it has, make sure that you are using the latest version
of this buildpack, and haven't pinned to an older release
via a custom buildpack configuration in project.toml.
Otherwise, switch to a supported version (such as Python 3.{NEWEST_SUPPORTED_PYTHON_3_MINOR_VERSION})
by changing the version in your .python-version file.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn python_version_non_existent_minor() {
let mut config = default_build_config("tests/fixtures/python_version_non_existent_minor");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
Using Python version 3.12.999 specified in .python-version
[Installing Python]
Installing Python 3.12.999
[Error: The requested Python version isn't available]
Your app's .python-version file specifies a Python version
of 3.12.999, however, we couldn't find that version on S3.
Check that this Python version has been released upstream,
and that the Python buildpack has added support for it:
https://www.python.org/downloads/
https://github.com/heroku/buildpacks-python/blob/main/CHANGELOG.md
If it has, make sure that you are using the latest version
of this buildpack, and haven't pinned to an older release
via a custom buildpack configuration in project.toml.
We also strongly recommend that you don't pin your app to an
exact Python version such as 3.12.999, and instead only specify
the major Python version of 3.12 in your .python-version file.
This will allow your app to receive the latest available Python
patch version automatically, and prevent this type of error.
ERROR: failed to build: exit status 1
"}
);
});
}
#[test]
#[ignore = "integration test"]
fn runtime_txt() {
let mut config = default_build_config("tests/fixtures/runtime_txt_and_python_version_file");
config.expected_pack_result(PackResult::Failure);
TestRunner::default().build(config, |context| {
assert_contains!(
context.pack_stdout,
&formatdoc! {"
[Determining Python version]
[Error: The runtime.txt file isn't supported]
The runtime.txt file can no longer be used, since it has been
replaced by the more widely supported .python-version file.
Please delete your runtime.txt file and create a new file named:
.python-version
Make sure to include the '.' character at the start of the
filename. Don't add a file extension such as '.txt'.
In the new file, specify your app's major Python version number
only. Don't include quotes or a 'python-' prefix.
For example, to request the latest version of Python {DEFAULT_PYTHON_VERSION},
update your .python-version file so it contains exactly:
{DEFAULT_PYTHON_VERSION}
We strongly recommend that you don't specify the Python patch
version number, since it will pin your app to an exact Python
version and so stop your app from receiving security updates
each time it builds.
ERROR: failed to build: exit status 1
"}
);
});
}