| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  | import errno | 
					
						
							| 
									
										
										
										
											2012-04-14 14:10:13 -04:00
										 |  |  | import importlib | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  | import io | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  | import shutil | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  | import socket | 
					
						
							| 
									
										
										
										
											2016-11-20 16:16:06 +02:00
										 |  |  | import stat | 
					
						
							| 
									
										
										
										
											2017-11-20 15:24:56 -08:00
										 |  |  | import subprocess | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | import sys | 
					
						
							|  |  |  | import tempfile | 
					
						
							| 
									
										
										
										
											2018-02-23 02:37:38 +01:00
										 |  |  | import textwrap | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  | import time | 
					
						
							|  |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | from test import support | 
					
						
							| 
									
										
										
										
											2018-02-23 02:37:38 +01:00
										 |  |  | from test.support import script_helper | 
					
						
							| 
									
										
										
										
											2020-04-25 10:06:29 +03:00
										 |  |  | from test.support import socket_helper | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TESTFN = support.TESTFN | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestSupport(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_module(self): | 
					
						
							|  |  |  |         support.import_module("ftplib") | 
					
						
							|  |  |  |         self.assertRaises(unittest.SkipTest, support.import_module, "foo") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_import_fresh_module(self): | 
					
						
							|  |  |  |         support.import_fresh_module("ftplib") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_get_attribute(self): | 
					
						
							|  |  |  |         self.assertEqual(support.get_attribute(self, "test_get_attribute"), | 
					
						
							|  |  |  |                         self.test_get_attribute) | 
					
						
							|  |  |  |         self.assertRaises(unittest.SkipTest, support.get_attribute, self, "foo") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-23 15:00:31 +03:00
										 |  |  |     @unittest.skip("failing buildbots") | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |     def test_get_original_stdout(self): | 
					
						
							|  |  |  |         self.assertEqual(support.get_original_stdout(), sys.stdout) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_unload(self): | 
					
						
							|  |  |  |         import sched | 
					
						
							|  |  |  |         self.assertIn("sched", sys.modules) | 
					
						
							|  |  |  |         support.unload("sched") | 
					
						
							|  |  |  |         self.assertNotIn("sched", sys.modules) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_unlink(self): | 
					
						
							|  |  |  |         with open(TESTFN, "w") as f: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         support.unlink(TESTFN) | 
					
						
							|  |  |  |         self.assertFalse(os.path.exists(TESTFN)) | 
					
						
							|  |  |  |         support.unlink(TESTFN) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_rmtree(self): | 
					
						
							| 
									
										
										
										
											2016-11-20 16:16:06 +02:00
										 |  |  |         dirpath = support.TESTFN + 'd' | 
					
						
							|  |  |  |         subdirpath = os.path.join(dirpath, 'subdir') | 
					
						
							|  |  |  |         os.mkdir(dirpath) | 
					
						
							|  |  |  |         os.mkdir(subdirpath) | 
					
						
							|  |  |  |         support.rmtree(dirpath) | 
					
						
							|  |  |  |         self.assertFalse(os.path.exists(dirpath)) | 
					
						
							|  |  |  |         with support.swap_attr(support, 'verbose', 0): | 
					
						
							|  |  |  |             support.rmtree(dirpath) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         os.mkdir(dirpath) | 
					
						
							|  |  |  |         os.mkdir(subdirpath) | 
					
						
							|  |  |  |         os.chmod(dirpath, stat.S_IRUSR|stat.S_IXUSR) | 
					
						
							|  |  |  |         with support.swap_attr(support, 'verbose', 0): | 
					
						
							|  |  |  |             support.rmtree(dirpath) | 
					
						
							|  |  |  |         self.assertFalse(os.path.exists(dirpath)) | 
					
						
							| 
									
										
										
										
											2015-11-24 22:12:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-20 16:16:06 +02:00
										 |  |  |         os.mkdir(dirpath) | 
					
						
							|  |  |  |         os.mkdir(subdirpath) | 
					
						
							|  |  |  |         os.chmod(dirpath, 0) | 
					
						
							|  |  |  |         with support.swap_attr(support, 'verbose', 0): | 
					
						
							|  |  |  |             support.rmtree(dirpath) | 
					
						
							|  |  |  |         self.assertFalse(os.path.exists(dirpath)) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_forget(self): | 
					
						
							| 
									
										
										
										
											2011-08-02 06:24:31 +03:00
										 |  |  |         mod_filename = TESTFN + '.py' | 
					
						
							|  |  |  |         with open(mod_filename, 'w') as f: | 
					
						
							|  |  |  |             print('foo = 1', file=f) | 
					
						
							| 
									
										
										
										
											2011-08-03 05:18:33 +03:00
										 |  |  |         sys.path.insert(0, os.curdir) | 
					
						
							| 
									
										
										
										
											2012-04-14 14:10:13 -04:00
										 |  |  |         importlib.invalidate_caches() | 
					
						
							| 
									
										
										
										
											2011-08-02 06:24:31 +03:00
										 |  |  |         try: | 
					
						
							|  |  |  |             mod = __import__(TESTFN) | 
					
						
							|  |  |  |             self.assertIn(TESTFN, sys.modules) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             support.forget(TESTFN) | 
					
						
							|  |  |  |             self.assertNotIn(TESTFN, sys.modules) | 
					
						
							|  |  |  |         finally: | 
					
						
							| 
									
										
										
										
											2011-08-03 05:18:33 +03:00
										 |  |  |             del sys.path[0] | 
					
						
							| 
									
										
										
										
											2011-08-02 06:24:31 +03:00
										 |  |  |             support.unlink(mod_filename) | 
					
						
							| 
									
										
										
										
											2014-10-05 17:37:41 +02:00
										 |  |  |             support.rmtree('__pycache__') | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_HOST(self): | 
					
						
							| 
									
										
										
										
											2020-04-25 10:06:29 +03:00
										 |  |  |         s = socket.create_server((socket_helper.HOST, 0)) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |         s.close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_find_unused_port(self): | 
					
						
							| 
									
										
										
										
											2020-04-25 10:06:29 +03:00
										 |  |  |         port = socket_helper.find_unused_port() | 
					
						
							|  |  |  |         s = socket.create_server((socket_helper.HOST, port)) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |         s.close() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_bind_port(self): | 
					
						
							|  |  |  |         s = socket.socket() | 
					
						
							| 
									
										
										
										
											2020-04-25 10:06:29 +03:00
										 |  |  |         socket_helper.bind_port(s) | 
					
						
							| 
									
										
										
										
											2014-07-23 19:28:13 +01:00
										 |  |  |         s.listen() | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |         s.close() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  |     # Tests for temp_dir() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_temp_dir(self): | 
					
						
							|  |  |  |         """Test that temp_dir() creates and destroys its directory.""" | 
					
						
							|  |  |  |         parent_dir = tempfile.mkdtemp() | 
					
						
							|  |  |  |         parent_dir = os.path.realpath(parent_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             path = os.path.join(parent_dir, 'temp') | 
					
						
							|  |  |  |             self.assertFalse(os.path.isdir(path)) | 
					
						
							|  |  |  |             with support.temp_dir(path) as temp_path: | 
					
						
							|  |  |  |                 self.assertEqual(temp_path, path) | 
					
						
							|  |  |  |                 self.assertTrue(os.path.isdir(path)) | 
					
						
							|  |  |  |             self.assertFalse(os.path.isdir(path)) | 
					
						
							|  |  |  |         finally: | 
					
						
							| 
									
										
										
										
											2014-03-12 15:07:01 -05:00
										 |  |  |             support.rmtree(parent_dir) | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_temp_dir__path_none(self): | 
					
						
							|  |  |  |         """Test passing no path.""" | 
					
						
							|  |  |  |         with support.temp_dir() as temp_path: | 
					
						
							|  |  |  |             self.assertTrue(os.path.isdir(temp_path)) | 
					
						
							|  |  |  |         self.assertFalse(os.path.isdir(temp_path)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_temp_dir__existing_dir__quiet_default(self): | 
					
						
							|  |  |  |         """Test passing a directory that already exists.""" | 
					
						
							|  |  |  |         def call_temp_dir(path): | 
					
						
							|  |  |  |             with support.temp_dir(path) as temp_path: | 
					
						
							|  |  |  |                 raise Exception("should not get here") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         path = tempfile.mkdtemp() | 
					
						
							|  |  |  |         path = os.path.realpath(path) | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             self.assertTrue(os.path.isdir(path)) | 
					
						
							|  |  |  |             self.assertRaises(FileExistsError, call_temp_dir, path) | 
					
						
							|  |  |  |             # Make sure temp_dir did not delete the original directory. | 
					
						
							|  |  |  |             self.assertTrue(os.path.isdir(path)) | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             shutil.rmtree(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_temp_dir__existing_dir__quiet_true(self): | 
					
						
							|  |  |  |         """Test passing a directory that already exists with quiet=True.""" | 
					
						
							|  |  |  |         path = tempfile.mkdtemp() | 
					
						
							|  |  |  |         path = os.path.realpath(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             with support.check_warnings() as recorder: | 
					
						
							|  |  |  |                 with support.temp_dir(path, quiet=True) as temp_path: | 
					
						
							|  |  |  |                     self.assertEqual(path, temp_path) | 
					
						
							|  |  |  |                 warnings = [str(w.message) for w in recorder.warnings] | 
					
						
							|  |  |  |             # Make sure temp_dir did not delete the original directory. | 
					
						
							|  |  |  |             self.assertTrue(os.path.isdir(path)) | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             shutil.rmtree(path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 12:49:02 +01:00
										 |  |  |         self.assertEqual(len(warnings), 1, warnings) | 
					
						
							|  |  |  |         warn = warnings[0] | 
					
						
							|  |  |  |         self.assertTrue(warn.startswith(f'tests may fail, unable to create ' | 
					
						
							| 
									
										
										
										
											2017-02-08 15:49:10 +01:00
										 |  |  |                                         f'temporary directory {path!r}: '), | 
					
						
							| 
									
										
										
										
											2017-02-08 12:49:02 +01:00
										 |  |  |                         warn) | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-23 02:37:38 +01:00
										 |  |  |     @unittest.skipUnless(hasattr(os, "fork"), "test requires os.fork") | 
					
						
							|  |  |  |     def test_temp_dir__forked_child(self): | 
					
						
							|  |  |  |         """Test that a forked child process does not remove the directory.""" | 
					
						
							|  |  |  |         # See bpo-30028 for details. | 
					
						
							|  |  |  |         # Run the test as an external script, because it uses fork. | 
					
						
							|  |  |  |         script_helper.assert_python_ok("-c", textwrap.dedent("""
 | 
					
						
							|  |  |  |             import os | 
					
						
							|  |  |  |             from test import support | 
					
						
							|  |  |  |             with support.temp_cwd() as temp_path: | 
					
						
							|  |  |  |                 pid = os.fork() | 
					
						
							|  |  |  |                 if pid != 0: | 
					
						
							| 
									
										
										
										
											2020-03-31 20:08:12 +02:00
										 |  |  |                     # parent process | 
					
						
							| 
									
										
										
										
											2018-02-23 02:37:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     # wait for the child to terminate | 
					
						
							| 
									
										
										
										
											2020-03-31 20:08:12 +02:00
										 |  |  |                     support.wait_process(pid, exitcode=0) | 
					
						
							| 
									
										
										
										
											2018-02-23 02:37:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     # Make sure that temp_path is still present. When the child | 
					
						
							|  |  |  |                     # process leaves the 'temp_cwd'-context, the __exit__()- | 
					
						
							|  |  |  |                     # method of the context must not remove the temporary | 
					
						
							|  |  |  |                     # directory. | 
					
						
							|  |  |  |                     if not os.path.isdir(temp_path): | 
					
						
							|  |  |  |                         raise AssertionError("Child removed temp_path.") | 
					
						
							|  |  |  |         """))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  |     # Tests for change_cwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_change_cwd(self): | 
					
						
							|  |  |  |         original_cwd = os.getcwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         with support.temp_dir() as temp_path: | 
					
						
							|  |  |  |             with support.change_cwd(temp_path) as new_cwd: | 
					
						
							|  |  |  |                 self.assertEqual(new_cwd, temp_path) | 
					
						
							|  |  |  |                 self.assertEqual(os.getcwd(), new_cwd) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(os.getcwd(), original_cwd) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_change_cwd__non_existent_dir(self): | 
					
						
							|  |  |  |         """Test passing a non-existent directory.""" | 
					
						
							|  |  |  |         original_cwd = os.getcwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def call_change_cwd(path): | 
					
						
							|  |  |  |             with support.change_cwd(path) as new_cwd: | 
					
						
							|  |  |  |                 raise Exception("should not get here") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         with support.temp_dir() as parent_dir: | 
					
						
							|  |  |  |             non_existent_dir = os.path.join(parent_dir, 'does_not_exist') | 
					
						
							|  |  |  |             self.assertRaises(FileNotFoundError, call_change_cwd, | 
					
						
							|  |  |  |                               non_existent_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(os.getcwd(), original_cwd) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_change_cwd__non_existent_dir__quiet_true(self): | 
					
						
							|  |  |  |         """Test passing a non-existent directory with quiet=True.""" | 
					
						
							|  |  |  |         original_cwd = os.getcwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         with support.temp_dir() as parent_dir: | 
					
						
							|  |  |  |             bad_dir = os.path.join(parent_dir, 'does_not_exist') | 
					
						
							|  |  |  |             with support.check_warnings() as recorder: | 
					
						
							|  |  |  |                 with support.change_cwd(bad_dir, quiet=True) as new_cwd: | 
					
						
							|  |  |  |                     self.assertEqual(new_cwd, original_cwd) | 
					
						
							|  |  |  |                     self.assertEqual(os.getcwd(), new_cwd) | 
					
						
							|  |  |  |                 warnings = [str(w.message) for w in recorder.warnings] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 12:49:02 +01:00
										 |  |  |         self.assertEqual(len(warnings), 1, warnings) | 
					
						
							|  |  |  |         warn = warnings[0] | 
					
						
							|  |  |  |         self.assertTrue(warn.startswith(f'tests may fail, unable to change ' | 
					
						
							|  |  |  |                                         f'the current working directory ' | 
					
						
							| 
									
										
										
										
											2017-02-08 15:49:10 +01:00
										 |  |  |                                         f'to {bad_dir!r}: '), | 
					
						
							| 
									
										
										
										
											2017-02-08 12:49:02 +01:00
										 |  |  |                         warn) | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Tests for change_cwd() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_change_cwd__chdir_warning(self): | 
					
						
							|  |  |  |         """Check the warning message when os.chdir() fails.""" | 
					
						
							|  |  |  |         path = TESTFN + '_does_not_exist' | 
					
						
							|  |  |  |         with support.check_warnings() as recorder: | 
					
						
							|  |  |  |             with support.change_cwd(path=path, quiet=True): | 
					
						
							|  |  |  |                 pass | 
					
						
							|  |  |  |             messages = [str(w.message) for w in recorder.warnings] | 
					
						
							| 
									
										
										
										
											2017-02-08 12:49:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(len(messages), 1, messages) | 
					
						
							|  |  |  |         msg = messages[0] | 
					
						
							|  |  |  |         self.assertTrue(msg.startswith(f'tests may fail, unable to change ' | 
					
						
							|  |  |  |                                        f'the current working directory ' | 
					
						
							| 
									
										
										
										
											2017-02-08 15:49:10 +01:00
										 |  |  |                                        f'to {path!r}: '), | 
					
						
							| 
									
										
										
										
											2017-02-08 12:49:02 +01:00
										 |  |  |                         msg) | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Tests for temp_cwd() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |     def test_temp_cwd(self): | 
					
						
							|  |  |  |         here = os.getcwd() | 
					
						
							|  |  |  |         with support.temp_cwd(name=TESTFN): | 
					
						
							|  |  |  |             self.assertEqual(os.path.basename(os.getcwd()), TESTFN) | 
					
						
							|  |  |  |         self.assertFalse(os.path.exists(TESTFN)) | 
					
						
							| 
									
										
										
										
											2018-07-09 20:25:55 +05:00
										 |  |  |         self.assertEqual(os.getcwd(), here) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-28 22:11:50 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_temp_cwd__name_none(self): | 
					
						
							|  |  |  |         """Test passing None to temp_cwd().""" | 
					
						
							|  |  |  |         original_cwd = os.getcwd() | 
					
						
							|  |  |  |         with support.temp_cwd(name=None) as new_cwd: | 
					
						
							|  |  |  |             self.assertNotEqual(new_cwd, original_cwd) | 
					
						
							|  |  |  |             self.assertTrue(os.path.isdir(new_cwd)) | 
					
						
							|  |  |  |             self.assertEqual(os.getcwd(), new_cwd) | 
					
						
							|  |  |  |         self.assertEqual(os.getcwd(), original_cwd) | 
					
						
							| 
									
										
										
										
											2012-09-21 16:53:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |     def test_sortdict(self): | 
					
						
							|  |  |  |         self.assertEqual(support.sortdict({3:3, 2:2, 1:1}), "{1: 1, 2: 2, 3: 3}") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_make_bad_fd(self): | 
					
						
							|  |  |  |         fd = support.make_bad_fd() | 
					
						
							|  |  |  |         with self.assertRaises(OSError) as cm: | 
					
						
							|  |  |  |             os.write(fd, b"foo") | 
					
						
							|  |  |  |         self.assertEqual(cm.exception.errno, errno.EBADF) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_check_syntax_error(self): | 
					
						
							| 
									
										
										
										
											2018-09-24 17:12:49 -04:00
										 |  |  |         support.check_syntax_error(self, "def class", lineno=1, offset=5) | 
					
						
							| 
									
										
										
										
											2016-02-08 17:57:02 +01:00
										 |  |  |         with self.assertRaises(AssertionError): | 
					
						
							|  |  |  |             support.check_syntax_error(self, "x=1") | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_CleanImport(self): | 
					
						
							|  |  |  |         import importlib | 
					
						
							|  |  |  |         with support.CleanImport("asyncore"): | 
					
						
							|  |  |  |             importlib.import_module("asyncore") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_DirsOnSysPath(self): | 
					
						
							|  |  |  |         with support.DirsOnSysPath('foo', 'bar'): | 
					
						
							|  |  |  |             self.assertIn("foo", sys.path) | 
					
						
							|  |  |  |             self.assertIn("bar", sys.path) | 
					
						
							|  |  |  |         self.assertNotIn("foo", sys.path) | 
					
						
							|  |  |  |         self.assertNotIn("bar", sys.path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_captured_stdout(self): | 
					
						
							| 
									
										
										
										
											2013-07-11 12:28:40 -04:00
										 |  |  |         with support.captured_stdout() as stdout: | 
					
						
							| 
									
										
										
										
											2011-07-23 08:51:14 +03:00
										 |  |  |             print("hello") | 
					
						
							| 
									
										
										
										
											2013-07-11 12:28:40 -04:00
										 |  |  |         self.assertEqual(stdout.getvalue(), "hello\n") | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_captured_stderr(self): | 
					
						
							| 
									
										
										
										
											2013-07-11 12:28:40 -04:00
										 |  |  |         with support.captured_stderr() as stderr: | 
					
						
							| 
									
										
										
										
											2011-07-23 08:51:14 +03:00
										 |  |  |             print("hello", file=sys.stderr) | 
					
						
							| 
									
										
										
										
											2013-07-11 12:28:40 -04:00
										 |  |  |         self.assertEqual(stderr.getvalue(), "hello\n") | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_captured_stdin(self): | 
					
						
							| 
									
										
										
										
											2013-07-11 12:28:40 -04:00
										 |  |  |         with support.captured_stdin() as stdin: | 
					
						
							|  |  |  |             stdin.write('hello\n') | 
					
						
							|  |  |  |             stdin.seek(0) | 
					
						
							|  |  |  |             # call test code that consumes from sys.stdin | 
					
						
							|  |  |  |             captured = input() | 
					
						
							|  |  |  |         self.assertEqual(captured, "hello") | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_gc_collect(self): | 
					
						
							|  |  |  |         support.gc_collect() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_python_is_optimized(self): | 
					
						
							|  |  |  |         self.assertIsInstance(support.python_is_optimized(), bool) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_swap_attr(self): | 
					
						
							|  |  |  |         class Obj: | 
					
						
							| 
									
										
										
										
											2017-04-28 19:17:26 +03:00
										 |  |  |             pass | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |         obj = Obj() | 
					
						
							| 
									
										
										
										
											2017-04-28 19:17:26 +03:00
										 |  |  |         obj.x = 1 | 
					
						
							|  |  |  |         with support.swap_attr(obj, "x", 5) as x: | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |             self.assertEqual(obj.x, 5) | 
					
						
							| 
									
										
										
										
											2017-04-28 19:17:26 +03:00
										 |  |  |             self.assertEqual(x, 1) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |         self.assertEqual(obj.x, 1) | 
					
						
							| 
									
										
										
										
											2017-04-28 19:17:26 +03:00
										 |  |  |         with support.swap_attr(obj, "y", 5) as y: | 
					
						
							|  |  |  |             self.assertEqual(obj.y, 5) | 
					
						
							|  |  |  |             self.assertIsNone(y) | 
					
						
							|  |  |  |         self.assertFalse(hasattr(obj, 'y')) | 
					
						
							|  |  |  |         with support.swap_attr(obj, "y", 5): | 
					
						
							|  |  |  |             del obj.y | 
					
						
							|  |  |  |         self.assertFalse(hasattr(obj, 'y')) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def test_swap_item(self): | 
					
						
							| 
									
										
										
										
											2017-04-28 19:17:26 +03:00
										 |  |  |         D = {"x":1} | 
					
						
							|  |  |  |         with support.swap_item(D, "x", 5) as x: | 
					
						
							|  |  |  |             self.assertEqual(D["x"], 5) | 
					
						
							|  |  |  |             self.assertEqual(x, 1) | 
					
						
							|  |  |  |         self.assertEqual(D["x"], 1) | 
					
						
							|  |  |  |         with support.swap_item(D, "y", 5) as y: | 
					
						
							|  |  |  |             self.assertEqual(D["y"], 5) | 
					
						
							|  |  |  |             self.assertIsNone(y) | 
					
						
							|  |  |  |         self.assertNotIn("y", D) | 
					
						
							|  |  |  |         with support.swap_item(D, "y", 5): | 
					
						
							|  |  |  |             del D["y"] | 
					
						
							|  |  |  |         self.assertNotIn("y", D) | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 13:26:06 -07:00
										 |  |  |     class RefClass: | 
					
						
							|  |  |  |         attribute1 = None | 
					
						
							|  |  |  |         attribute2 = None | 
					
						
							|  |  |  |         _hidden_attribute1 = None | 
					
						
							|  |  |  |         __magic_1__ = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class OtherClass: | 
					
						
							|  |  |  |         attribute2 = None | 
					
						
							|  |  |  |         attribute3 = None | 
					
						
							|  |  |  |         __magic_1__ = None | 
					
						
							|  |  |  |         __magic_2__ = None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 12:56:53 -07:00
										 |  |  |     def test_detect_api_mismatch(self): | 
					
						
							| 
									
										
										
										
											2015-04-14 13:26:06 -07:00
										 |  |  |         missing_items = support.detect_api_mismatch(self.RefClass, | 
					
						
							|  |  |  |                                                     self.OtherClass) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:56:53 -07:00
										 |  |  |         self.assertEqual({'attribute1'}, missing_items) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 13:26:06 -07:00
										 |  |  |         missing_items = support.detect_api_mismatch(self.OtherClass, | 
					
						
							|  |  |  |                                                     self.RefClass) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:56:53 -07:00
										 |  |  |         self.assertEqual({'attribute3', '__magic_2__'}, missing_items) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_detect_api_mismatch__ignore(self): | 
					
						
							|  |  |  |         ignore = ['attribute1', 'attribute3', '__magic_2__', 'not_in_either'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 13:26:06 -07:00
										 |  |  |         missing_items = support.detect_api_mismatch( | 
					
						
							|  |  |  |                 self.RefClass, self.OtherClass, ignore=ignore) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:56:53 -07:00
										 |  |  |         self.assertEqual(set(), missing_items) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 13:26:06 -07:00
										 |  |  |         missing_items = support.detect_api_mismatch( | 
					
						
							|  |  |  |                 self.OtherClass, self.RefClass, ignore=ignore) | 
					
						
							| 
									
										
										
										
											2015-04-14 12:56:53 -07:00
										 |  |  |         self.assertEqual(set(), missing_items) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 11:47:00 +00:00
										 |  |  |     def test_check__all__(self): | 
					
						
							|  |  |  |         extra = {'tempdir'} | 
					
						
							|  |  |  |         blacklist = {'template'} | 
					
						
							|  |  |  |         support.check__all__(self, | 
					
						
							|  |  |  |                              tempfile, | 
					
						
							|  |  |  |                              extra=extra, | 
					
						
							|  |  |  |                              blacklist=blacklist) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         extra = {'TextTestResult', 'installHandler'} | 
					
						
							|  |  |  |         blacklist = {'load_tests', "TestProgram", "BaseTestSuite"} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         support.check__all__(self, | 
					
						
							|  |  |  |                              unittest, | 
					
						
							|  |  |  |                              ("unittest.result", "unittest.case", | 
					
						
							|  |  |  |                               "unittest.suite", "unittest.loader", | 
					
						
							|  |  |  |                               "unittest.main", "unittest.runner", | 
					
						
							| 
									
										
										
										
											2019-05-29 12:33:59 +03:00
										 |  |  |                               "unittest.signals", "unittest.async_case"), | 
					
						
							| 
									
										
										
										
											2015-11-14 11:47:00 +00:00
										 |  |  |                              extra=extra, | 
					
						
							|  |  |  |                              blacklist=blacklist) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertRaises(AssertionError, support.check__all__, self, unittest) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  |     @unittest.skipUnless(hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG'), | 
					
						
							|  |  |  |                          'need os.waitpid() and os.WNOHANG') | 
					
						
							|  |  |  |     def test_reap_children(self): | 
					
						
							|  |  |  |         # Make sure that there is no other pending child process | 
					
						
							|  |  |  |         support.reap_children() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Create a child process | 
					
						
							|  |  |  |         pid = os.fork() | 
					
						
							|  |  |  |         if pid == 0: | 
					
						
							|  |  |  |             # child process: do nothing, just exit | 
					
						
							|  |  |  |             os._exit(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         t0 = time.monotonic() | 
					
						
							| 
									
										
										
										
											2019-12-11 11:30:03 +01:00
										 |  |  |         deadline = time.monotonic() + support.SHORT_TIMEOUT | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         was_altered = support.environment_altered | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             support.environment_altered = False | 
					
						
							|  |  |  |             stderr = io.StringIO() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             while True: | 
					
						
							|  |  |  |                 if time.monotonic() > deadline: | 
					
						
							|  |  |  |                     self.fail("timeout") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-23 19:03:52 +02:00
										 |  |  |                 old_stderr = sys.__stderr__ | 
					
						
							|  |  |  |                 try: | 
					
						
							|  |  |  |                     sys.__stderr__ = stderr | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  |                     support.reap_children() | 
					
						
							| 
									
										
										
										
											2020-04-23 19:03:52 +02:00
										 |  |  |                 finally: | 
					
						
							|  |  |  |                     sys.__stderr__ = old_stderr | 
					
						
							| 
									
										
										
										
											2017-08-10 16:01:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 # Use environment_altered to check if reap_children() found | 
					
						
							|  |  |  |                 # the child process | 
					
						
							|  |  |  |                 if support.environment_altered: | 
					
						
							|  |  |  |                     break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 # loop until the child process completed | 
					
						
							|  |  |  |                 time.sleep(0.100) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             msg = "Warning -- reap_children() reaped child process %s" % pid | 
					
						
							|  |  |  |             self.assertIn(msg, stderr.getvalue()) | 
					
						
							|  |  |  |             self.assertTrue(support.environment_altered) | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             support.environment_altered = was_altered | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Just in case, check again that there is no other | 
					
						
							|  |  |  |         # pending child process | 
					
						
							|  |  |  |         support.reap_children() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 17:54:20 +01:00
										 |  |  |     def check_options(self, args, func, expected=None): | 
					
						
							| 
									
										
										
										
											2017-11-20 15:24:56 -08:00
										 |  |  |         code = f'from test.support import {func}; print(repr({func}()))' | 
					
						
							|  |  |  |         cmd = [sys.executable, *args, '-c', code] | 
					
						
							|  |  |  |         env = {key: value for key, value in os.environ.items() | 
					
						
							|  |  |  |                if not key.startswith('PYTHON')} | 
					
						
							|  |  |  |         proc = subprocess.run(cmd, | 
					
						
							|  |  |  |                               stdout=subprocess.PIPE, | 
					
						
							|  |  |  |                               stderr=subprocess.DEVNULL, | 
					
						
							|  |  |  |                               universal_newlines=True, | 
					
						
							|  |  |  |                               env=env) | 
					
						
							| 
									
										
										
										
											2018-11-23 17:54:20 +01:00
										 |  |  |         if expected is None: | 
					
						
							|  |  |  |             expected = args | 
					
						
							|  |  |  |         self.assertEqual(proc.stdout.rstrip(), repr(expected)) | 
					
						
							| 
									
										
										
										
											2017-11-20 15:24:56 -08:00
										 |  |  |         self.assertEqual(proc.returncode, 0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_args_from_interpreter_flags(self): | 
					
						
							|  |  |  |         # Test test.support.args_from_interpreter_flags() | 
					
						
							|  |  |  |         for opts in ( | 
					
						
							|  |  |  |             # no option | 
					
						
							|  |  |  |             [], | 
					
						
							|  |  |  |             # single option | 
					
						
							|  |  |  |             ['-B'], | 
					
						
							|  |  |  |             ['-s'], | 
					
						
							|  |  |  |             ['-S'], | 
					
						
							|  |  |  |             ['-E'], | 
					
						
							|  |  |  |             ['-v'], | 
					
						
							|  |  |  |             ['-b'], | 
					
						
							|  |  |  |             ['-q'], | 
					
						
							| 
									
										
										
										
											2018-11-23 17:54:20 +01:00
										 |  |  |             ['-I'], | 
					
						
							| 
									
										
										
										
											2017-11-20 15:24:56 -08:00
										 |  |  |             # same option multiple times | 
					
						
							|  |  |  |             ['-bb'], | 
					
						
							|  |  |  |             ['-vvv'], | 
					
						
							|  |  |  |             # -W options | 
					
						
							|  |  |  |             ['-Wignore'], | 
					
						
							|  |  |  |             # -X options | 
					
						
							|  |  |  |             ['-X', 'dev'], | 
					
						
							|  |  |  |             ['-Wignore', '-X', 'dev'], | 
					
						
							|  |  |  |             ['-X', 'faulthandler'], | 
					
						
							|  |  |  |             ['-X', 'importtime'], | 
					
						
							|  |  |  |             ['-X', 'showrefcount'], | 
					
						
							|  |  |  |             ['-X', 'tracemalloc'], | 
					
						
							|  |  |  |             ['-X', 'tracemalloc=3'], | 
					
						
							|  |  |  |         ): | 
					
						
							|  |  |  |             with self.subTest(opts=opts): | 
					
						
							|  |  |  |                 self.check_options(opts, 'args_from_interpreter_flags') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 17:54:20 +01:00
										 |  |  |         self.check_options(['-I', '-E', '-s'], 'args_from_interpreter_flags', | 
					
						
							|  |  |  |                            ['-I']) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-20 15:24:56 -08:00
										 |  |  |     def test_optim_args_from_interpreter_flags(self): | 
					
						
							|  |  |  |         # Test test.support.optim_args_from_interpreter_flags() | 
					
						
							|  |  |  |         for opts in ( | 
					
						
							|  |  |  |             # no option | 
					
						
							|  |  |  |             [], | 
					
						
							|  |  |  |             ['-O'], | 
					
						
							|  |  |  |             ['-OO'], | 
					
						
							|  |  |  |             ['-OOOO'], | 
					
						
							|  |  |  |         ): | 
					
						
							|  |  |  |             with self.subTest(opts=opts): | 
					
						
							|  |  |  |                 self.check_options(opts, 'optim_args_from_interpreter_flags') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |     def test_match_test(self): | 
					
						
							|  |  |  |         class Test: | 
					
						
							|  |  |  |             def __init__(self, test_id): | 
					
						
							|  |  |  |                 self.test_id = test_id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             def id(self): | 
					
						
							|  |  |  |                 return self.test_id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test_access = Test('test.test_os.FileTests.test_access') | 
					
						
							|  |  |  |         test_chdir = Test('test.test_os.Win32ErrorTests.test_chdir') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |         # Test acceptance | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |         with support.swap_attr(support, '_match_test_func', None): | 
					
						
							|  |  |  |             # match all | 
					
						
							|  |  |  |             support.set_match_tests([]) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 20:58:59 +01:00
										 |  |  |             # match all using None | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(None, None) | 
					
						
							| 
									
										
										
										
											2017-11-22 20:58:59 +01:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             # match the full test identifier | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests([test_access.id()], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # match the module name | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(['test_os'], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Test '*' pattern | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(['test_*'], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Test case sensitivity | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(['filetests'], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(['FileTests'], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Test pattern containing '.' and a '*' metacharacter | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(['*test_os.*.test_*'], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Multiple patterns | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests([test_access.id(), test_chdir.id()], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |             support.set_match_tests(['test_access', 'DONTMATCH'], None) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-19 23:46:49 +00:00
										 |  |  |         # Test rejection | 
					
						
							|  |  |  |         with support.swap_attr(support, '_match_test_func', None): | 
					
						
							|  |  |  |             # match all | 
					
						
							|  |  |  |             support.set_match_tests(ignore_patterns=[]) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # match all using None | 
					
						
							|  |  |  |             support.set_match_tests(None, None) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # match the full test identifier | 
					
						
							|  |  |  |             support.set_match_tests(None, [test_access.id()]) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # match the module name | 
					
						
							|  |  |  |             support.set_match_tests(None, ['test_os']) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Test '*' pattern | 
					
						
							|  |  |  |             support.set_match_tests(None, ['test_*']) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Test case sensitivity | 
					
						
							|  |  |  |             support.set_match_tests(None, ['filetests']) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_access)) | 
					
						
							|  |  |  |             support.set_match_tests(None, ['FileTests']) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Test pattern containing '.' and a '*' metacharacter | 
					
						
							|  |  |  |             support.set_match_tests(None, ['*test_os.*.test_*']) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             # Multiple patterns | 
					
						
							|  |  |  |             support.set_match_tests(None, [test_access.id(), test_chdir.id()]) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             support.set_match_tests(None, ['test_access', 'DONTMATCH']) | 
					
						
							|  |  |  |             self.assertFalse(support.match_test(test_access)) | 
					
						
							|  |  |  |             self.assertTrue(support.match_test(test_chdir)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 17:23:50 +02:00
										 |  |  |     def test_fd_count(self): | 
					
						
							|  |  |  |         # We cannot test the absolute value of fd_count(): on old Linux | 
					
						
							|  |  |  |         # kernel or glibc versions, os.urandom() keeps a FD open on | 
					
						
							|  |  |  |         # /dev/urandom device and Python has 4 FD opens instead of 3. | 
					
						
							|  |  |  |         start = support.fd_count() | 
					
						
							|  |  |  |         fd = os.open(__file__, os.O_RDONLY) | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             more = support.fd_count() | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             os.close(fd) | 
					
						
							|  |  |  |         self.assertEqual(more - start, 1) | 
					
						
							| 
									
										
										
										
											2017-11-21 15:34:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-23 19:03:52 +02:00
										 |  |  |     def check_print_warning(self, msg, expected): | 
					
						
							|  |  |  |         stderr = io.StringIO() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         old_stderr = sys.__stderr__ | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             sys.__stderr__ = stderr | 
					
						
							|  |  |  |             support.print_warning(msg) | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             sys.__stderr__ = old_stderr | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.assertEqual(stderr.getvalue(), expected) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_print_warning(self): | 
					
						
							|  |  |  |         self.check_print_warning("msg", | 
					
						
							|  |  |  |                                  "Warning -- msg\n") | 
					
						
							|  |  |  |         self.check_print_warning("a\nb", | 
					
						
							|  |  |  |                                  'Warning -- a\nWarning -- b\n') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  |     # XXX -follows a list of untested API | 
					
						
							|  |  |  |     # make_legacy_pyc | 
					
						
							|  |  |  |     # is_resource_enabled | 
					
						
							|  |  |  |     # requires | 
					
						
							|  |  |  |     # fcmp | 
					
						
							|  |  |  |     # umaks | 
					
						
							|  |  |  |     # findfile | 
					
						
							|  |  |  |     # check_warnings | 
					
						
							|  |  |  |     # EnvironmentVarGuard | 
					
						
							|  |  |  |     # TransientResource | 
					
						
							|  |  |  |     # transient_internet | 
					
						
							|  |  |  |     # run_with_locale | 
					
						
							|  |  |  |     # set_memlimit | 
					
						
							|  |  |  |     # bigmemtest | 
					
						
							|  |  |  |     # precisionbigmemtest | 
					
						
							|  |  |  |     # bigaddrspacetest | 
					
						
							|  |  |  |     # requires_resource | 
					
						
							|  |  |  |     # run_doctest | 
					
						
							|  |  |  |     # threading_cleanup | 
					
						
							|  |  |  |     # reap_threads | 
					
						
							|  |  |  |     # can_symlink | 
					
						
							|  |  |  |     # skip_unless_symlink | 
					
						
							| 
									
										
										
										
											2013-10-08 23:04:32 +02:00
										 |  |  |     # SuppressCrashReport | 
					
						
							| 
									
										
										
										
											2011-07-23 08:48:53 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_main(): | 
					
						
							|  |  |  |     tests = [TestSupport] | 
					
						
							|  |  |  |     support.run_unittest(*tests) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     test_main() |