Skip to content

Commit

Permalink
Fix for rlimit foreground test.
Browse files Browse the repository at this point in the history
Using the `TERM=dummy` environment fixed the prompt coloring issue.
Some minor changes to the test file itself and `setup.py` to avoid
IDE warnings.
  • Loading branch information
grouigrokon committed Oct 19, 2023
1 parent 8016bdb commit 76f6a34
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
19 changes: 18 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

from setuptools import setup, find_packages

import os
Expand All @@ -20,9 +22,24 @@
# There are some backward incompatible checks in typeguard 3.x
"typeguard<3.0.0",
],
"test": ["mock", "pytest-html", "pytest-socket", "ansi2html", "httpretty"],
"test": [
"mock",
"pytest",
"pytest-html",
"pytest-socket",
"ansi2html",
"httpretty",
"ptyprocess",
"psutil",
],
}

# Some IDEs are able to detect that packages are not in the setup.py. Still
# adding the package afterward does not work. Better set it in the default
# list, and remove it if needed.
if sys.platform == "win32":
extras_require["test"].remove("ptyprocess")

for p in ("darwin", "linux", "linux2", "win32"):
platform_string = ":sys_platform=='%s'" % p
extras_require[platform_string] = ["psutil"]
Expand Down
33 changes: 20 additions & 13 deletions tests/tests_e3/os/process/main_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import sys
import subprocess
Expand Down Expand Up @@ -107,7 +109,9 @@ def run_test():
if sys.platform == "win32":
# On Windows make sure that rlimit works when
# setting the build environment to 64bit windows
e = e3.env.Env()
from e3.env import Env

e = Env()
e.store()
e.set_build("x86_64-windows")
run_test()
Expand Down Expand Up @@ -205,6 +209,9 @@ def test_rlimit_foreground_option():

# Test with --foreground
os.environ["PS1"] = "$ "
# Use TERM=dummy to avoid prompt coloring to interfere with the result
# string.
os.environ["TERM"] = "dummy"
p = PtyProcess.spawn(
[e3.os.process.get_rlimit(), "--foreground", "30", "bash", "--norc", "-i"],
env=os.environ,
Expand All @@ -216,7 +223,7 @@ def test_rlimit_foreground_option():
# Ensure that the process is killed
p.kill(signal.SIGKILL)

# Test without foreground (Should failed)
# Test without foreground (Should fail)
p = PtyProcess.spawn(
[e3.os.process.get_rlimit(), "30", "bash", "--norc", "-i"],
env=os.environ,
Expand Down Expand Up @@ -391,7 +398,7 @@ def test_is_running():
assert e3.os.process.is_running(p.pid)
p.kill(recursive=False)

# On windows we don't want to wait as otherwise pid will be reused
# On windows, we don't want to wait as otherwise pid will be reused
# Note also that the semantic is slightly different between Unix
# and Windows. is_running will report false on Windows once the
# process is in a waitable state.
Expand All @@ -408,7 +415,9 @@ def test_is_running_non_existant():
pid_list = psutil.pids()
pid_list.sort()

# Try to found a non existing process
running: bool = True

# Try to found a non-existing process
for a in range(1, 1000):
running = e3.os.process.is_running(pid_list[-1] + a)
if not running:
Expand Down Expand Up @@ -506,14 +515,12 @@ def get_one_child(idx):

def test_run_with_env():
os.environ["EXT_VAR"] = "bar"
cmd = (
[
sys.executable,
"-c",
'import os; print(os.environ.get("TEST_RUN_VAR")'
' + os.environ.get("EXT_VAR", "world"))',
],
)
cmd = [
sys.executable,
"-c",
'import os; print(os.environ.get("TEST_RUN_VAR")'
' + os.environ.get("EXT_VAR", "world"))',
]
p1 = e3.os.process.Run(cmd, env={"TEST_RUN_VAR": "foo"}, ignore_environ=False)
assert p1.out.strip() == "foobar"

Expand All @@ -538,7 +545,7 @@ def test_no_rlimit(caplog):
def test_shell_override():
"""Unix shell shebang handling.
On windows we ensure that /bin/bash /bin/sh shebangs are replaced by
On windows, we ensure that /bin/bash /bin/sh shebangs are replaced by
SHELL env var.
"""
work_dir = os.getcwd()
Expand Down

0 comments on commit 76f6a34

Please sign in to comment.