Skip to content

Commit 77e65a3

Browse files
committed
Add test
1 parent 2b758d0 commit 77e65a3

1 file changed

Lines changed: 89 additions & 3 deletions

File tree

tests/python/python_tests.bzl

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,27 @@ def _single_version_platform_override(
117117
patches = [],
118118
platform = "",
119119
python_version = "",
120+
python_version_env = None,
120121
sha256 = "",
122+
sha256_env = None,
121123
strip_prefix = "python",
122-
urls = []):
123-
if not platform or not python_version:
124-
fail("missing mandatory args: platform ({}) and python_version ({})".format(platform, python_version))
124+
strip_prefix_env = None,
125+
urls = [],
126+
url_env = None):
127+
if not platform:
128+
fail("missing mandatory arg: platform")
125129

126130
return struct(
127131
sha256 = sha256,
132+
sha256_env = sha256_env,
128133
urls = urls,
134+
url_env = url_env,
129135
strip_prefix = strip_prefix,
136+
strip_prefix_env = strip_prefix_env,
130137
platform = platform,
131138
coverage_tool = coverage_tool,
132139
python_version = python_version,
140+
python_version_env = python_version_env,
133141
patch_strip = patch_strip,
134142
patches = patches,
135143
target_compatible_with = [],
@@ -818,6 +826,84 @@ def _test_single_version_platform_override_errors(env):
818826

819827
_tests.append(_test_single_version_platform_override_errors)
820828

829+
def _test_single_version_platform_override_from_env(env):
830+
py = parse_modules(
831+
module_ctx = _mock_mctx(
832+
_mod(
833+
name = "my_module",
834+
toolchain = [_toolchain("3.13")],
835+
single_version_platform_override = [
836+
_single_version_platform_override(
837+
platform = "aarch64-unknown-linux-gnu",
838+
python_version_env = "PYTHON_VERSION_ENV",
839+
sha256_env = "SHA256_ENV",
840+
strip_prefix_env = "STRIP_PREFIX_ENV",
841+
url_env = "URL_ENV",
842+
),
843+
],
844+
override = [
845+
_override(
846+
available_python_versions = ["3.13.6"],
847+
),
848+
],
849+
),
850+
environ = {
851+
"PYTHON_VERSION_ENV": "3.13",
852+
"SHA256_ENV": "deadbeef",
853+
"STRIP_PREFIX_ENV": "my-prefix",
854+
"URL_ENV": "example.com,example.org",
855+
},
856+
),
857+
logger = repo_utils.logger(verbosity_level = 0, name = "python"),
858+
)
859+
860+
env.expect.that_dict(py.config.default["tool_versions"]["3.13.6"]).contains_exactly({
861+
"sha256": {"aarch64-unknown-linux-gnu": "deadbeef"},
862+
"strip_prefix": {"aarch64-unknown-linux-gnu": "my-prefix"},
863+
"url": {"aarch64-unknown-linux-gnu": ["example.com", "example.org"]},
864+
})
865+
866+
_tests.append(_test_single_version_platform_override_from_env)
867+
868+
# def _test_single_version_platform_override_from_env_minor_version(env):
869+
# py = parse_modules(
870+
# module_ctx = _mock_mctx(
871+
# _mod(
872+
# name = "my_module",
873+
# toolchain = [_toolchain("3.13")],
874+
# single_version_platform_override = [
875+
# _single_version_platform_override(
876+
# platform = "aarch64-unknown-linux-gnu",
877+
# python_version_env = "PYTHON_VERSION_ENV",
878+
# sha256_env = "SHA256_ENV",
879+
# strip_prefix_env = "STRIP_PREFIX_ENV",
880+
# url_env = "URL_ENV",
881+
# ),
882+
# ],
883+
# override = [
884+
# _override(
885+
# available_python_versions = ["3.13.6"],
886+
# ),
887+
# ],
888+
# ),
889+
# environ = {
890+
# "PYTHON_VERSION_ENV": "3.13",
891+
# "SHA256_ENV": "deadbeef",
892+
# "STRIP_PREFIX_ENV": "my-prefix",
893+
# "URL_ENV": "example.com,example.org",
894+
# },
895+
# ),
896+
# logger = repo_utils.logger(verbosity_level = 0, name = "python"),
897+
# )
898+
899+
# env.expect.that_dict(py.config.default["tool_versions"]["3.13.6"]).contains_exactly({
900+
# "sha256": {"aarch64-unknown-linux-gnu": "deadbeef"},
901+
# "strip_prefix": {"aarch64-unknown-linux-gnu": "my-prefix"},
902+
# "url": {"aarch64-unknown-linux-gnu": ["example.com", "example.org"]},
903+
# })
904+
905+
# _tests.append(_test_single_version_platform_override_from_env_minor_version)
906+
821907
# TODO @aignas 2024-09-03: add failure tests:
822908
# * incorrect platform failure
823909
# * missing python_version failure

0 commit comments

Comments
 (0)