mirror of https://github.com/python/cpython.git
bpo-45453: Fix test_embed.StdPrinterTests (GH-28916)
test_embed.StdPrinterTests now always use the file descriptor 1 for stdout, rather than using sys.__stdout__.fileno(). PyFile_NewStdPrinter() does crash if the argument is not 1 or 2. Fix also a few pyflakes warnings: remove unused import and variables.
This commit is contained in:
parent
c63623a0a6
commit
678433f25e
|
@ -13,7 +13,6 @@
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
@ -592,7 +591,6 @@ def _get_expected_config(self):
|
||||||
def get_expected_config(self, expected_preconfig, expected,
|
def get_expected_config(self, expected_preconfig, expected,
|
||||||
expected_pathconfig, env, api,
|
expected_pathconfig, env, api,
|
||||||
modify_path_cb=None):
|
modify_path_cb=None):
|
||||||
cls = self.__class__
|
|
||||||
configs = self._get_expected_config()
|
configs = self._get_expected_config()
|
||||||
|
|
||||||
pre_config = configs['pre_config']
|
pre_config = configs['pre_config']
|
||||||
|
@ -1248,7 +1246,6 @@ def test_init_setpythonhome(self):
|
||||||
self.fail(f"Unable to find home in {paths!r}")
|
self.fail(f"Unable to find home in {paths!r}")
|
||||||
|
|
||||||
prefix = exec_prefix = home
|
prefix = exec_prefix = home
|
||||||
ver = sys.version_info
|
|
||||||
expected_paths = self.module_search_paths(prefix=home, exec_prefix=home)
|
expected_paths = self.module_search_paths(prefix=home, exec_prefix=home)
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
@ -1549,8 +1546,7 @@ class StdPrinterTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
# "Set up a preliminary stderr printer until we have enough
|
# "Set up a preliminary stderr printer until we have enough
|
||||||
# infrastructure for the io module in place."
|
# infrastructure for the io module in place."
|
||||||
|
|
||||||
def get_stdout_fd(self):
|
STDOUT_FD = 1
|
||||||
return sys.__stdout__.fileno()
|
|
||||||
|
|
||||||
def create_printer(self, fd):
|
def create_printer(self, fd):
|
||||||
ctypes = import_helper.import_module('ctypes')
|
ctypes = import_helper.import_module('ctypes')
|
||||||
|
@ -1562,7 +1558,7 @@ def create_printer(self, fd):
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
message = "unicode:\xe9-\u20ac-\udc80!\n"
|
message = "unicode:\xe9-\u20ac-\udc80!\n"
|
||||||
|
|
||||||
stdout_fd = self.get_stdout_fd()
|
stdout_fd = self.STDOUT_FD
|
||||||
stdout_fd_copy = os.dup(stdout_fd)
|
stdout_fd_copy = os.dup(stdout_fd)
|
||||||
self.addCleanup(os.close, stdout_fd_copy)
|
self.addCleanup(os.close, stdout_fd_copy)
|
||||||
|
|
||||||
|
@ -1583,7 +1579,7 @@ def test_write(self):
|
||||||
self.assertEqual(data, message.encode('utf8', 'backslashreplace'))
|
self.assertEqual(data, message.encode('utf8', 'backslashreplace'))
|
||||||
|
|
||||||
def test_methods(self):
|
def test_methods(self):
|
||||||
fd = self.get_stdout_fd()
|
fd = self.STDOUT_FD
|
||||||
printer = self.create_printer(fd)
|
printer = self.create_printer(fd)
|
||||||
self.assertEqual(printer.fileno(), fd)
|
self.assertEqual(printer.fileno(), fd)
|
||||||
self.assertEqual(printer.isatty(), os.isatty(fd))
|
self.assertEqual(printer.isatty(), os.isatty(fd))
|
||||||
|
@ -1591,7 +1587,7 @@ def test_methods(self):
|
||||||
printer.close() # noop
|
printer.close() # noop
|
||||||
|
|
||||||
def test_disallow_instantiation(self):
|
def test_disallow_instantiation(self):
|
||||||
fd = self.get_stdout_fd()
|
fd = self.STDOUT_FD
|
||||||
printer = self.create_printer(fd)
|
printer = self.create_printer(fd)
|
||||||
support.check_disallow_instantiation(self, type(printer))
|
support.check_disallow_instantiation(self, type(printer))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue