本文整理汇总了Python中importlib.machinery.SourceFileLoader.main方法的典型用法代码示例。如果您正苦于以下问题:Python SourceFileLoader.main方法的具体用法?Python SourceFileLoader.main怎么用?Python SourceFileLoader.main使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类importlib.machinery.SourceFileLoader
的用法示例。
在下文中一共展示了SourceFileLoader.main方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gantry_resampling
# 需要导入模块: from importlib.machinery import SourceFileLoader [as 别名]
# 或者: from importlib.machinery.SourceFileLoader import main [as 别名]
def test_gantry_resampling(self):
tmp_output_dir = tempfile.mkdtemp()
script_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'scripts',
'dicom2nifti')
assert os.path.isfile(script_file)
try:
if sys.version_info > (3, 0):
from importlib.machinery import SourceFileLoader
dicom2nifti_module = SourceFileLoader("dicom2nifti_script", script_file).load_module()
else:
import imp
dicom2nifti_module = imp.load_source('dicom2nifti_script', script_file)
dicom2nifti_module.main(['-G', '-r', '-o', '1', '-p', '-1000', test_data.FAILING_ORHTOGONAL, tmp_output_dir])
assert os.path.isfile(os.path.join(tmp_output_dir, "4_dicom2nifti.nii.gz"))
dicom2nifti_module.main(['--allow-gantry-tilting',
'--resample',
'--resample-order', '1',
'--resample-padding', '-1000',
test_data.FAILING_ORHTOGONAL,
tmp_output_dir])
assert os.path.isfile(os.path.join(tmp_output_dir, "4_dicom2nifti.nii.gz"))
finally:
shutil.rmtree(tmp_output_dir)
示例2: run_example
# 需要导入模块: from importlib.machinery import SourceFileLoader [as 别名]
# 或者: from importlib.machinery.SourceFileLoader import main [as 别名]
def run_example(self, theInput, theOutput):
# Import program (decrapted in 3.4, no other way at the moment)
from importlib.machinery import SourceFileLoader
solution = SourceFileLoader("solution", self.programPath).load_module()
# Feed the input
with PatchStd(theInput) as std:
# Start time counter
startTime = time.time()
# Run the program
solution.main()
# Get end time
endTime = time.time() - startTime
# Get memory (include current tests ~14MB but more or less is that)
mem = memory_usage(max_usage=True)
# Check output
actual_output = std.getStdOut().getvalue()
self.assertEqual(actual_output, theOutput)
# Print time (not do before because output is not yet retrieved)
std.restore()
print("\tTime: %.3f sec" % endTime)
print("\tMemory: %.3f MB" % mem)
# Show errors if any
errors = std.getStdErr().getvalue()
if errors != '':
print("\t" + errors)
示例3: test_main_function
# 需要导入模块: from importlib.machinery import SourceFileLoader [as 别名]
# 或者: from importlib.machinery.SourceFileLoader import main [as 别名]
def test_main_function(self):
tmp_output_dir = tempfile.mkdtemp()
script_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'scripts',
'dicom2nifti')
assert os.path.isfile(script_file)
try:
if sys.version_info > (3, 0):
from importlib.machinery import SourceFileLoader
dicom2nifti_module = SourceFileLoader("dicom2nifti_script", script_file).load_module()
else:
import imp
dicom2nifti_module = imp.load_source('dicom2nifti_script', script_file)
dicom2nifti_module.main([test_data.SIEMENS_ANATOMICAL, tmp_output_dir])
assert os.path.isfile(os.path.join(tmp_output_dir, "4_dicom2nifti.nii.gz"))
finally:
shutil.rmtree(tmp_output_dir)
示例4: test_multiframe_option
# 需要导入模块: from importlib.machinery import SourceFileLoader [as 别名]
# 或者: from importlib.machinery.SourceFileLoader import main [as 别名]
def test_multiframe_option(self):
tmp_output_dir = tempfile.mkdtemp()
script_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'scripts',
'dicom2nifti')
assert os.path.isfile(script_file)
try:
if sys.version_info > (3, 0):
from importlib.machinery import SourceFileLoader
dicom2nifti_module = SourceFileLoader("dicom2nifti_script", script_file).load_module()
else:
import imp
dicom2nifti_module = imp.load_source('dicom2nifti_script', script_file)
dicom2nifti_module.main(['-M', test_data.PHILIPS_ENHANCED_ANATOMICAL_IMPLICIT, tmp_output_dir])
assert os.path.isfile(os.path.join(tmp_output_dir, "301_dicom2nifti.nii.gz"))
dicom2nifti_module.main(
['--allow-multiframe-implicit', test_data.PHILIPS_ENHANCED_ANATOMICAL_IMPLICIT, tmp_output_dir])
assert os.path.isfile(os.path.join(tmp_output_dir, "301_dicom2nifti.nii.gz"))
finally:
shutil.rmtree(tmp_output_dir)