app = ApplevelClass(''' #NOT_RPYTHON import unittest from test import test_support import sys def getmethods(suite_or_class): """ flatten out suites down to TestCase instances/methods. """ if isinstance(suite_or_class, unittest.TestCase): res = [suite_or_class] elif isinstance(suite_or_class, unittest.TestSuite): res = [] for x in suite_or_class._tests: res.extend(getmethods(x)) elif isinstance(suite_or_class, list): res = [] for x in suite_or_class: res.extend(getmethods(x)) else: raise TypeError, "expected TestSuite or TestClass, got %r" %(suite_or_class) return res # # exported API # def intercept_test_support(): """ intercept calls to test_support.run_doctest and run_suite. Return doctestmodules, suites which will hold collected items from these test_support invocations. """ suites = [] doctestmodules = [] def hack_run_doctest(module, verbose=None): doctestmodules.append(module) test_support.run_doctest = hack_run_doctest def hack_run_suite(suite, testclass=None): suites.append(suite) test_support.run_suite = hack_run_suite return suites, doctestmodules def collect_intercepted(suites, doctestmodules): namemethodlist = [] for method in getmethods(suites): name = (method.__class__.__name__ + '.' + method._TestCase__testMethodName) namemethodlist.append((name, method)) doctestlist = [] for mod in doctestmodules: doctestlist.append((mod.__name__, mod)) return namemethodlist, doctestlist def run_testcase_method(method): result = method.defaultTestResult() method.run(result) if result.errors: assert len(result.errors) print result.errors[0][1] if result.failures: assert len(result.failures) print result.failures[0][1] if result.failures or result.errors: return 1 def set_argv(filename): sys.argv[:] = ['python', filename] ''')
@unwrap_spec(name=str, startfrom=int) def call_method(self, name, w_args, startfrom=0): return call_method(self.space, self.b_obj, self.b_obj.GetType(), name, w_args, startfrom) @unwrap_spec(typename=str) def cli_object_new(space, w_subtype, typename, w_args): b_type = System.Type.GetType(typename) b_args, b_paramtypes = rewrap_args(space, w_args, 0) b_ctor = get_constructor(space, b_type, b_paramtypes) try: b_obj = b_ctor.Invoke(b_args) except TargetInvocationException, e: b_inner = native_exc(e).get_InnerException() message = str(b_inner.get_Message()) # TODO: use the appropriate exception, not StandardError raise OperationError(space.w_StandardError, space.wrap(message)) return space.wrap(W_CliObject(space, b_obj)) W_CliObject.typedef = TypeDef( '_CliObject_internal', __new__ = interp2app(cli_object_new), call_method = interp2app(W_CliObject.call_method), ) path, _ = os.path.split(__file__) app_clr = os.path.join(path, 'app_clr.py') app = ApplevelClass(file(app_clr).read()) del path, app_clr build_wrapper = app.interphook("build_wrapper") wrapper_from_cliobj = app.interphook("wrapper_from_cliobj")
def call_method(self, name, w_args, startfrom=0): return call_method(self.space, self.b_obj, self.b_obj.GetType(), name, w_args, startfrom) call_method.unwrap_spec = ['self', str, W_Root, int] def cli_object_new(space, w_subtype, typename, w_args): b_type = System.Type.GetType(typename) b_args, b_paramtypes = rewrap_args(space, w_args, 0) b_ctor = get_constructor(space, b_type, b_paramtypes) try: b_obj = b_ctor.Invoke(b_args) except TargetInvocationException, e: b_inner = native_exc(e).get_InnerException() message = str(b_inner.get_Message()) # TODO: use the appropriate exception, not StandardError raise OperationError(space.w_StandardError, space.wrap(message)) return space.wrap(W_CliObject(space, b_obj)) cli_object_new.unwrap_spec = [ObjSpace, W_Root, str, W_Root] W_CliObject.typedef = TypeDef( '_CliObject_internal', __new__ = interp2app(cli_object_new), call_method = interp2app(W_CliObject.call_method), ) path, _ = os.path.split(__file__) app_clr = os.path.join(path, 'app_clr.py') app = ApplevelClass(file(app_clr).read()) del path, app_clr build_wrapper = app.interphook("build_wrapper") wrapper_from_cliobj = app.interphook("wrapper_from_cliobj")
def call_method(self, name, w_args, startfrom=0): return call_method(self.space, self.b_obj, self.b_obj.GetType(), name, w_args, startfrom) call_method.unwrap_spec = ['self', str, W_Root, int] def cli_object_new(space, w_subtype, typename, w_args): b_type = System.Type.GetType(typename) b_args, b_paramtypes = rewrap_args(space, w_args, 0) b_ctor = get_constructor(space, b_type, b_paramtypes) try: b_obj = b_ctor.Invoke(b_args) except TargetInvocationException, e: b_inner = native_exc(e).get_InnerException() message = str(b_inner.get_Message()) # TODO: use the appropriate exception, not StandardError raise OperationError(space.w_StandardError, space.wrap(message)) return space.wrap(W_CliObject(space, b_obj)) cli_object_new.unwrap_spec = [ObjSpace, W_Root, str, W_Root] W_CliObject.typedef = TypeDef( '_CliObject_internal', __new__ = interp2app(cli_object_new), call_method = interp2app(W_CliObject.call_method), ) path, _ = os.path.split(__file__) app_clr = os.path.join(path, 'app_clr.py') app = ApplevelClass(file(app_clr).read()) del path, app_clr build_wrapper = app.interphook("build_wrapper")