示例#1
0
def run_functional_test(pyx_file, keep_files=0):
    "Run a compile, link and execute test."
    try:
        mark_item(pyx_file, "failed")
        result = compile_and_link(pyx_file)
        aux_pyx_file = functional_test_aux_file(pyx_file)
        if os.path.exists(aux_pyx_file):
            aux_result = compile_and_link(aux_pyx_file)
        else:
            aux_result = None
        #new_c = compare_with_reference(result.c_file, show_diffs = 1)
        new_c = 0
        py_file = replace_suffix(pyx_file, "_t.py")
        out_file = replace_suffix(pyx_file, ".out")
        err_file = replace_suffix(pyx_file, ".err")
        try:
            stat = run_python_file(py_file, out_file, err_file)
        except:
            print_file(err_file)
            fail_with_exception("Python script execution failed.")
        if stat:
            fail("Exit status %s" % stat)
        new_output = compare_with_reference(
            out_file,
            show_diffs=0,
            line_munger=munge_runnable_test_output_line)
        if not keep_files:
            remove_file(replace_suffix(pyx_file, ".lis"))
            if not new_c:
                remove_file(result.c_file)
            remove_file(result.object_file)
            remove_file(result.extension_file)
            remove_file(err_file)
            if aux_result:
                remove_file(replace_suffix(aux_pyx_file, ".lis"))
                remove_file(aux_result.c_file)
                remove_file(aux_result.object_file)
                remove_file(aux_result.extension_file)
        mark_item(pyx_file, "passed")
        return "passed"
    except FailureError:
        return "failed"
示例#2
0
def run_tests_in_dir(dir):
    "Run all tests in given directory."
    #print "*** run_tests_in_dir:", dir ###
    print "Running tests in", dir
    items = glob_pyx(dir)
    result = "passed"
    for item in items:
        #print "*** run_tests_in_dir: doing file", item ###
        #item = path.join(dir, name)
        if run_test(item) <> "passed":
            result = "failed"
    names = os.listdir(dir)
    for name in names:
        if name not in ignore_dir_names:
            #print "*** run_tests_in_dir: checking name", name ###
            item = path.join(dir, name)
            if path.isdir(item):
                if run_test(item) <> "passed":
                    result = "failed"
    mark_item(dir, result)
    return result
示例#3
0
文件: Testing.py 项目: jwilk/Pyrex
def run_tests_in_dir(dir):
	"Run all tests in given directory."
	#print "*** run_tests_in_dir:", dir ###
	print "Running tests in", dir
	items = glob_pyx(dir)
	result = "passed"
	for item in items:
		#print "*** run_tests_in_dir: doing file", item ###
		#item = path.join(dir, name)
		if run_test(item) <> "passed":
			result = "failed"
	names = os.listdir(dir)
	for name in names:
		if name not in ignore_dir_names:
			#print "*** run_tests_in_dir: checking name", name ###
			item = path.join(dir, name)
			if path.isdir(item):
				if run_test(item) <> "passed":
					result = "failed"
	mark_item(dir, result)
	return result
示例#4
0
文件: Testing.py 项目: jwilk/Pyrex
def run_functional_test(pyx_file, keep_files = 0):
	"Run a compile, link and execute test."
	try:
		mark_item(pyx_file, "failed")
		result = compile_and_link(pyx_file)
		aux_pyx_file = functional_test_aux_file(pyx_file)
		if os.path.exists(aux_pyx_file):
			aux_result = compile_and_link(aux_pyx_file)
		else:
			aux_result = None
		#new_c = compare_with_reference(result.c_file, show_diffs = 1)
		new_c = 0
		py_file = replace_suffix(pyx_file, "_t.py")
		out_file = replace_suffix(pyx_file, ".out")
		err_file = replace_suffix(pyx_file, ".err")
		try:
			stat = run_python_file(py_file, out_file, err_file)
		except:
			print_file(err_file)
			fail_with_exception("Python script execution failed.")
		if stat:
			fail("Exit status %s" % stat)
		new_output = compare_with_reference(out_file, show_diffs = 0,
			line_munger = munge_runnable_test_output_line)
		if not keep_files:
			remove_file(replace_suffix(pyx_file, ".lis"))
			if not new_c:
				remove_file(result.c_file)
			remove_file(result.object_file)
			remove_file(result.extension_file)
			remove_file(err_file)
			if aux_result:
				remove_file(replace_suffix(aux_pyx_file, ".lis"))
				remove_file(aux_result.c_file)
				remove_file(aux_result.object_file)
				remove_file(aux_result.extension_file)
		mark_item(pyx_file, "passed")
		return "passed"
	except FailureError:
		return "failed"
示例#5
0
def run_compile_test(item, link=0):
    """Run a single compile-only or compile-and-link test.
	   If linking, the linked extension module is kept for use by later tests.
	"""
    try:
        mark_item(item, "failed")
        dir = path.dirname(item)
        name = path.basename(item)
        global mangled_module_name
        module_name, _ = os.path.splitext(name)
        mangled_module_name = "%d%s_" % (len(module_name), module_name)
        produces_include_files = name.startswith("i_") or name.startswith(
            "ia_")
        produces_api_file = name.startswith("a_") or name.startswith("ia_")
        is_error_test = (name[:2] == "e_" or name[:3] == "se_")
        options = Main.CompilationOptions(Main.default_options)
        if is_error_test:
            options.use_listing_file = 1
            options.errors_to_stderr = 0
        try:
            result = Main.compile(item, options)
        except CCompilerError:
            fail("C compilation error.")
        except:
            fail_with_exception("Exception raised in Pyrex compiler.")
        #print "result =", result.__dict__ ###
        if is_error_test:
            if result.num_errors == 0:
                fail("No errors produced, expected some")
            if result.listing_file is None:
                fail("No listing file produced")
            compare_with_reference(result.listing_file,
                                   show_diffs=0,
                                   line_munger=munge_error_line)
            remove_file(replace_suffix(item, ".c"))
            remove_file(replace_suffix(item, ".cpp"))
        else:
            if result.num_errors <> 0:
                #display_files(replace_suffix(item, ".lis"))
                fail("%s errors reported, expected none" % result.num_errors)
            if result.c_file is None:
                fail("No C file produced")
            compare_with_reference(result.c_file,
                                   show_diffs=1,
                                   line_munger=munge_c_line)
            if produces_include_files:
                if result.h_file is None:
                    fail("No header file produced")
                compare_with_reference(result.h_file,
                                       show_diffs=1,
                                       line_munger=munge_c_line)
                if result.i_file is None:
                    pass
                    # .pxi files no longer produced by default
                    #fail("No include file produced")
                else:
                    compare_with_reference(result.i_file,
                                           show_diffs=1,
                                           line_munger=None)
            if produces_api_file:
                if result.api_file is None:
                    fail("No api header file produced")
                compare_with_reference(result.api_file,
                                       show_diffs=1,
                                       line_munger=munge_c_line)
            try:
                result.object_file = c_compile(result.c_file)
            except CCompilerError:
                fail("C compilation error.")
            except:
                fail_with_exception("C compiler failed.")
            try:
                cplus_object_file = c_compile(result.c_file,
                                              cplus=1,
                                              obj_suffix=".cplus.o")
            except CCompilerError:
                fail("C++ compilation error.")
            except:
                fail_with_exception("C++ compiler failed.")
            if link:
                try:
                    c_link(result.object_file)
                except CCompilerError:
                    fail("C linking error.")
            remove_file(result.listing_file)
            remove_file(result.object_file)
            remove_file(cplus_object_file)
        mark_item(item, "passed")
        return "passed"
    except FailureError:
        return "failed"
示例#6
0
文件: Testing.py 项目: jwilk/Pyrex
def run_compile_test(item, link = 0):
	"""Run a single compile-only or compile-and-link test.
	   If linking, the linked extension module is kept for use by later tests.
	"""
	try:
		mark_item(item, "failed")
		dir = path.dirname(item)
		name = path.basename(item)
		global mangled_module_name
		module_name, _ = os.path.splitext(name)
		mangled_module_name = "%d%s_" % (len(module_name), module_name)
		produces_include_files = name.startswith("i_") or name.startswith("ia_")
		produces_api_file = name.startswith("a_") or name.startswith("ia_")
		is_error_test = (
			name[:2] == "e_" or
			name[:3] == "se_")
		options = Main.CompilationOptions(Main.default_options)
		if is_error_test:
			options.use_listing_file = 1
			options.errors_to_stderr = 0
		try:
			result = Main.compile(item, options)
		except CCompilerError:
			fail("C compilation error.")
		except:
			fail_with_exception("Exception raised in Pyrex compiler.")
		#print "result =", result.__dict__ ###
		if is_error_test:
			if result.num_errors == 0:
				fail("No errors produced, expected some")
			if result.listing_file is None:
				fail("No listing file produced")
			compare_with_reference(result.listing_file, show_diffs = 0,
				line_munger = munge_error_line)
			remove_file(replace_suffix(item, ".c"))
			remove_file(replace_suffix(item, ".cpp"))
		else:
			if result.num_errors <> 0:
				#display_files(replace_suffix(item, ".lis"))
				fail("%s errors reported, expected none" %
					result.num_errors)
			if result.c_file is None:
				fail("No C file produced")
			compare_with_reference(result.c_file, show_diffs = 1,
				line_munger = munge_c_line)
			if produces_include_files:
				if result.h_file is None:
					fail("No header file produced")
				compare_with_reference(result.h_file, show_diffs = 1,
					line_munger = munge_c_line)
				if result.i_file is None:
					pass
					# .pxi files no longer produced by default
					#fail("No include file produced")
				else:
					compare_with_reference(result.i_file, show_diffs = 1,
						line_munger = None)
			if produces_api_file:
				if result.api_file is None:
					fail("No api header file produced")
				compare_with_reference(result.api_file, show_diffs = 1,
					line_munger = munge_c_line)
			try:
				result.object_file = c_compile(result.c_file)
			except CCompilerError:
				fail("C compilation error.")
			except:
				fail_with_exception("C compiler failed.")
			try:
				cplus_object_file = c_compile(result.c_file, cplus = 1, obj_suffix = ".cplus.o")
			except CCompilerError:
				fail("C++ compilation error.")
			except:
				fail_with_exception("C++ compiler failed.")
			if link:
				try:
					c_link(result.object_file)
				except CCompilerError:
					fail("C linking error.")
			remove_file(result.listing_file)
			remove_file(result.object_file)
			remove_file(cplus_object_file)
		mark_item(item, "passed")
		return "passed"
	except FailureError:
		return "failed"