qubes/tests: change globals= to module= and fix syntax errors
This commit is contained in:
		
							parent
							
								
									dfe7688158
								
							
						
					
					
						commit
						843bbdb2c5
					
				| @ -1127,7 +1127,7 @@ def list_templates(): | ||||
|             _templates = () | ||||
|     return _templates | ||||
| 
 | ||||
| def create_testcases_for_templates(name, *bases, globals, **kwds): | ||||
| def create_testcases_for_templates(name, *bases, module, **kwds): | ||||
|     '''Do-it-all helper for generating per-template tests via load_tests proto | ||||
| 
 | ||||
|     This does several things: | ||||
| @ -1149,27 +1149,24 @@ def create_testcases_for_templates(name, *bases, globals, **kwds): | ||||
|     ...     tests.addTests(loader.loadTestsFromNames( | ||||
|     ...         qubes.tests.create_testcases_for_templates( | ||||
|     ...             'TC_00_MyTests', MyTestsMixIn, qubes.tests.SystemTestCase, | ||||
|     ...             globals=globals()))) | ||||
|     ...             module=sys.modules[__name__]))) | ||||
| 
 | ||||
|     *NOTE* adding ``globals=globals()`` is *mandatory*, and to allow enforcing | ||||
|     this, it uses keyword-only argument syntax, which is Python 3 only. | ||||
|     *NOTE* adding ``module=sys.modules[__name__]`` is *mandatory*, and to allow | ||||
|     enforcing this, it uses keyword-only argument syntax, which is only in | ||||
|     Python 3. | ||||
|     ''' | ||||
|     # Do not attempt to grab the module from traceback, since we are actually | ||||
|     # a generator and loadTestsFromNames may also be a generator, so it's not | ||||
|     # possible to correctly guess frame from stack. Explicit is better than | ||||
|     # implicit! | ||||
| 
 | ||||
|     # NOTE globals is passed from calling function, and has slightly different | ||||
|     # semantics (no ``()``). | ||||
|     # | ||||
|     # Do not attempt to grab from traceback, since we are actually a generator | ||||
|     # and loadTestsFromNames may also be a generator, so it's not possible to | ||||
|     # correctly guess frame from stack. Explicit is better than implicit! | ||||
| 
 | ||||
|     module = globals['__name__'] | ||||
|     for template in list_templates(): | ||||
|         clsname = name + '_' + template | ||||
|         cls = type(clsname, bases, {'template': template, **kwds}) | ||||
|         cls.__module__ = module | ||||
|         cls.__module__ = module.__name__ | ||||
|         # XXX I wonder what other __dunder__ attrs did I miss | ||||
|         globals[clsname] = cls | ||||
|         yield '.'.join((module, clsname)) | ||||
|         setattr(module, clsname, cls) | ||||
|         yield '.'.join((module.__name__, clsname)) | ||||
| 
 | ||||
| def extra_info(obj): | ||||
|     '''Return short info identifying object. | ||||
|  | ||||
| @ -18,14 +18,14 @@ | ||||
| # USA. | ||||
| # | ||||
| 
 | ||||
| import asyncio | ||||
| import os | ||||
| import shutil | ||||
| import subprocess | ||||
| import sys | ||||
| import tempfile | ||||
| import unittest | ||||
| 
 | ||||
| import asyncio | ||||
| 
 | ||||
| import qubes | ||||
| import qubes.tests | ||||
| 
 | ||||
| @ -388,6 +388,6 @@ Test package | ||||
| def load_tests(loader, tests, pattern): | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('TC_00_Dom0Upgrade', | ||||
|             TC_00_Dom0UpgradeMixin, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             TC_00_Dom0UpgradeMixin, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     return tests | ||||
|  | ||||
| @ -25,8 +25,9 @@ import asyncio | ||||
| import multiprocessing | ||||
| import os | ||||
| import subprocess | ||||
| import unittest | ||||
| import sys | ||||
| import time | ||||
| import unittest | ||||
| 
 | ||||
| import qubes.tests | ||||
| import qubes.firewall | ||||
| @ -1325,14 +1326,14 @@ SHA256: | ||||
| def load_tests(loader, tests, pattern): | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('VmNetworking', | ||||
|             VmNetworkingMixin, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             VmNetworkingMixin, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('VmIPv6Networking', | ||||
|             VmIPv6NetworkingMixin, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             VmIPv6NetworkingMixin, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('VmUpdates', | ||||
|             VmUpdates, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             VmUpdates, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     return tests | ||||
|  | ||||
| @ -23,8 +23,11 @@ | ||||
| 
 | ||||
| import os | ||||
| import subprocess | ||||
| import sys | ||||
| import unittest | ||||
| 
 | ||||
| import qubes.tests | ||||
| 
 | ||||
| @unittest.skipUnless(os.path.exists('/var/lib/qubes/vm-kernels/pvgrub2'), | ||||
|                      'grub-xen package not installed') | ||||
| class TC_40_PVGrub(object): | ||||
| @ -138,6 +141,6 @@ class TC_40_PVGrub(object): | ||||
| def load_tests(loader, tests, pattern): | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('TC_40_PVGrub', | ||||
|             TC_40_PVGrub, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             TC_40_PVGrub, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     return tests | ||||
|  | ||||
| @ -17,13 +17,13 @@ | ||||
| # | ||||
| # You should have received a copy of the GNU General Public License along | ||||
| # with this program; if not, see <http://www.gnu.org/licenses/>. | ||||
| import os | ||||
| import subprocess | ||||
| import json | ||||
| 
 | ||||
| import shutil | ||||
| 
 | ||||
| import asyncio | ||||
| import json | ||||
| import os | ||||
| import shutil | ||||
| import subprocess | ||||
| import sys | ||||
| 
 | ||||
| import qubes.tests | ||||
| 
 | ||||
| @ -394,6 +394,6 @@ class SaltVMTestMixin(SaltTestMixin): | ||||
| def load_tests(loader, tests, pattern): | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('TC_10_VMSalt', | ||||
|             SaltVMTestMixin, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             SaltVMTestMixin, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     return tests | ||||
|  | ||||
| @ -23,6 +23,7 @@ import asyncio | ||||
| import multiprocessing | ||||
| import os | ||||
| import subprocess | ||||
| import sys | ||||
| import unittest | ||||
| 
 | ||||
| from distutils import spawn | ||||
| @ -1014,6 +1015,6 @@ class TC_10_Generic(qubes.tests.SystemTestCase): | ||||
| def load_tests(loader, tests, pattern): | ||||
|     tests.addTests(loader.loadTestsFromNames( | ||||
|         qubes.tests.create_testcases_for_templates('TC_00_AppVM', | ||||
|             TC_00_AppVMMixin, qubes.tests.SystemTestCase | ||||
|             globals=globals()))) | ||||
|             TC_00_AppVMMixin, qubes.tests.SystemTestCase, | ||||
|             module=sys.modules[__name__]))) | ||||
|     return tests | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Wojtek Porczyk
						Wojtek Porczyk