[Pydev-cvs] org.python.pydev/PySrc test_pyserver.py,1.5,1.6 test_refactoring.py,1.1,1.2 pycompletion
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-16 15:27:45
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24305/PySrc Modified Files: test_pyserver.py test_refactoring.py pycompletionserver.py refactoring.py Log Message: Making refactoring. Index: pycompletionserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/pycompletionserver.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pycompletionserver.py 15 Sep 2004 17:36:08 -0000 1.7 --- pycompletionserver.py 16 Sep 2004 15:27:25 -0000 1.8 *************** *** 10,25 **** HOST = '127.0.0.1' # Symbolic name meaning the local host ! MSG_KILL_SERVER = '@@KILL_SERVER_END@@' ! MSG_COMPLETIONS = '@@COMPLETIONS' ! MSG_END = 'END@@' ! MSG_GLOBALS = '@@GLOBALS:' ! MSG_TOKEN_GLOBALS = '@@TOKEN_GLOBALS(' ! MSG_CLASS_GLOBALS = '@@CLASS_GLOBALS(' ! MSG_INVALID_REQUEST = '@@INVALID_REQUEST' ! MSG_RELOAD_MODULES = '@@RELOAD_MODULES_END@@' ! MSG_CHANGE_DIR = '@@CHANGE_DIR:' ! MSG_OK = '@@MSG_OK_END@@' ! MSG_REFACTOR = '@@REFACTOR' ! MSG_PROCESSING = '@@PROCESSING_END@@' BUFFER_SIZE = 1024 --- 10,26 ---- HOST = '127.0.0.1' # Symbolic name meaning the local host ! MSG_KILL_SERVER = '@@KILL_SERVER_END@@' ! MSG_COMPLETIONS = '@@COMPLETIONS' ! MSG_END = 'END@@' ! MSG_GLOBALS = '@@GLOBALS:' ! MSG_TOKEN_GLOBALS = '@@TOKEN_GLOBALS(' ! MSG_CLASS_GLOBALS = '@@CLASS_GLOBALS(' ! MSG_INVALID_REQUEST = '@@INVALID_REQUEST' ! MSG_RELOAD_MODULES = '@@RELOAD_MODULES_END@@' ! MSG_CHANGE_DIR = '@@CHANGE_DIR:' ! MSG_OK = '@@MSG_OK_END@@' ! MSG_REFACTOR = '@@REFACTOR' ! MSG_PROCESSING = '@@PROCESSING_END@@' ! MSG_PROCESSING_PROGRESS = '@@PROCESSING:%sEND@@' BUFFER_SIZE = 1024 *************** *** 29,32 **** --- 30,34 ---- threading.Thread.__init__(self) self.socket = socket + self.processMsgFunc = None self.lastMsg = None *************** *** 34,41 **** time.sleep(0.1) while self.lastMsg == None: ! print 'sending', MSG_PROCESSING ! self.socket.send(MSG_PROCESSING) time.sleep(0.1) ! print 'sending', self.lastMsg self.socket.send(self.lastMsg) --- 36,48 ---- time.sleep(0.1) while self.lastMsg == None: ! ! if self.processMsgFunc != None: ! s = MSG_PROCESSING_PROGRESS % self.processMsgFunc() ! self.socket.send(s) ! else: ! self.socket.send(MSG_PROCESSING) time.sleep(0.1) ! ! #print 'sending', self.lastMsg self.socket.send(self.lastMsg) *************** *** 134,138 **** else: ! data = data[:data.find(MSG_END)] if data.startswith(MSG_GLOBALS): --- 141,145 ---- else: ! data = data[:data.rfind(MSG_END)] if data.startswith(MSG_GLOBALS): *************** *** 160,164 **** elif data.startswith(MSG_REFACTOR): data = data.replace(MSG_REFACTOR, '') ! returnMsg = refactoring.HandleRefactorMessage(data) else: --- 167,171 ---- elif data.startswith(MSG_REFACTOR): data = data.replace(MSG_REFACTOR, '') ! returnMsg = refactoring.HandleRefactorMessage(data, keepAliveThread) else: Index: test_refactoring.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_refactoring.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_refactoring.py 15 Sep 2004 17:36:08 -0000 1.1 --- test_refactoring.py 16 Sep 2004 15:27:25 -0000 1.2 *************** *** 29,37 **** FILE = 'temporary_file.py' - - class Test(unittest.TestCase): ! def getInitialFile(self): ! s = \ ''' class C: --- 29,35 ---- FILE = 'temporary_file.py' ! def getInitialFile(): ! s = \ ''' class C: *************** *** 41,46 **** c = a+b #this should be refactored. return c ''' ! return s def getRefactoredFile(self): --- 39,62 ---- c = a+b #this should be refactored. return c + c = C() ''' ! return s ! ! ! def getRenameRefactored(): ! s = \ ! ''' ! class G: ! def a(self): ! a = 2 ! b = 3 ! c = a+b #this should be refactored. ! return c ! c = G() ! ''' ! return s ! ! class Test(unittest.TestCase): ! def getRefactoredFile(self): *************** *** 51,60 **** a = 2 b = 3 ! c = self.plusMet(a, b) return c def plusMet(self, a, b): ! c = a+b #this should be refactored. ! return c ''' return s --- 67,76 ---- a = 2 b = 3 ! c = self.plusMet(a, b) #this should be refactored. return c def plusMet(self, a, b): ! return a+b ! c = C() ''' return s *************** *** 62,66 **** def setUp(self): unittest.TestCase.setUp(self) ! createFile(FILE, self.getInitialFile()) def tearDown(self): --- 78,82 ---- def setUp(self): unittest.TestCase.setUp(self) ! createFile(FILE, getInitialFile()) def tearDown(self): *************** *** 68,74 **** delete(FILE) ! def testIt(self): r = refactoring.Refactoring() ! s = r.extractMethod(FILE, 5+1, 0, 5+1, 44, 'plusMet') f = file(FILE, 'r') --- 84,90 ---- delete(FILE) ! def testExtractMethod(self): r = refactoring.Refactoring() ! s = r.extractMethod(FILE, 5+1, 12, 5+1, 12+3, 'plusMet') f = file(FILE, 'r') *************** *** 76,81 **** f.close() ! self.assertEquals(contents, self.getRefactoredFile()) ! if __name__ == '__main__': --- 92,107 ---- f.close() ! self.assertEquals(self.getRefactoredFile(), contents) ! ! def testRename(self): ! r = refactoring.Refactoring() ! s = r.renameByCoordinates(FILE, 1+1, 6, 'G') ! ! f = file(FILE, 'r') ! contents = f.read() ! f.close() ! ! self.assertEquals(getRenameRefactored(), contents) ! if __name__ == '__main__': Index: test_pyserver.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/test_pyserver.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_pyserver.py 15 Sep 2004 17:36:08 -0000 1.5 --- test_pyserver.py 16 Sep 2004 15:27:25 -0000 1.6 *************** *** 34,50 **** self.assertEquals('@@COMPLETIONS((Def,description),(Def1,description1),(Def2,description2))END@@', msg) ! def createConnections(self): ''' Creates the connections needed for testing. ''' ! t = pycompletionserver.T(50002,50003) t.start() sToWrite = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ! sToWrite.connect((pycompletionserver.HOST, 50002)) sToRead = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ! sToRead.bind((pycompletionserver.HOST, 50003)) sToRead.listen(1) #socket to receive messages. --- 34,50 ---- self.assertEquals('@@COMPLETIONS((Def,description),(Def1,description1),(Def2,description2))END@@', msg) ! def createConnections(self, p1 = 50002,p2 = 50003): ''' Creates the connections needed for testing. ''' ! t = pycompletionserver.T(p1,p2) t.start() sToWrite = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ! sToWrite.connect((pycompletionserver.HOST, p1)) sToRead = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ! sToRead.bind((pycompletionserver.HOST, p2)) sToRead.listen(1) #socket to receive messages. *************** *** 53,68 **** return t, sToWrite, sToRead, connToRead, addr - # def testRefactoring(self): - # t, sToWrite, sToRead, connToRead, addr = self.createConnections() - # self. def readMsg(self): msg = '@@PROCESSING_END@@' ! while msg == '@@PROCESSING_END@@': msg = self.connToRead.recv(1024*4) return msg ! def testSocketsAndMessages(self): t, sToWrite, sToRead, self.connToRead, addr = self.createConnections() --- 53,67 ---- return t, sToWrite, sToRead, connToRead, addr def readMsg(self): msg = '@@PROCESSING_END@@' ! while msg.startswith('@@PROCESSING'): msg = self.connToRead.recv(1024*4) + if msg.startswith('@@PROCESSING:'): + print 'Status msg:', msg return msg ! def testCompletionSocketsAndMessages(self): t, sToWrite, sToRead, self.connToRead, addr = self.createConnections() *************** *** 143,146 **** --- 142,146 ---- sToRead.close() sToWrite.close() + self.connToRead.close() def sendKillMsg(self, socket): *************** *** 148,151 **** --- 148,174 ---- + def testRefactoringSocketsAndMessages(self): + t, sToWrite, sToRead, self.connToRead, addr = self.createConnections(50002+2,50003+2) + + import refactoring + from test_refactoring import delete, createFile, FILE, getInitialFile, getRenameRefactored + createFile(FILE, getInitialFile()) + + sToWrite.send('@@REFACTORrenameByCoordinates %s %s %s %sEND@@'%(FILE, 1+1, 6, 'G')) + result = self.readMsg() + print 'result', result + + self.sendKillMsg(sToWrite) + + + while not hasattr(t, 'ended'): + pass #wait until it receives the message and quits. + + + sToRead.close() + sToWrite.close() + self.connToRead.close() + + if __name__ == '__main__': unittest.main() Index: refactoring.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/refactoring.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** refactoring.py 15 Sep 2004 17:36:08 -0000 1.2 --- refactoring.py 16 Sep 2004 15:27:25 -0000 1.3 *************** *** 16,21 **** --- 16,47 ---- def __init__(self): + self.progress = StringIO.StringIO() + self.warning = StringIO.StringIO() self.init() + + def getLastProgressMsg(self): + progress = self.progress.getvalue().split('\n') + msg = '' + i = -1 + while msg == '' and i > -5: + try: + msg = progress[i] + except: + msg = '' + i -= 1 + return msg + def getLastProgressMsgs(self, v): + progress = self.progress.getvalue().split('\n') + msg = '' + i = -1 + while i > -v: + try: + msg += progress[i]+'\n' + except: + pass + i -= 1 + return msg + def init(self): """ *************** *** 23,28 **** """ self.brmctx = bike.init() ! self.brmctx.setProgressLogger(sys.stdout) ! self.brmctx.setWarningLogger(sys.stderr) def handleReset(self): --- 49,54 ---- """ self.brmctx = bike.init() ! self.brmctx.setProgressLogger(self.progress) ! self.brmctx.setWarningLogger(self.warning) def handleReset(self): *************** *** 61,65 **** return __Refactoring ! def HandleRefactorMessage(msg): ''' The message received should have: the method of the class --- 87,102 ---- return __Refactoring ! def releaseRefactorerBuffers(): ! GetRefactorer().warning.close() ! GetRefactorer().progress.close() ! ! GetRefactorer().warning.__init__() ! GetRefactorer().progress.__init__() ! ! def restartRefactorer(): ! global __Refactoring ! __Refactoring = Refactoring() ! ! def HandleRefactorMessage(msg, keepAliveThread): ''' The message received should have: the method of the class *************** *** 69,83 **** func = msgSplit.pop(0) ! func = getattr(GetRefactorer(), func) try: ! return func(*msgSplit)+'END@@' except: import sys s = StringIO.StringIO() exc_info = sys.exc_info() print >> s, str(exc_info[1]) traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file = s) ! return 'ERROR: %s\nEND@@'%(s.getvalue()) --- 106,137 ---- func = msgSplit.pop(0) ! refactorer = GetRefactorer() ! func = getattr(refactorer, func) ! ! keepAliveThread.processMsgFunc = refactorer.getLastProgressMsg try: ! f = func(*msgSplit)+'END@@' ! releaseRefactorerBuffers() ! return f except: import sys s = StringIO.StringIO() exc_info = sys.exc_info() + print >> s, str(exc_info[1]) + + print >> s, '\nWARNINGS:\n' + print >> s, refactorer.warning.getvalue() + + print >> s, '\nPROGRESS:\n' + print >> s, refactorer.getLastProgressMsgs(8) + + print >> s, '\nDETAILS:\n' traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file = s) ! ! releaseRefactorerBuffers() ! restartRefactorer() ! return 'ERROR:%s\nEND@@'%(s.getvalue().replace('END@@','')) |