-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
Copy pathtest_discussion_2516.py
104 lines (89 loc) · 2.9 KB
/
test_discussion_2516.py
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
# Copyright 2024 Pex project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import absolute_import
import glob
import os.path
import subprocess
from textwrap import dedent
from pex.common import safe_open
from pex.scie import SciePlatform
from pex.typing import TYPE_CHECKING
from testing import make_env, run_pex_command
if TYPE_CHECKING:
from typing import Any
import colors # vendor:skip
else:
from pex.third_party import colors
def test_discussion_2516_op(tmpdir):
# type: (Any) -> None
requirements = os.path.join(str(tmpdir), "requirements-pex.txt")
with open(requirements, "w") as fp:
fp.write(
dedent(
"""\
ansicolors
cowsay
"""
)
)
with safe_open(os.path.join(str(tmpdir), "src", "ardia", "cli", "ardia.py"), "w") as fp:
fp.write(
dedent(
"""\
import sys
import colors
import cowsay
def main() -> None:
message = " ".join(sys.argv[1:])
cowsay.tux(colors.cyan(message))
"""
)
)
out_dir = os.path.join(str(tmpdir), "build", "pex")
for abbreviated_platform in (
"linux_aarch64-cp-3.11.9-cp311",
"linux_x86_64-cp-3.11.9-cp311",
"macosx_11_0_arm64-cp-3.11.9-cp311",
"macosx_11_0_x86_64-cp-3.11.9-cp311",
):
run_pex_command(
args=[
"--no-build",
"--requirement",
"requirements-pex.txt",
"--entry-point",
"ardia.cli.ardia:main",
"--package",
"ardia@src",
"--output-file",
os.path.join(out_dir, "ardia"),
"--scie",
"eager",
"--scie-only",
"--scie-name-style",
"platform-parent-dir",
"--platform",
abbreviated_platform,
],
cwd=str(tmpdir),
).assert_success()
assert sorted(
[
"build/pex/linux-aarch64/ardia",
"build/pex/linux-x86_64/ardia",
"build/pex/macos-aarch64/ardia",
"build/pex/macos-x86_64/ardia",
]
) == sorted(
os.path.relpath(os.path.join(root, f), str(tmpdir))
for root, _, files in os.walk(out_dir)
for f in files
)
assert not glob.glob(
os.path.join(str(tmpdir), "ardia*")
), "We expected no PEX or scie leaked in the CWD."
native_scie = os.path.join(out_dir, SciePlatform.CURRENT.value, "ardia")
output = subprocess.check_output(
args=[native_scie, "Tux", "says", "Moo?"], env=make_env(PATH=None)
).decode("utf-8")
assert "| {msg} |".format(msg=colors.cyan("Tux says Moo?")) in output, output