]> granicus.if.org Git - python/commitdiff
Issue #20373: generalize use of test.script_helper in test_warnings. Patch by Arfrever.
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 29 Jan 2014 22:45:07 +0000 (23:45 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 29 Jan 2014 22:45:07 +0000 (23:45 +0100)
1  2 
Lib/test/test_warnings.py

index ccdc65b5b58dfe5ec63dcb086d0d03e01fd0e271,10076af3aab75a8f8bcd11320fe4decd0cc79db1..eec2c2421832bffc9705a3937a680af49b9b46dd
@@@ -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()