Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for rlimit foreground test. #647

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -9,6 +11,8 @@
import e3.os.fs
import e3.os.process

from e3.env import Env

import pytest

from subprocess import STDOUT
Expand Down Expand Up @@ -107,7 +111,7 @@ 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()
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
Loading