Commit bb08b365 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #20373: generalize use of test.script_helper in test_warnings. Patch by Arfrever.

parent c92ea76f
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
from io import StringIO from io import StringIO
import sys import sys
import unittest import unittest
import subprocess
from test import support from test import support
from test.script_helper import assert_python_ok from test.script_helper import assert_python_ok
...@@ -719,47 +718,34 @@ class PyCatchWarningTests(CatchWarningTests, unittest.TestCase): ...@@ -719,47 +718,34 @@ class PyCatchWarningTests(CatchWarningTests, unittest.TestCase):
class EnvironmentVariableTests(BaseTest): class EnvironmentVariableTests(BaseTest):
def test_single_warning(self): def test_single_warning(self):
newenv = os.environ.copy() rc, stdout, stderr = assert_python_ok("-c",
newenv["PYTHONWARNINGS"] = "ignore::DeprecationWarning" "import sys; sys.stdout.write(str(sys.warnoptions))",
p = subprocess.Popen([sys.executable, PYTHONWARNINGS="ignore::DeprecationWarning")
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], self.assertEqual(stdout, b"['ignore::DeprecationWarning']")
stdout=subprocess.PIPE, env=newenv)
self.assertEqual(p.communicate()[0], b"['ignore::DeprecationWarning']")
self.assertEqual(p.wait(), 0)
def test_comma_separated_warnings(self): def test_comma_separated_warnings(self):
newenv = os.environ.copy() rc, stdout, stderr = assert_python_ok("-c",
newenv["PYTHONWARNINGS"] = ("ignore::DeprecationWarning," "import sys; sys.stdout.write(str(sys.warnoptions))",
"ignore::UnicodeWarning") PYTHONWARNINGS="ignore::DeprecationWarning,ignore::UnicodeWarning")
p = subprocess.Popen([sys.executable, self.assertEqual(stdout,
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']")
stdout=subprocess.PIPE, env=newenv)
self.assertEqual(p.communicate()[0],
b"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']")
self.assertEqual(p.wait(), 0)
def test_envvar_and_command_line(self): def test_envvar_and_command_line(self):
newenv = os.environ.copy() rc, stdout, stderr = assert_python_ok("-Wignore::UnicodeWarning", "-c",
newenv["PYTHONWARNINGS"] = "ignore::DeprecationWarning" "import sys; sys.stdout.write(str(sys.warnoptions))",
p = subprocess.Popen([sys.executable, "-W" "ignore::UnicodeWarning", PYTHONWARNINGS="ignore::DeprecationWarning")
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], self.assertEqual(stdout,
stdout=subprocess.PIPE, env=newenv) b"['ignore::UnicodeWarning', 'ignore::DeprecationWarning']")
self.assertEqual(p.communicate()[0],
b"['ignore::UnicodeWarning', 'ignore::DeprecationWarning']")
self.assertEqual(p.wait(), 0)
@unittest.skipUnless(sys.getfilesystemencoding() != 'ascii', @unittest.skipUnless(sys.getfilesystemencoding() != 'ascii',
'requires non-ascii filesystemencoding') 'requires non-ascii filesystemencoding')
def test_nonascii(self): def test_nonascii(self):
newenv = os.environ.copy() rc, stdout, stderr = assert_python_ok("-c",
newenv["PYTHONWARNINGS"] = "ignore:DeprecaciónWarning" "import sys; sys.stdout.write(str(sys.warnoptions))",
newenv["PYTHONIOENCODING"] = "utf-8" PYTHONIOENCODING="utf-8",
p = subprocess.Popen([sys.executable, PYTHONWARNINGS="ignore:DeprecaciónWarning")
"-c", "import sys; sys.stdout.write(str(sys.warnoptions))"], self.assertEqual(stdout,
stdout=subprocess.PIPE, env=newenv) "['ignore:DeprecaciónWarning']".encode('utf-8'))
self.assertEqual(p.communicate()[0],
"['ignore:DeprecaciónWarning']".encode('utf-8'))
self.assertEqual(p.wait(), 0)
class CEnvironmentVariableTests(EnvironmentVariableTests, unittest.TestCase): class CEnvironmentVariableTests(EnvironmentVariableTests, unittest.TestCase):
module = c_warnings module = c_warnings
...@@ -774,18 +760,11 @@ class BootstrapTest(unittest.TestCase): ...@@ -774,18 +760,11 @@ class BootstrapTest(unittest.TestCase):
# or not completely loaded (warnings imports indirectly encodings by # or not completely loaded (warnings imports indirectly encodings by
# importing linecache) yet # importing linecache) yet
with support.temp_cwd() as cwd, support.temp_cwd('encodings'): with support.temp_cwd() as cwd, support.temp_cwd('encodings'):
env = os.environ.copy()
env['PYTHONPATH'] = cwd
# encodings loaded by initfsencoding() # encodings loaded by initfsencoding()
retcode = subprocess.call([sys.executable, '-c', 'pass'], env=env) assert_python_ok('-c', 'pass', PYTHONPATH=cwd)
self.assertEqual(retcode, 0)
# Use -W to load warnings module at startup # Use -W to load warnings module at startup
retcode = subprocess.call( assert_python_ok('-c', 'pass', '-W', 'always', PYTHONPATH=cwd)
[sys.executable, '-c', 'pass', '-W', 'always'],
env=env)
self.assertEqual(retcode, 0)
def setUpModule(): def setUpModule():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment