Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Respond to review comments.
  • Loading branch information
warsaw committed Oct 24, 2025
commit 3bd8c8c202ebcfec1eed57842aee292cf672420c
18 changes: 9 additions & 9 deletions Lib/test/libregrtest/save_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
import sys
import threading

from importlib import import_module
from test import support
from test.support import os_helper

from .utils import print_warning

# Import termios to save and restore the tty. This is only available on
# Unix, and it's fine if the module can't be found.
try:
import termios

Check failure on line 15 in Lib/test/libregrtest/save_env.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

Lib/test/libregrtest/save_env.py:15:12: F401 `termios` imported but unused; consider using `importlib.util.find_spec` to test for availability
except ModuleNotFoundError:
pass
Comment thread
warsaw marked this conversation as resolved.


class SkipTestEnvironment(Exception):
pass
Expand Down Expand Up @@ -73,16 +79,11 @@
# function for restore() methods
return sys.modules[name]

def try_get_module(self, name, *, demand=False):
def try_get_module(self, name):
# function for get() methods
try:
return self.get_module(name)
except KeyError:
if demand:
try:
return import_module(name)
except ModuleNotFoundError:
pass
raise SkipTestEnvironment

def get_urllib_requests__url_tempfiles(self):
Expand Down Expand Up @@ -300,13 +301,12 @@
warnings.showwarning = fxn

def get_stty_echo(self):
termios = self.try_get_module('termios', demand=True)
termios = self.try_get_module('termios')
if not os.isatty(fd := sys.__stdin__.fileno()):
return None
attrs = termios.tcgetattr(fd)
lflags = attrs[3]
Comment thread
warsaw marked this conversation as resolved.
return bool(lflags & termios.ECHO)

def restore_stty_echo(self, echo):
termios = self.get_module('termios')
attrs = termios.tcgetattr(fd := sys.__stdin__.fileno())
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Preserve and restore the state of ``stty echo`` as a test environment.
Preserve and restore the state of ``stty echo`` as part of the test environment.
Loading