本文整理汇总了Python中Modules.get_init_file方法的典型用法代码示例。如果您正苦于以下问题:Python Modules.get_init_file方法的具体用法?Python Modules.get_init_file怎么用?Python Modules.get_init_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Modules
的用法示例。
在下文中一共展示了Modules.get_init_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_init_file_no_param_passed
# 需要导入模块: import Modules [as 别名]
# 或者: from Modules import get_init_file [as 别名]
def test_get_init_file_no_param_passed(self):
"""Test the method that gets called when script is run directly when
no params are passed"""
error = 'A single init file name parameter is required by ' \
'Modules.py when invoked directly'
with mock.patch.object(sys, 'argv', ['Modules']):
with self.assertRaisesRegexp(RuntimeError, error):
Modules.get_init_file()
示例2: test_get_init_file_no_file_found
# 需要导入模块: import Modules [as 别名]
# 或者: from Modules import get_init_file [as 别名]
def test_get_init_file_no_file_found(self):
"""Test the function that gets called when script is run directly
when no init file is returned"""
modules_home = {'MODULESHOME': '/dummy/path/1'}
which_side_effects = ['/path/to/modulecmd', None, None]
find_side_effects = [None, None]
with mock.patch.object(sys, 'argv', ['Modules', 'python']):
with mock.patch.dict(os.environ, modules_home), \
mock.patch('Modules.which',
side_effect=which_side_effects), \
mock.patch('Modules.find_first_binary',
return_value=None), \
mock.patch('Modules.find_file_in_list',
side_effect=find_side_effects), \
mock.patch('__builtin__.execfile') as exec_file:
error = 'Unable to determine init file for python in ' \
'Modules.py'
with self.assertRaisesRegexp(RuntimeError, error):
Modules.get_init_file()
exec_file.assert_not_called()
示例3: test_get_init_file
# 需要导入模块: import Modules [as 别名]
# 或者: from Modules import get_init_file [as 别名]
def test_get_init_file(self):
"""Test the method that gets called when script is run directly"""
modules_home = {'MODULESHOME': '/dummy/path/1'}
which_side_effects = ['/path/to/modulecmd', None, None]
find_side_effects = [None, '/fake/path/modules/init/python.py']
with mock.patch('sys.stdout', new_callable=StringIO) as output:
with mock.patch.object(sys, 'argv', ['Modules', 'python']):
with mock.patch.dict(os.environ, modules_home), \
mock.patch('Modules.which',
side_effect=which_side_effects), \
mock.patch('Modules.find_first_binary',
return_value='/fake/path/modulecmd'), \
mock.patch('Modules.find_file_in_list',
side_effect=find_side_effects), \
mock.patch('__builtin__.execfile') as exec_file:
Modules.get_init_file()
stdout = output.getvalue()
self.assertEqual('/fake/path/modules/init/python.py\n', stdout)
exec_file.assert_not_called()