def test__import_argmod_3(self): """Test SConsArguments.Importer._import_argmod('foo')""" with mock.patch('SConsArguments.Importer.GetDefaultArgpath') as mock_GetDefaultArgpath, \ mock.patch('SConsArguments.Importer._load_module_file') as mock_load_module_file: mock_GetDefaultArgpath.return_value = ['site_scons/site_arguments'] mock_load_module_file.side_effect = ImportError oldpath = sys.path with self.assertRaisesRegexp(RuntimeError, "No module named %s :" % 'foo'): tested._import_argmod('foo') self.assertEqual(sys.path, oldpath)
def test__import_argmod_2(self): """Test SConsArguments.Importer._import_argmod('foo')""" with mock.patch('SConsArguments.Importer.GetDefaultArgpath',) as mock_GetDefaultArgpath, \ mock.patch('SConsArguments.Importer._load_module_file') as mock_load_module_file: mock_GetDefaultArgpath.return_value = ['site_scons/site_arguments'] mock_load_module_file.return_value = 'xyz' oldpath = sys.path mod = tested._import_argmod('foo') self.assertEqual(mod, 'xyz') self.assertEqual(sys.path, oldpath)
def test__import_argmod_4(self): """Test SConsArguments.Importer._import_argmod(...)""" def fake_load_module_file(modname, path=None): if path == ['SConsArguments'] and modname == 'foo': return 'SConsArguments.foo' else: raise ImportError("bleah") with mock.patch('SConsArguments.Importer.GetDefaultArgpath') as mock_GetDefaultArgpath, \ mock.patch('SConsArguments.Importer._load_module_file') as mock_load_module_file: mock_GetDefaultArgpath.return_value = ['site_scons/site_arguments'] mock_load_module_file.side_effect = fake_load_module_file oldpath = sys.path with self.assertRaisesRegexp( RuntimeError, "No module named %s : %s" % ('bar', 'bleah')): tested._import_argmod('bar') self.assertEqual(sys.path, oldpath) oldpath = sys.path self.assertEqual(tested._import_argmod('foo'), 'SConsArguments.foo') self.assertEqual(sys.path, oldpath)
def test__import_argmod_1(self): """Test SConsArguments.Importer._import_argmod(sys)""" oldpath = sys.path mod = tested._import_argmod(sys) self.assertEqual(mod, sys)