示例#1
0
    def __get_module_from_str(self, modname, print_exception, pyfile):
        """ Import the module in the given import path.
            * Returns the "final" module, so importing "coilib40.subject.visu" 
            returns the "visu" module, not the "coilib40" as returned by __import__ """
        try:
            mod = __import__(modname)
            for part in modname.split('.')[1:]:
                mod = getattr(mod, part)
            return mod
        except:
            if print_exception:
                import pydev_runfiles_xml_rpc
                import pydevd_io
                buf_err = pydevd_io.StartRedirect(
                    keep_original_redirection=True, std='stderr')
                buf_out = pydevd_io.StartRedirect(
                    keep_original_redirection=True, std='stdout')
                try:
                    import traceback
                    traceback.print_exc()
                    sys.stderr.write(
                        'ERROR: Module: %s could not be imported (file: %s).\n'
                        % (modname, pyfile))
                finally:
                    pydevd_io.EndRedirect('stderr')
                    pydevd_io.EndRedirect('stdout')

                pydev_runfiles_xml_rpc.notifyTest('error', buf_out.getvalue(),
                                                  buf_err.getvalue(), pyfile,
                                                  modname, 0)

            return None
示例#2
0
    def __get_module_from_str(self, modname, print_exception, pyfile):
        """ Import the module in the given import path.
            * Returns the "final" module, so importing "coilib40.subject.visu"
            returns the "visu" module, not the "coilib40" as returned by __import__ """
        try:
            mod = __import__(modname)
            for part in modname.split('.')[1:]:
                mod = getattr(mod, part)
            return mod
        except:
            if print_exception:
                import pydev_runfiles_xml_rpc
                import pydevd_io
                buf_err = pydevd_io.StartRedirect(keep_original_redirection=True, std='stderr')
                buf_out = pydevd_io.StartRedirect(keep_original_redirection=True, std='stdout')
                try:
                    import traceback;traceback.print_exc()
                    sys.stderr.write('ERROR: Module: %s could not be imported (file: %s).\n' % (modname, pyfile))
                finally:
                    pydevd_io.EndRedirect('stderr')
                    pydevd_io.EndRedirect('stdout')

                pydev_runfiles_xml_rpc.notifyTest(
                    'error', buf_out.getvalue(), buf_err.getvalue(), pyfile, modname, 0)

            return None
 def reportCond(self, cond, filename, test, captured_output, error_contents, delta):
     '''
     @param filename: 'D:\\src\\mod1\\hello.py'
     @param test: 'TestCase.testMet1'
     @param cond: fail, error, ok
     '''
     time_str = '%.2f' % (delta,)
     pydev_runfiles_xml_rpc.notifyTest(cond, captured_output, error_contents, filename, test, time_str)
示例#4
0
 def reportCond(self, cond, filename, test, captured_output, error_contents, delta):
     '''
     @param filename: 'D:\\src\\mod1\\hello.py'
     @param test: 'TestCase.testMet1'
     @param cond: fail, error, ok
     '''
     time_str = '%.2f' % (delta,)
     pydev_runfiles_xml_rpc.notifyTest(cond, captured_output, error_contents, filename, test, time_str)
 def _reportErrors(self, errors, failures, captured_output, test_name, diff_time=''):
     error_contents = []
     for test, s in errors+failures:
         if type(s) == type((1,)): #If it's a tuple (for jython 2.1)
             sio = StringIO()
             traceback.print_exception(s[0], s[1], s[2], file=sio)
             s = sio.getvalue()
         error_contents.append(s)
     
     sep = '\n'+self.separator1
     error_contents = sep.join(error_contents)
     
     if errors and not failures:
         try:
             pydev_runfiles_xml_rpc.notifyTest(
                 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
         except:
             file_start = error_contents.find('File "')
             file_end = error_contents.find('", ', file_start)
             if file_start != -1 and file_end != -1:
                 file = error_contents[file_start+6:file_end]
             else:
                 file = '<unable to get file>'
             pydev_runfiles_xml_rpc.notifyTest(
                 'error', captured_output, error_contents, file, test_name, diff_time)
         
     elif failures and not errors:
         pydev_runfiles_xml_rpc.notifyTest(
             'fail', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
     
     else: #Ok, we got both, errors and failures. Let's mark it as an error in the end.
         pydev_runfiles_xml_rpc.notifyTest(
             'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
 def stopTest(self, test):
     end_time = time.time()
     pydevd_io.EndRedirect(std='both')
     
     _PythonTextTestResult.stopTest(self, test)
     
     captured_output = self.buf.getvalue()
     del self.buf
     error_contents = ''
     test_name = self.getTestName(test)
         
     
     diff_time = '%.2f' % (end_time - self.start_time)
     if not self._current_errors_stack and not self._current_failures_stack:
         pydev_runfiles_xml_rpc.notifyTest(
             'ok', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
     else:
         self._reportErrors(self._current_errors_stack, self._current_failures_stack, captured_output, test_name)
 def stopTest(self, test):
     end_time = time.time()
     pydevd_io.EndRedirect(std='both')
     
     _PythonTextTestResult.stopTest(self, test)
     
     captured_output = self.buf.getvalue()
     del self.buf
     error_contents = ''
     test_name = self.getTestName(test)
         
     
     diff_time = '%.2f' % (end_time - self.start_time)
     if not self._current_errors_stack and not self._current_failures_stack:
         pydev_runfiles_xml_rpc.notifyTest(
             'ok', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
     else:
         self._reportErrors(self._current_errors_stack, self._current_failures_stack, captured_output, test_name)
    def reportCond(self, cond, test, captured_output, error=''):
        '''
        @param cond: fail, error, ok
        '''

        # test.address() is something as:
        # ('D:\\workspaces\\temp\\test_workspace\\pytesting1\\src\\mod1\\hello.py', 'mod1.hello', 'TestCase.testMet1')
        #
        # and we must pass: location, test
        #    E.g.: ['D:\\src\\mod1\\hello.py', 'TestCase.testMet1']
        try:
            if hasattr(test, 'address'):
                address = test.address()
                address = address[0], address[2]
            else:
                # multiprocess
                try:
                    address = test[0], test[1]
                except TypeError:
                    # It may be an error at setup, in which case it's not really a test, but a Context object.
                    f = test.context.__file__
                    if f.endswith('.pyc'):
                        f = f[:-1]
                    address = f, '?'
        except:
            sys.stderr.write(
                "PyDev: Internal pydev error getting test address. Please report at the pydev bug tracker\n"
            )
            import traceback
            traceback.print_exc()
            sys.stderr.write("\n\n\n")
            address = '?', '?'

        error_contents = self.getIoFromError(error)
        try:
            time_str = '%.2f' % (time.time() - test._pydev_start_time)
        except:
            time_str = '?'

        pydev_runfiles_xml_rpc.notifyTest(cond, captured_output,
                                          error_contents, address[0],
                                          address[1], time_str)
示例#9
0
    def _reportErrors(self,
                      errors,
                      failures,
                      captured_output,
                      test_name,
                      diff_time=''):
        error_contents = []
        for test, s in errors + failures:
            if type(s) == type((1, )):  #If it's a tuple (for jython 2.1)
                sio = StringIO()
                traceback.print_exception(s[0], s[1], s[2], file=sio)
                s = sio.getvalue()
            error_contents.append(s)

        sep = '\n' + self.separator1
        error_contents = sep.join(error_contents)

        if errors and not failures:
            pydev_runfiles_xml_rpc.notifyTest('error', captured_output,
                                              error_contents,
                                              test.__pydev_pyfile__, test_name,
                                              diff_time)

        elif failures and not errors:
            pydev_runfiles_xml_rpc.notifyTest('fail', captured_output,
                                              error_contents,
                                              test.__pydev_pyfile__, test_name,
                                              diff_time)

        else:  #Ok, we got both, errors and failures. Let's mark it as an error in the end.
            pydev_runfiles_xml_rpc.notifyTest('error', captured_output,
                                              error_contents,
                                              test.__pydev_pyfile__, test_name,
                                              diff_time)
    def reportCond(self, cond, test, captured_output, error=''):
        '''
        @param cond: fail, error, ok
        '''

        # test.address() is something as:
        # ('D:\\workspaces\\temp\\test_workspace\\pytesting1\\src\\mod1\\hello.py', 'mod1.hello', 'TestCase.testMet1')
        #
        # and we must pass: location, test
        #    E.g.: ['D:\\src\\mod1\\hello.py', 'TestCase.testMet1']
        try:
            if hasattr(test, 'address'):
                address = test.address()
                address = address[0], address[2]
            else:
                # multiprocess
                try:
                    address = test[0], test[1]
                except TypeError:
                    # It may be an error at setup, in which case it's not really a test, but a Context object.
                    f = test.context.__file__
                    if f.endswith('.pyc'):
                        f = f[:-1]
                    address = f, '?'
        except:
            sys.stderr.write("PyDev: Internal pydev error getting test address. Please report at the pydev bug tracker\n")
            import traceback;traceback.print_exc()
            sys.stderr.write("\n\n\n")
            address = '?', '?'

        error_contents = self.getIoFromError(error)
        try:
            time_str = '%.2f' % (time.time() - test._pydev_start_time)
        except:
            time_str = '?'

        pydev_runfiles_xml_rpc.notifyTest(cond, captured_output, error_contents, address[0], address[1], time_str)
示例#11
0
    def reportCond(self, cond, test, captured_output, error=''):
        '''
        @param cond: fail, error, ok
        '''
        
        #test.address() is something as:
        #('D:\\workspaces\\temp\\test_workspace\\pytesting1\\src\\mod1\\hello.py', 'mod1.hello', 'TestCase.testMet1')
        #
        #and we must pass: location, test
        #    E.g.: ['D:\\src\\mod1\\hello.py', 'TestCase.testMet1']
        if hasattr(test, 'address'):
            address = test.address()
            address = address[0], address[2]
        else:
            #multiprocess
            address = test

        error_contents = self.getIoFromError(error)
        try:
            time_str = '%.2f' % (time.time() - test._pydev_start_time)
        except:
            time_str = '?'
            
        pydev_runfiles_xml_rpc.notifyTest(cond, captured_output, error_contents, address[0], address[1], time_str)
示例#12
0
 def stopTest(self, test):
     end_time = time.time()
     pydevd_io.EndRedirect(std='both')
     
     _PythonTextTestResult.stopTest(self, test)
     
     captured_output = self.buf.getvalue()
     del self.buf
     error_contents = ''
     try:
         test_name = test.__class__.__name__+"."+test._testMethodName
     except AttributeError:
         #Support for jython 2.1 (__testMethodName is pseudo-private in the test case)
         test_name = test.__class__.__name__+"."+test._TestCase__testMethodName
         
     
     diff_time = '%.2f' % (end_time - self.start_time)
     if not self._current_errors_stack and not self._current_failures_stack:
         pydev_runfiles_xml_rpc.notifyTest(
             'ok', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
     else:
         error_contents = []
         for test, s in self._current_errors_stack+self._current_failures_stack:
             if type(s) == type((1,)): #If it's a tuple (for jython 2.1)
                 sio = StringIO()
                 traceback.print_exception(s[0], s[1], s[2], file=sio)
                 s = sio.getvalue()
             error_contents.append(s)
         
         sep = '\n'+self.separator1
         error_contents = sep.join(error_contents)
         
         if self._current_errors_stack and not self._current_failures_stack:
             pydev_runfiles_xml_rpc.notifyTest(
                 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
             
         elif self._current_failures_stack and not self._current_errors_stack:
             pydev_runfiles_xml_rpc.notifyTest(
                 'fail', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
         
         else: #Ok, we got both, errors and failures. Let's mark it as an error in the end.
             pydev_runfiles_xml_rpc.notifyTest(
                 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
示例#13
0
 def stopTest(self, test):
     end_time = time.time()
     pydevd_io.EndRedirect(std='both')
     
     _PythonTextTestResult.stopTest(self, test)
     
     captured_output = self.buf.getvalue()
     del self.buf
     error_contents = ''
     try:
         test_name = test.__class__.__name__+"."+test._testMethodName
     except AttributeError:
         #Support for jython 2.1 (__testMethodName is pseudo-private in the test case)
         test_name = test.__class__.__name__+"."+test._TestCase__testMethodName
         
     
     diff_time = '%.2f' % (end_time - self.start_time)
     if not self._current_errors_stack and not self._current_failures_stack:
         pydev_runfiles_xml_rpc.notifyTest(
             'ok', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
     else:
         error_contents = []
         for test, s in self._current_errors_stack+self._current_failures_stack:
             if type(s) == type((1,)): #If it's a tuple (for jython 2.1)
                 sio = StringIO()
                 traceback.print_exception(s[0], s[1], s[2], file=sio)
                 s = sio.getvalue()
             error_contents.append(s)
         
         sep = '\n'+self.separator1
         error_contents = sep.join(error_contents)
         
         if self._current_errors_stack and not self._current_failures_stack:
             pydev_runfiles_xml_rpc.notifyTest(
                 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
             
         elif self._current_failures_stack and not self._current_errors_stack:
             pydev_runfiles_xml_rpc.notifyTest(
                 'fail', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
         
         else: #Ok, we got both, errors and failures. Let's mark it as an error in the end.
             pydev_runfiles_xml_rpc.notifyTest(
                 'error', captured_output, error_contents, test.__pydev_pyfile__, test_name, diff_time)
 def notifyTest(self, job_id, *args, **kwargs):
     pydev_runfiles_xml_rpc.notifyTest(*args, **kwargs)
     return True
示例#15
0
 def notifyTest(self, job_id, *args, **kwargs):
     pydev_runfiles_xml_rpc.notifyTest(*args, **kwargs)
     return True