1
1
from __future__ import annotations
2
2
3
+ import logging
3
4
import sysconfig
4
5
import typing
5
6
from pathlib import Path
@@ -22,6 +23,53 @@ class VersionInfo(typing.NamedTuple):
22
23
releaselevel : str = "final"
23
24
24
25
26
+ def test_disallow_hardcoded (
27
+ tmp_path : Path ,
28
+ caplog : pytest .LogCaptureFixture ,
29
+ capsys : pytest .CaptureFixture [str ],
30
+ ):
31
+ caplog .set_level (logging .WARNING )
32
+ pyproject_toml = tmp_path / "pyproject.toml"
33
+ template = dedent (
34
+ """\
35
+ [tool.scikit-build]
36
+ strict-config = {strict_config}
37
+ fail = false
38
+ """
39
+ )
40
+
41
+ # First check without strict-config to make sure all fields are disallowed
42
+ strict_config = "false"
43
+ pyproject_toml .write_text (
44
+ template .format (strict_config = strict_config ),
45
+ encoding = "utf-8" ,
46
+ )
47
+
48
+ settings_reader = SettingsReader .from_file (pyproject_toml )
49
+ settings_reader .validate_may_exit ()
50
+ assert caplog .records
51
+ for idx , key in enumerate (["fail" ]):
52
+ assert (
53
+ f"{ key } is not allowed to be hard-coded in the pyproject.toml file"
54
+ in str (caplog .records [idx ].msg )
55
+ )
56
+
57
+ # Next check that this exits if string-config is set
58
+ strict_config = "true"
59
+ pyproject_toml .write_text (
60
+ template .format (strict_config = strict_config ),
61
+ encoding = "utf-8" ,
62
+ )
63
+ # Flush the capsys just in case
64
+ capsys .readouterr ()
65
+ settings_reader = SettingsReader .from_file (pyproject_toml )
66
+ with pytest .raises (SystemExit ) as exc :
67
+ settings_reader .validate_may_exit ()
68
+ assert exc .value .code == 7
69
+ out , _ = capsys .readouterr ()
70
+ assert "is not allowed to be hard-coded in the pyproject.toml file" in out
71
+
72
+
25
73
@pytest .mark .parametrize ("python_version" , ["3.9" , "3.10" ])
26
74
def test_skbuild_overrides_pyver (
27
75
python_version : str , tmp_path : Path , monkeypatch : pytest .MonkeyPatch
0 commit comments