当前位置: 首页>>代码示例>>Python>>正文


Python SourceFileLoader.main方法代码示例

本文整理汇总了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)
开发者ID:icometrix,项目名称:dicom2nifti,代码行数:28,代码来源:test_script_dicom2nifti.py

示例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)
开发者ID:aetel,项目名称:ieeextreme9,代码行数:34,代码来源:xtremetests.py

示例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)
开发者ID:icometrix,项目名称:dicom2nifti,代码行数:21,代码来源:test_script_dicom2nifti.py

示例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)
开发者ID:icometrix,项目名称:dicom2nifti,代码行数:24,代码来源:test_script_dicom2nifti.py


注:本文中的importlib.machinery.SourceFileLoader.main方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。