Add failing test
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import platform as platform_module
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from cibuildwheel.__main__ import get_build_identifiers
|
||||
from cibuildwheel.bashlex_eval import local_environment_executor
|
||||
from cibuildwheel.environment import parse_environment
|
||||
from cibuildwheel.options import Options, _get_pinned_container_images
|
||||
|
||||
@@ -133,16 +136,53 @@ def test_toml_environment_evil(tmp_path, monkeypatch, env_var_value):
|
||||
args = get_default_command_line_arguments()
|
||||
args.package_dir = tmp_path
|
||||
|
||||
with tmp_path.joinpath("pyproject.toml").open("w") as f:
|
||||
f.write(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
[tool.cibuildwheel.environment]
|
||||
EXAMPLE='''{env_var_value}'''
|
||||
"""
|
||||
)
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
[tool.cibuildwheel.environment]
|
||||
EXAMPLE='''{env_var_value}'''
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
options = Options(platform="linux", command_line_arguments=args)
|
||||
parsed_environment = options.build_options(identifier=None).environment
|
||||
assert parsed_environment.as_dictionary(prev_environment={}) == {"EXAMPLE": env_var_value}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"toml_assignment,result_value",
|
||||
[
|
||||
('TEST_VAR="simple_value"', "simple_value"),
|
||||
# spaces
|
||||
('TEST_VAR="simple value"', "simple value"),
|
||||
# env var
|
||||
('TEST_VAR="$PARAM"', "spam"),
|
||||
('TEST_VAR="$PARAM $PARAM"', "spam spam"),
|
||||
# env var extension
|
||||
('TEST_VAR="before:$PARAM:after"', "before:spam:after"),
|
||||
# env var extension with spaces
|
||||
('TEST_VAR="before $PARAM after"', "before spam after"),
|
||||
],
|
||||
)
|
||||
def test_toml_environment_quoting(tmp_path: Path, toml_assignment, result_value):
|
||||
args = get_default_command_line_arguments()
|
||||
args.package_dir = tmp_path
|
||||
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
[tool.cibuildwheel.environment]
|
||||
{toml_assignment}
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
options = Options(platform="linux", command_line_arguments=args)
|
||||
parsed_environment = options.build_options(identifier=None).environment
|
||||
environment_values = parsed_environment.as_dictionary(
|
||||
prev_environment={**os.environ, "PARAM": "spam"},
|
||||
executor=local_environment_executor,
|
||||
)
|
||||
|
||||
assert environment_values["TEST_VAR"] == result_value
|
||||
|
||||
Reference in New Issue
Block a user