From: Antoine Pitrou <solipsis@pitrou.net>
Date: Wed, 29 Jan 2014 22:45:07 +0000 (+0100)
Subject: Issue #20373: generalize use of test.script_helper in test_warnings.  Patch by Arfrever.
X-Git-Tag: v3.4.0rc1~178
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e5b2412c2162ca57a3c9f0882e9e2c71ade964e;p=python

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

0e5b2412c2162ca57a3c9f0882e9e2c71ade964e
diff --cc Lib/test/test_warnings.py
index ccdc65b5b5,10076af3aa..eec2c24218
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@@ -787,38 -760,12 +773,31 @@@ class BootstrapTest(unittest.TestCase)
          # or not completely loaded (warnings imports indirectly encodings by
          # importing linecache) yet
          with support.temp_cwd() as cwd, support.temp_cwd('encodings'):
-             env = os.environ.copy()
-             env['PYTHONPATH'] = cwd
- 
              # encodings loaded by initfsencoding()
-             retcode = subprocess.call([sys.executable, '-c', 'pass'], env=env)
-             self.assertEqual(retcode, 0)
+             assert_python_ok('-c', 'pass', PYTHONPATH=cwd)
  
              # Use -W to load warnings module at startup
-             retcode = subprocess.call(
-                 [sys.executable, '-c', 'pass', '-W', 'always'],
-                 env=env)
-             self.assertEqual(retcode, 0)
+             assert_python_ok('-c', 'pass', '-W', 'always', PYTHONPATH=cwd)
  
 +class FinalizationTest(unittest.TestCase):
 +    def test_finalization(self):
 +        # Issue #19421: warnings.warn() should not crash
 +        # during Python finalization
 +        code = """
 +import warnings
 +warn = warnings.warn
 +
 +class A:
 +    def __del__(self):
 +        warn("test")
 +
 +a=A()
 +        """
 +        rc, out, err = assert_python_ok("-c", code)
 +        # note: "__main__" filename is not correct, it should be the name
 +        # of the script
 +        self.assertEqual(err, b'__main__:7: UserWarning: test')
 +
  
  def setUpModule():
      py_warnings.onceregistry.clear()