summaryrefslogtreecommitdiff
path: root/python/helpers/pydev/tests_python/test_debugger.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/helpers/pydev/tests_python/test_debugger.py')
-rw-r--r--python/helpers/pydev/tests_python/test_debugger.py510
1 files changed, 371 insertions, 139 deletions
diff --git a/python/helpers/pydev/tests_python/test_debugger.py b/python/helpers/pydev/tests_python/test_debugger.py
index 3a216cb64079..ea569ddce556 100644
--- a/python/helpers/pydev/tests_python/test_debugger.py
+++ b/python/helpers/pydev/tests_python/test_debugger.py
@@ -5,6 +5,17 @@
Note that it's a python script but it'll spawn a process to run as jython, ironpython and as python.
'''
+SHOW_WRITES_AND_READS = False
+SHOW_OTHER_DEBUG_INFO = False
+SHOW_STDOUT = False
+
+
+
+from pydevd_constants import IS_PY3K
+try:
+ from thread import start_new_thread
+except:
+ from _thread import start_new_thread
CMD_SET_PROPERTY_TRACE, CMD_EVALUATE_CONSOLE_EXPRESSION, CMD_RUN_CUSTOM_OPERATION, CMD_ENABLE_DONT_TRACE = 133, 134, 135, 141
PYTHON_EXE = None
IRONPYTHON_EXE = None
@@ -14,9 +25,13 @@ JAVA_LOCATION = None
import unittest
import pydev_localhost
-
port = None
+try:
+ xrange
+except:
+ xrange = range
+
def UpdatePort():
global port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -25,29 +40,26 @@ def UpdatePort():
s.close()
import os
-def NormFile(filename):
+def _get_debugger_test_file(filename):
try:
rPath = os.path.realpath # @UndefinedVariable
except:
# jython does not support os.path.realpath
# realpath is a no-op on systems without islink support
rPath = os.path.abspath
- return os.path.normcase(rPath(filename))
-
-PYDEVD_FILE = NormFile('../pydevd.py')
-import sys
-sys.path.append(os.path.dirname(PYDEVD_FILE))
+
+ return os.path.normcase(rPath(os.path.join(os.path.dirname(__file__), filename)))
-SHOW_WRITES_AND_READS = False
-SHOW_RESULT_STR = False
-SHOW_OTHER_DEBUG_INFO = False
+import pydevd
+PYDEVD_FILE = pydevd.__file__
+import sys
import subprocess
import socket
import threading
import time
-from urllib import quote_plus, quote, unquote_plus
+from pydev_imports import quote_plus, quote, unquote_plus
#=======================================================================================================================
@@ -59,13 +71,16 @@ class ReaderThread(threading.Thread):
threading.Thread.__init__(self)
self.setDaemon(True)
self.sock = sock
- self.lastReceived = None
+ self.lastReceived = ''
def run(self):
+ last_printed = None
try:
buf = ''
while True:
l = self.sock.recv(1024)
+ if IS_PY3K:
+ l = l.decode('utf-8')
buf += l
if '\n' in buf:
@@ -73,7 +88,9 @@ class ReaderThread(threading.Thread):
buf = ''
if SHOW_WRITES_AND_READS:
- print 'Test Reader Thread Received %s' % self.lastReceived.strip()
+ if last_printed != self.lastReceived.strip():
+ last_printed = self.lastReceived.strip()
+ print('Test Reader Thread Received %s' % last_printed)
except:
pass # ok, finished it
@@ -90,6 +107,8 @@ class AbstractWriterThread(threading.Thread):
self.setDaemon(True)
self.finishedOk = False
self._next_breakpoint_id = 0
+ self.log = []
+
def DoKill(self):
if hasattr(self, 'readerThread'):
@@ -98,10 +117,14 @@ class AbstractWriterThread(threading.Thread):
self.sock.close()
def Write(self, s):
+
last = self.readerThread.lastReceived
if SHOW_WRITES_AND_READS:
- print 'Test Writer Thread Written %s' % (s,)
- self.sock.send(s + '\n')
+ print('Test Writer Thread Written %s' % (s,))
+ msg = s + '\n'
+ if IS_PY3K:
+ msg = msg.encode('utf-8')
+ self.sock.send(msg)
time.sleep(0.2)
i = 0
@@ -112,16 +135,16 @@ class AbstractWriterThread(threading.Thread):
def StartSocket(self):
if SHOW_WRITES_AND_READS:
- print 'StartSocket'
+ print('StartSocket')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', port))
s.listen(1)
if SHOW_WRITES_AND_READS:
- print 'Waiting in socket.accept()'
+ print('Waiting in socket.accept()')
newSock, addr = s.accept()
if SHOW_WRITES_AND_READS:
- print 'Test Writer Thread Socket:', newSock, addr
+ print('Test Writer Thread Socket:', newSock, addr)
readerThread = self.readerThread = ReaderThread(newSock)
readerThread.start()
@@ -130,6 +153,7 @@ class AbstractWriterThread(threading.Thread):
self._sequence = -1
# initial command is always the version
self.WriteVersion()
+ self.log.append('StartSocket')
def NextBreakpointId(self):
self._next_breakpoint_id += 1
@@ -160,22 +184,27 @@ class AbstractWriterThread(threading.Thread):
109 is return
111 is breakpoint
'''
+ self.log.append('Start: WaitForBreakpointHit')
i = 0
# wait for hit breakpoint
- while not ('stop_reason="%s"' % reason) in self.readerThread.lastReceived:
+ last = self.readerThread.lastReceived
+ while not ('stop_reason="%s"' % reason) in last:
i += 1
time.sleep(1)
+ last = self.readerThread.lastReceived
if i >= 10:
raise AssertionError('After %s seconds, a break with reason: %s was not hit. Found: %s' % \
- (i, reason, self.readerThread.lastReceived))
+ (i, reason, last))
# we have something like <xml><thread id="12152656" stop_reason="111"><frame id="12453120" ...
- splitted = self.readerThread.lastReceived.split('"')
+ splitted = last.split('"')
threadId = splitted[1]
frameId = splitted[7]
if get_line:
+ self.log.append('End(0): WaitForBreakpointHit')
return threadId, frameId, int(splitted[13])
+ self.log.append('End(1): WaitForBreakpointHit')
return threadId, frameId
def WaitForCustomOperation(self, expected):
@@ -264,6 +293,7 @@ class AbstractWriterThread(threading.Thread):
def WriteMakeInitialRun(self):
self.Write("101\t%s\t" % self.NextSeq())
+ self.log.append('WriteMakeInitialRun')
def WriteVersion(self):
self.Write("501\t%s\t1.0\tWINDOWS\tID" % self.NextSeq())
@@ -274,6 +304,7 @@ class AbstractWriterThread(threading.Thread):
'''
breakpoint_id = self.NextBreakpointId()
self.Write("111\t%s\t%s\t%s\t%s\t%s\t%s\tNone\tNone" % (self.NextSeq(), breakpoint_id, 'python-line', self.TEST_FILE, line, func))
+ self.log.append('WriteAddBreakpoint: %s line: %s func: %s' % (breakpoint_id, line, func))
return breakpoint_id
def WriteRemoveBreakpoint(self, breakpoint_id):
@@ -284,6 +315,7 @@ class AbstractWriterThread(threading.Thread):
def WriteGetFrame(self, threadId, frameId):
self.Write("114\t%s\t%s\t%s\tFRAME" % (self.NextSeq(), threadId, frameId))
+ self.log.append('WriteGetFrame')
def WriteGetVariable(self, threadId, frameId, var_attrs):
self.Write("110\t%s\t%s\t%s\tFRAME\t%s" % (self.NextSeq(), threadId, frameId, var_attrs))
@@ -301,6 +333,7 @@ class AbstractWriterThread(threading.Thread):
self.Write("105\t%s\t%s" % (self.NextSeq(), threadId,))
def WriteRunThread(self, threadId):
+ self.log.append('WriteRunThread')
self.Write("106\t%s\t%s" % (self.NextSeq(), threadId,))
def WriteKillThread(self, threadId):
@@ -328,7 +361,7 @@ class AbstractWriterThread(threading.Thread):
#======================================================================================================================
class WriterThreadCase19(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case19.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case19.py')
def run(self):
self.StartSocket()
@@ -352,7 +385,7 @@ class WriterThreadCase19(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase18(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case18.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case18.py')
def run(self):
self.StartSocket()
@@ -372,7 +405,7 @@ class WriterThreadCase18(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase17(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case17.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case17.py')
def run(self):
self.StartSocket()
@@ -400,7 +433,7 @@ class WriterThreadCase17(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase16(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case16.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case16.py')
def run(self):
self.StartSocket()
@@ -430,8 +463,16 @@ class WriterThreadCase16(AbstractWriterThread):
self.WaitForVar('<var name="%27size%27')
self.WriteGetVariable(threadId, frameId, 'bigarray')
- self.WaitForVar(['<var name="min" type="int64" value="int64%253A 0" />', '<var name="size" type="int" value="int%3A 100000" />']) # TODO: When on a 32 bit python we get an int32 (which makes this test fail).
- self.WaitForVar(['<var name="max" type="int64" value="int64%253A 99999" />', '<var name="max" type="int32" value="int32%253A 99999" />'])
+ self.WaitForVar([
+ '<var name="min" type="int64" value="int64%253A 0" />',
+ '<var name="min" type="int64" value="int64%3A 0" />',
+ '<var name="size" type="int" value="int%3A 100000" />',
+ ])
+ self.WaitForVar([
+ '<var name="max" type="int64" value="int64%253A 99999" />',
+ '<var name="max" type="int32" value="int32%253A 99999" />',
+ '<var name="max" type="int64" value="int64%3A 99999"'
+ ])
self.WaitForVar('<var name="shape" type="tuple"')
self.WaitForVar('<var name="dtype" type="dtype"')
self.WaitForVar('<var name="size" type="int"')
@@ -441,8 +482,14 @@ class WriterThreadCase16(AbstractWriterThread):
# this one is different because it crosses the magic threshold where we don't calculate
# the min/max
self.WriteGetVariable(threadId, frameId, 'hugearray')
- self.WaitForVar('<var name="min" type="str" value="str%253A ndarray too big%252C calculating min would slow down debugging" />')
- self.WaitForVar('<var name="max" type="str" value="str%253A ndarray too big%252C calculating max would slow down debugging" />')
+ self.WaitForVar([
+ '<var name="min" type="str" value="str%253A ndarray too big%252C calculating min would slow down debugging" />',
+ '<var name="min" type="str" value="str%3A ndarray too big%252C calculating min would slow down debugging" />',
+ ])
+ self.WaitForVar([
+ '<var name="max" type="str" value="str%253A ndarray too big%252C calculating max would slow down debugging" />',
+ '<var name="max" type="str" value="str%3A ndarray too big%252C calculating max would slow down debugging" />',
+ ])
self.WaitForVar('<var name="shape" type="tuple"')
self.WaitForVar('<var name="dtype" type="dtype"')
self.WaitForVar('<var name="size" type="int"')
@@ -458,7 +505,7 @@ class WriterThreadCase16(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase15(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case15.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case15.py')
def run(self):
self.StartSocket()
@@ -472,7 +519,7 @@ class WriterThreadCase15(AbstractWriterThread):
self.WaitForCustomOperation('val=Black')
assert 7 == self._sequence, 'Expected 7. Had: %s' % self._sequence
- self.WriteCustomOperation("%s\t%s\tEXPRESSION\tcarObj.color" % (threadId, frameId), "EXECFILE", NormFile('_debugger_case15_execfile.py'), "f")
+ self.WriteCustomOperation("%s\t%s\tEXPRESSION\tcarObj.color" % (threadId, frameId), "EXECFILE", _get_debugger_test_file('_debugger_case15_execfile.py'), "f")
self.WaitForCustomOperation('val=Black')
assert 9 == self._sequence, 'Expected 9. Had: %s' % self._sequence
@@ -486,7 +533,7 @@ class WriterThreadCase15(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase14(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case14.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case14.py')
def run(self):
self.StartSocket()
@@ -499,21 +546,26 @@ class WriterThreadCase14(AbstractWriterThread):
# Access some variable
self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\tcarObj.color" % (threadId, frameId))
- self.WaitForMultipleVars(['<more>False</more>', '%27Black%27'])
+ self.WaitForVar(['<more>False</more>', '%27Black%27'])
assert 7 == self._sequence, 'Expected 9. Had: %s' % self._sequence
# Change some variable
self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\tcarObj.color='Red'" % (threadId, frameId))
self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\tcarObj.color" % (threadId, frameId))
- self.WaitForMultipleVars(['<more>False</more>', '%27Red%27'])
+ self.WaitForVar(['<more>False</more>', '%27Red%27'])
assert 11 == self._sequence, 'Expected 13. Had: %s' % self._sequence
# Iterate some loop
self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\tfor i in range(3):" % (threadId, frameId))
- self.WaitForVars('<xml><more>True</more></xml>')
- self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\t print i" % (threadId, frameId))
+ self.WaitForVar(['<xml><more>True</more></xml>', '<xml><more>1</more></xml>'])
+ self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\t print(i)" % (threadId, frameId))
self.WriteDebugConsoleExpression("%s\t%s\tEVALUATE\t" % (threadId, frameId))
- self.WaitForVars('<xml><more>False</more><output message="0"></output><output message="1"></output><output message="2"></output></xml>')
+ self.WaitForVar(
+ [
+ '<xml><more>False</more><output message="0"></output><output message="1"></output><output message="2"></output></xml>',
+ '<xml><more>0</more><output message="0"></output><output message="1"></output><output message="2"></output></xml>'
+ ]
+ )
assert 17 == self._sequence, 'Expected 19. Had: %s' % self._sequence
self.WriteRunThread(threadId)
@@ -525,7 +577,7 @@ class WriterThreadCase14(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase13(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case13.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case13.py')
def run(self):
self.StartSocket()
@@ -575,7 +627,7 @@ class WriterThreadCase13(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase12(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case10.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case10.py')
def run(self):
self.StartSocket()
@@ -607,7 +659,7 @@ class WriterThreadCase12(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase11(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case10.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case10.py')
def run(self):
self.StartSocket()
@@ -648,7 +700,7 @@ class WriterThreadCase11(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase10(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case10.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case10.py')
def run(self):
self.StartSocket()
@@ -682,7 +734,7 @@ class WriterThreadCase10(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase9(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case89.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case89.py')
def run(self):
self.StartSocket()
@@ -715,7 +767,7 @@ class WriterThreadCase9(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase8(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case89.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case89.py')
def run(self):
self.StartSocket()
@@ -744,7 +796,7 @@ class WriterThreadCase8(AbstractWriterThread):
#======================================================================================================================
class WriterThreadCase7(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case7.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case7.py')
def run(self):
self.StartSocket()
@@ -782,7 +834,7 @@ class WriterThreadCase7(AbstractWriterThread):
#=======================================================================================================================
class WriterThreadCase6(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case56.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case56.py')
def run(self):
self.StartSocket()
@@ -817,7 +869,7 @@ class WriterThreadCase6(AbstractWriterThread):
#=======================================================================================================================
class WriterThreadCase5(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case56.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case56.py')
def run(self):
self.StartSocket()
@@ -855,7 +907,7 @@ class WriterThreadCase5(AbstractWriterThread):
#=======================================================================================================================
class WriterThreadCase4(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case4.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case4.py')
def run(self):
self.StartSocket()
@@ -877,12 +929,12 @@ class WriterThreadCase4(AbstractWriterThread):
#=======================================================================================================================
class WriterThreadCase3(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case3.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case3.py')
def run(self):
self.StartSocket()
self.WriteMakeInitialRun()
- time.sleep(1)
+ time.sleep(.5)
breakpoint_id = self.WriteAddBreakpoint(4, '')
self.WriteAddBreakpoint(5, 'FuncNotAvailable') # Check that it doesn't get hit in the global when a function is available
@@ -909,7 +961,7 @@ class WriterThreadCase3(AbstractWriterThread):
#=======================================================================================================================
class WriterThreadCase2(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case2.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case2.py')
def run(self):
self.StartSocket()
@@ -930,8 +982,79 @@ class WriterThreadCase2(AbstractWriterThread):
self.WriteRunThread(threadId)
+ self.log.append('Checking sequence. Found: %s' % (self._sequence))
assert 15 == self._sequence, 'Expected 15. Had: %s' % self._sequence
+ self.log.append('Marking finished ok.')
+ self.finishedOk = True
+
+#=======================================================================================================================
+# WriterThreadCaseQThread1
+#=======================================================================================================================
+class WriterThreadCaseQThread1(AbstractWriterThread):
+
+ TEST_FILE = _get_debugger_test_file('_debugger_case_qthread1.py')
+
+ def run(self):
+ self.StartSocket()
+ breakpoint_id = self.WriteAddBreakpoint(16, 'run')
+ self.WriteMakeInitialRun()
+
+ threadId, frameId = self.WaitForBreakpointHit()
+
+ self.WriteRemoveBreakpoint(breakpoint_id)
+ self.WriteRunThread(threadId)
+
+ self.log.append('Checking sequence. Found: %s' % (self._sequence))
+ assert 9 == self._sequence, 'Expected 9. Had: %s' % self._sequence
+
+ self.log.append('Marking finished ok.')
+ self.finishedOk = True
+
+#=======================================================================================================================
+# WriterThreadCaseQThread2
+#=======================================================================================================================
+class WriterThreadCaseQThread2(AbstractWriterThread):
+
+ TEST_FILE = _get_debugger_test_file('_debugger_case_qthread2.py')
+
+ def run(self):
+ self.StartSocket()
+ breakpoint_id = self.WriteAddBreakpoint(18, 'longRunning')
+ self.WriteMakeInitialRun()
+
+ threadId, frameId = self.WaitForBreakpointHit()
+
+ self.WriteRemoveBreakpoint(breakpoint_id)
+ self.WriteRunThread(threadId)
+
+ self.log.append('Checking sequence. Found: %s' % (self._sequence))
+ assert 9 == self._sequence, 'Expected 9. Had: %s' % self._sequence
+
+ self.log.append('Marking finished ok.')
+ self.finishedOk = True
+
+#=======================================================================================================================
+# WriterThreadCaseQThread3
+#=======================================================================================================================
+class WriterThreadCaseQThread3(AbstractWriterThread):
+
+ TEST_FILE = _get_debugger_test_file('_debugger_case_qthread3.py')
+
+ def run(self):
+ self.StartSocket()
+ breakpoint_id = self.WriteAddBreakpoint(19, 'run')
+ self.WriteMakeInitialRun()
+
+ threadId, frameId = self.WaitForBreakpointHit()
+
+ self.WriteRemoveBreakpoint(breakpoint_id)
+ self.WriteRunThread(threadId)
+
+ self.log.append('Checking sequence. Found: %s' % (self._sequence))
+ assert 9 == self._sequence, 'Expected 9. Had: %s' % self._sequence
+
+ self.log.append('Marking finished ok.')
self.finishedOk = True
#=======================================================================================================================
@@ -939,24 +1062,39 @@ class WriterThreadCase2(AbstractWriterThread):
#=======================================================================================================================
class WriterThreadCase1(AbstractWriterThread):
- TEST_FILE = NormFile('_debugger_case1.py')
+ TEST_FILE = _get_debugger_test_file('_debugger_case1.py')
def run(self):
self.StartSocket()
+
+ self.log.append('writing add breakpoint')
self.WriteAddBreakpoint(6, 'SetUp')
+
+ self.log.append('making initial run')
self.WriteMakeInitialRun()
+ self.log.append('waiting for breakpoint hit')
threadId, frameId = self.WaitForBreakpointHit()
+ self.log.append('get frame')
self.WriteGetFrame(threadId, frameId)
+ self.log.append('step over')
self.WriteStepOver(threadId)
+ self.log.append('get frame')
self.WriteGetFrame(threadId, frameId)
+ self.log.append('run thread')
self.WriteRunThread(threadId)
- assert 13 == self._sequence, 'Expected 13. Had: %s' % self._sequence
+ self.log.append('asserting')
+ try:
+ assert 13 == self._sequence, 'Expected 13. Had: %s' % self._sequence
+ except:
+ self.log.append('assert failed!')
+ raise
+ self.log.append('asserted')
self.finishedOk = True
@@ -972,6 +1110,7 @@ class DebuggerBase(object):
UpdatePort()
writerThread = writerThreadClass()
writerThread.start()
+ time.sleep(1)
localhost = pydev_localhost.get_localhost()
args = self.getCommandLine()
@@ -987,60 +1126,74 @@ class DebuggerBase(object):
]
if SHOW_OTHER_DEBUG_INFO:
- print 'executing', ' '.join(args)
-
-# process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=os.path.dirname(PYDEVD_FILE))
- process = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=os.path.dirname(PYDEVD_FILE))
- class ProcessReadThread(threading.Thread):
- def run(self):
- self.resultStr = None
- self.resultStr = process.stdout.read()
- process.stdout.close()
-
- def DoKill(self):
- process.stdout.close()
-
- processReadThread = ProcessReadThread()
- processReadThread.setDaemon(True)
- processReadThread.start()
+ print('executing', ' '.join(args))
+
+ process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=os.path.dirname(PYDEVD_FILE))
+
+ stdout = []
+ stderr = []
+
+ def read(stream, buffer):
+ for line in stream.readlines():
+ if IS_PY3K:
+ line = line.decode('utf-8')
+
+ if SHOW_STDOUT:
+ print(line)
+ buffer.append(line)
+
+ start_new_thread(read, (process.stdout, stdout))
+
+
if SHOW_OTHER_DEBUG_INFO:
- print 'Both processes started'
+ print('Both processes started')
# polls can fail (because the process may finish and the thread still not -- so, we give it some more chances to
# finish successfully).
- pools_failed = 0
- while writerThread.isAlive():
+ check = 0
+ while True:
if process.poll() is not None:
- pools_failed += 1
- time.sleep(.2)
- if pools_failed == 10:
break
-
- if process.poll() is None:
- for i in range(10):
- if processReadThread.resultStr is None:
- time.sleep(.5)
- else:
- break
else:
- writerThread.DoKill()
-
- else:
- if process.poll() < 0:
- self.fail("The other process exited with error code: " + str(process.poll()) + " result:" + processReadThread.resultStr)
-
+ if not writerThread.isAlive():
+ check += 1
+ if check == 20:
+ print('Warning: writer thread exited and process still did not.')
+ if check == 100:
+ self.fail_with_message(
+ "The other process should've exited but still didn't (timeout for process to exit).",
+ stdout, stderr, writerThread
+ )
+ time.sleep(.2)
+
+
+ poll = process.poll()
+ if poll < 0:
+ self.fail_with_message(
+ "The other process exited with error code: " + str(poll), stdout, stderr, writerThread)
- if SHOW_RESULT_STR:
- print processReadThread.resultStr
- if processReadThread.resultStr is None:
- self.fail("The other process may still be running -- and didn't give any output")
+ if stdout is None:
+ self.fail_with_message(
+ "The other process may still be running -- and didn't give any output.", stdout, stderr, writerThread)
- if 'TEST SUCEEDED' not in processReadThread.resultStr:
- self.fail(processReadThread.resultStr)
+ if 'TEST SUCEEDED' not in ''.join(stdout):
+ self.fail_with_message("TEST SUCEEDED not found in stdout.", stdout, stderr, writerThread)
+ for i in xrange(100):
+ if not writerThread.finishedOk:
+ time.sleep(.1)
+
if not writerThread.finishedOk:
- self.fail("The thread that was doing the tests didn't finish successfully. Output: %s" % processReadThread.resultStr)
+ self.fail_with_message(
+ "The thread that was doing the tests didn't finish successfully.", stdout, stderr, writerThread)
+
+ def fail_with_message(self, msg, stdout, stderr, writerThread):
+ self.fail(msg+
+ "\nStdout: \n"+'\n'.join(stdout)+
+ "\nStderr:"+'\n'.join(stderr)+
+ "\nLog:\n"+'\n'.join(getattr(writerThread, 'log', [])))
+
def testCase1(self):
self.CheckCase(WriterThreadCase1)
@@ -1098,6 +1251,30 @@ class DebuggerBase(object):
def testCase19(self):
self.CheckCase(WriterThreadCase19)
+
+ def _has_qt(self):
+ try:
+ from PySide import QtCore
+ return True
+ except:
+ try:
+ from PyQt4 import QtCore
+ return True
+ except:
+ pass
+ return False
+
+ def testCaseQthread1(self):
+ if self._has_qt():
+ self.CheckCase(WriterThreadCaseQThread1)
+
+ def testCaseQthread2(self):
+ if self._has_qt():
+ self.CheckCase(WriterThreadCaseQThread2)
+
+ def testCaseQthread3(self):
+ if self._has_qt():
+ self.CheckCase(WriterThreadCaseQThread3)
class TestPython(unittest.TestCase, DebuggerBase):
@@ -1117,9 +1294,6 @@ class TestJython(unittest.TestCase, DebuggerBase):
def testCase13(self):
self.skipTest("Unsupported Decorators")
- def testCase16(self):
- self.skipTest("Unsupported numpy")
-
# This case requires decorators to work (which are not present on Jython 2.1), so, this test is just removed from the jython run.
def testCase17(self):
self.skipTest("Unsupported Decorators")
@@ -1127,6 +1301,9 @@ class TestJython(unittest.TestCase, DebuggerBase):
def testCase18(self):
self.skipTest("Unsupported assign to local")
+ def testCase16(self):
+ self.skipTest("Unsupported numpy")
+
class TestIronPython(unittest.TestCase, DebuggerBase):
def getCommandLine(self):
return [
@@ -1134,8 +1311,22 @@ class TestIronPython(unittest.TestCase, DebuggerBase):
'-X:Frames'
]
+ def testCase3(self):
+ self.skipTest("Timing issues") # This test fails once in a while due to timing issues on IronPython, so, skipping it.
+
+ def testCase7(self):
+ # This test checks that we start without variables and at each step a new var is created, but on ironpython,
+ # the variables exist all at once (with None values), so, we can't test it properly.
+ self.skipTest("Different behavior on IronPython")
+
+ def testCase13(self):
+ self.skipTest("Unsupported Decorators") # Not sure why it doesn't work on IronPython, but it's not so common, so, leave it be.
+
def testCase16(self):
self.skipTest("Unsupported numpy")
+
+ def testCase18(self):
+ self.skipTest("Unsupported assign to local")
def GetLocationFromLine(line):
@@ -1157,49 +1348,90 @@ def SplitLine(line):
+
import platform
sysname = platform.system().lower()
test_dependent = os.path.join('../../../', 'org.python.pydev.core', 'tests', 'org', 'python', 'pydev', 'core', 'TestDependent.' + sysname + '.properties')
-f = open(test_dependent)
-try:
- for line in f.readlines():
- var, loc = SplitLine(line)
- if 'PYTHON_EXE' == var:
- PYTHON_EXE = loc
-
- if 'IRONPYTHON_EXE' == var:
- IRONPYTHON_EXE = loc
-
- if 'JYTHON_JAR_LOCATION' == var:
- JYTHON_JAR_LOCATION = loc
-
- if 'JAVA_LOCATION' == var:
- JAVA_LOCATION = loc
-finally:
- f.close()
-
-assert PYTHON_EXE, 'PYTHON_EXE not found in %s' % (test_dependent,)
-assert IRONPYTHON_EXE, 'IRONPYTHON_EXE not found in %s' % (test_dependent,)
-assert JYTHON_JAR_LOCATION, 'JYTHON_JAR_LOCATION not found in %s' % (test_dependent,)
-assert JAVA_LOCATION, 'JAVA_LOCATION not found in %s' % (test_dependent,)
-assert os.path.exists(PYTHON_EXE), 'The location: %s is not valid' % (PYTHON_EXE,)
-assert os.path.exists(IRONPYTHON_EXE), 'The location: %s is not valid' % (IRONPYTHON_EXE,)
-assert os.path.exists(JYTHON_JAR_LOCATION), 'The location: %s is not valid' % (JYTHON_JAR_LOCATION,)
-assert os.path.exists(JAVA_LOCATION), 'The location: %s is not valid' % (JAVA_LOCATION,)
-
-if False:
- suite = unittest.TestSuite()
- #PYTHON_EXE = r'C:\bin\Anaconda\python.exe'
-# suite.addTest(TestPython('testCase10'))
-# suite.addTest(TestPython('testCase3'))
-# suite.addTest(TestPython('testCase16'))
-# suite.addTest(TestPython('testCase17'))
-# suite.addTest(TestPython('testCase18'))
-# suite.addTest(TestPython('testCase19'))
- suite = unittest.makeSuite(TestPython)
- unittest.TextTestRunner(verbosity=3).run(suite)
+
+if os.path.exists(test_dependent):
+ f = open(test_dependent)
+ try:
+ for line in f.readlines():
+ var, loc = SplitLine(line)
+ if 'PYTHON_EXE' == var:
+ PYTHON_EXE = loc
+
+ if 'IRONPYTHON_EXE' == var:
+ IRONPYTHON_EXE = loc
+
+ if 'JYTHON_JAR_LOCATION' == var:
+ JYTHON_JAR_LOCATION = loc
+
+ if 'JAVA_LOCATION' == var:
+ JAVA_LOCATION = loc
+ finally:
+ f.close()
+else:
+ pass
+
+if IRONPYTHON_EXE is None:
+ sys.stderr.write('Warning: not running IronPython tests.\n')
+ class TestIronPython(unittest.TestCase):
+ pass
+
+if JAVA_LOCATION is None:
+ sys.stderr.write('Warning: not running Jython tests.\n')
+ class TestJython(unittest.TestCase):
+ pass
-# unittest.TextTestRunner(verbosity=3).run(suite)
-#
-# suite = unittest.makeSuite(TestJython)
-# unittest.TextTestRunner(verbosity=3).run(suite)
+# if PYTHON_EXE is None:
+PYTHON_EXE = sys.executable
+
+
+if __name__ == '__main__':
+ if False:
+ assert PYTHON_EXE, 'PYTHON_EXE not found in %s' % (test_dependent,)
+ assert IRONPYTHON_EXE, 'IRONPYTHON_EXE not found in %s' % (test_dependent,)
+ assert JYTHON_JAR_LOCATION, 'JYTHON_JAR_LOCATION not found in %s' % (test_dependent,)
+ assert JAVA_LOCATION, 'JAVA_LOCATION not found in %s' % (test_dependent,)
+ assert os.path.exists(PYTHON_EXE), 'The location: %s is not valid' % (PYTHON_EXE,)
+ assert os.path.exists(IRONPYTHON_EXE), 'The location: %s is not valid' % (IRONPYTHON_EXE,)
+ assert os.path.exists(JYTHON_JAR_LOCATION), 'The location: %s is not valid' % (JYTHON_JAR_LOCATION,)
+ assert os.path.exists(JAVA_LOCATION), 'The location: %s is not valid' % (JAVA_LOCATION,)
+
+ if True:
+ #try:
+ # os.remove(r'X:\pydev\plugins\org.python.pydev\pysrc\pydevd.pyc')
+ #except:
+ # pass
+ suite = unittest.TestSuite()
+
+# suite.addTests(unittest.makeSuite(TestJython)) # Note: Jython should be 2.2.1
+#
+# suite.addTests(unittest.makeSuite(TestIronPython))
+#
+# suite.addTests(unittest.makeSuite(TestPython))
+
+
+
+
+# suite.addTest(TestIronPython('testCase18'))
+# suite.addTest(TestIronPython('testCase17'))
+# suite.addTest(TestIronPython('testCase3'))
+# suite.addTest(TestIronPython('testCase7'))
+#
+ suite.addTest(TestPython('testCaseQthread1'))
+ suite.addTest(TestPython('testCaseQthread2'))
+ suite.addTest(TestPython('testCaseQthread3'))
+
+# suite.addTest(TestPython('testCase4'))
+
+
+# suite.addTest(TestJython('testCase1'))
+# suite.addTest(TestPython('testCase2'))
+# unittest.TextTestRunner(verbosity=3).run(suite)
+ # suite.addTest(TestPython('testCase17'))
+ # suite.addTest(TestPython('testCase18'))
+ # suite.addTest(TestPython('testCase19'))
+
+ unittest.TextTestRunner(verbosity=3).run(suite)