mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	A few more test skips via import_module, and change import_module to
return the error message produced by importlib, so that if an import in the package whose import is being wrapped is what failed the skip message will contain the name of that module instead of the name of the wrapped module. Also fixed formatting of some previous comments.
This commit is contained in:
		
							parent
							
								
									9e0b363629
								
							
						
					
					
						commit
						597ebab744
					
				
					 10 changed files with 37 additions and 15 deletions
				
			
		| 
						 | 
					@ -4,11 +4,16 @@
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
import os, sys
 | 
					import os, sys
 | 
				
			||||||
import copy
 | 
					import copy
 | 
				
			||||||
import bsddb
 | 
					 | 
				
			||||||
import dbhash # Just so we know it's imported
 | 
					 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Skip test if _bsddb wasn't built.
 | 
				
			||||||
 | 
					test_support.import_module('_bsddb')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import bsddb
 | 
				
			||||||
 | 
					import dbhash # Just so we know it's imported
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestBSDDB(unittest.TestCase):
 | 
					class TestBSDDB(unittest.TestCase):
 | 
				
			||||||
    openflag = 'c'
 | 
					    openflag = 'c'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,8 +10,8 @@ import unittest
 | 
				
			||||||
from test.test_support import (requires, verbose, run_unittest, unlink, rmtree,
 | 
					from test.test_support import (requires, verbose, run_unittest, unlink, rmtree,
 | 
				
			||||||
    import_module)
 | 
					    import_module)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Skip test if bsddb cannot import _bsddb.
 | 
					# Skip test if _bsddb module was not built.
 | 
				
			||||||
import_module('bsddb')
 | 
					import_module('_bsddb')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# When running as a script instead of within the regrtest framework, skip the
 | 
					# When running as a script instead of within the regrtest framework, skip the
 | 
				
			||||||
# requires test, since it's obvious we want to run them.
 | 
					# requires test, since it's obvious we want to run them.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,12 +3,16 @@
 | 
				
			||||||
OS/2+EMX doesn't support the file locking operations.
 | 
					OS/2+EMX doesn't support the file locking operations.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
import fcntl
 | 
					 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import struct
 | 
					import struct
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
from test.test_support import verbose, TESTFN, unlink, run_unittest
 | 
					from test.test_support import (verbose, TESTFN, unlink, run_unittest,
 | 
				
			||||||
 | 
					    import_module)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Skip test if no fnctl module.
 | 
				
			||||||
 | 
					fcntl = import_module('fcntl')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO - Write tests for flock() and lockf().
 | 
					# TODO - Write tests for flock() and lockf().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,8 @@
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
aetools = test_support.import_module('aetools')
 | 
					# Skip this test if aetools does not exist.
 | 
				
			||||||
 | 
					test_support.import_module('aetools')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestScriptpackages(unittest.TestCase):
 | 
					class TestScriptpackages(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,8 +51,8 @@ def import_module(name, deprecated=False):
 | 
				
			||||||
                                    DeprecationWarning)
 | 
					                                    DeprecationWarning)
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            module = importlib.import_module(name)
 | 
					            module = importlib.import_module(name)
 | 
				
			||||||
        except ImportError:
 | 
					        except ImportError, msg:
 | 
				
			||||||
            raise unittest.SkipTest("No module named " + name)
 | 
					            raise unittest.SkipTest(str(msg))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return module
 | 
					            return module
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,8 +2,11 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import _tkinter
 | 
					 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Skip this test if the _tkinter module wasn't built.
 | 
				
			||||||
 | 
					_tkinter = test_support.import_module('_tkinter')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from Tkinter import Tcl
 | 
					from Tkinter import Tcl
 | 
				
			||||||
from _tkinter import TclError
 | 
					from _tkinter import TclError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,13 @@
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
import Tkinter
 | 
					 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Skip test if _tkinter wasn't built.
 | 
				
			||||||
 | 
					test_support.import_module('_tkinter')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import Tkinter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    Tkinter.Button()
 | 
					    Tkinter.Button()
 | 
				
			||||||
except Tkinter.TclError, msg:
 | 
					except Tkinter.TclError, msg:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,10 @@ import sys
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ttk = test_support.import_module('ttk')
 | 
					# Skip this test if _tkinter wasn't built.
 | 
				
			||||||
#If ttk exists _tkinter must exist.
 | 
					test_support.import_module('_tkinter')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ttk
 | 
				
			||||||
from _tkinter import TclError
 | 
					from _tkinter import TclError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,9 @@ import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Skip this test if _tkinter does not exist.
 | 
				
			||||||
 | 
					test_support.import_module('_tkinter')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
this_dir = os.path.dirname(os.path.abspath(__file__))
 | 
					this_dir = os.path.dirname(os.path.abspath(__file__))
 | 
				
			||||||
lib_tk_test = os.path.abspath(os.path.join(this_dir, '..', 'lib-tk', 'test'))
 | 
					lib_tk_test = os.path.abspath(os.path.join(this_dir, '..', 'lib-tk', 'test'))
 | 
				
			||||||
if lib_tk_test not in sys.path:
 | 
					if lib_tk_test not in sys.path:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,9 @@ import os, sys
 | 
				
			||||||
import unittest
 | 
					import unittest
 | 
				
			||||||
from test import test_support
 | 
					from test import test_support
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Do this first so test will be skipped if module doesn't exist
 | 
					# Do this first so test will be skipped if module doesn't exist
 | 
				
			||||||
test_support.import_module('_winreg')
 | 
					test_support.import_module('_winreg')
 | 
				
			||||||
#Now import everything
 | 
					# Now import everything
 | 
				
			||||||
from _winreg import *
 | 
					from _winreg import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me"
 | 
					test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue