Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
joerick committed Sep 17, 2022
1 parent 00b2600 commit 7b43ed4
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions unit_test/options_test.py
@@ -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

Expand Down Expand Up @@ -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

0 comments on commit 7b43ed4

Please sign in to comment.