Changeset: eba6437bc25e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eba6437bc25e
Modified Files:
        testing/Mtest.py.in
        testing/exportutils.py
        testing/listexports.py.in
        testing/monet_options.py.in
Branch: default
Log Message:

Ported to Python 3, keeping compatibility with Python 2.


diffs (truncated from 996 to 300 lines):

diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -56,7 +56,7 @@ else:
     RED = GREEN = PURPLE = BLACK = ''
 
 def ErrExit(msg):
-    print >> sys.stderr, msg
+    sys.stderr.write(msg + '\n')
     sys.exit(1)
 
 def _configure(str):
@@ -121,7 +121,7 @@ except ImportError:
         p = _configure(os.path.join('@QXprefix@', '@QXPYTHON2_LIBDIR@'))
         sys.path.insert(0, p)
         import MonetDBtesting.Mfilter as Mfilter
-        if os.environ.has_key('PYTHONPATH'):
+        if 'PYTHONPATH' in os.environ:
             p += os.pathsep + os.environ['PYTHONPATH']
         os.environ['PYTHONPATH'] = p
 
@@ -176,7 +176,8 @@ if isatty and os.isatty(sys.stdin.fileno
     else:
         try:
             proc = process.Popen(['stty', '-a'], stdout = process.PIPE,
-                                 stderr = process.PIPE)
+                                 stderr = process.PIPE,
+                                 universal_newlines = True)
         except OSError:
             pass
         else:
@@ -394,9 +395,7 @@ class Element(_Encode):
     def __str__(self):
         # string representation of the element with its children
         s = ['<%s' % self.tag]
-        attrlist = self.attrdict.items()
-        attrlist.sort()
-        for name, value in attrlist:
+        for name, value in sorted(self.attrdict.items()):
             s.append(' %s="%s"' % (name, self.encode(value, True)))
         if self.children or (not self.xml and not self.isempty):
             s.append('>')
@@ -427,9 +426,7 @@ class Element(_Encode):
                         '"http://www.w3.org/TR/html4/loose.dtd";>\n')
         inline = self.tag.lower() in self.inline
         f.write('<%s' % self.tag)
-        attrlist = self.attrdict.items()
-        attrlist.sort()
-        for name, value in attrlist:
+        for name, value in sorted(self.attrdict.items()):
             f.write(' %s="%s"' % (name, self.encode(value, True)))
         if self.children or (not self.xml and not self.isempty):
             if not inline:
@@ -593,22 +590,26 @@ def startswithpath(str,pre) :
     return os.path.normcase(str[:len(pre)]) == os.path.normcase(pre)
 ### startswithpath(str,pre) #
 
-import urllib
 ##def path(str) :
 ##    return str.replace('/', os.sep)
-path = urllib.url2pathname
 ### path(str) #
-
 ##def url(str) :
 ##    return str.replace(os.sep, '/')
-url = urllib.pathname2url
 ### url(str) #
+if sys.version_info[0] == 2:
+    import urllib
+    path = urllib.url2pathname
+    url = urllib.pathname2url
+elif sys.version_info[0] == 3:
+    import urllib.request
+    path = urllib.request.url2pathname
+    url = urllib.request.pathname2url
 
 def try_open(path, mode) :
     try:
         f = open(path, mode)
-    except IOError, (IOerrNo, IOerrStr):
-        Warn("Opening file '%s' in mode '%s' failed with #%d: '%s'." % (path, 
mode, IOerrNo, IOerrStr))
+    except IOError as err:
+        Warn("Opening file '%s' in mode '%s' failed with #%d: '%s'." % (path, 
mode, err.errno, err.strerror))
         f = None
     return f
 ###  try_open(path, mode) #
@@ -1022,7 +1023,7 @@ def AddTstToHtmlIndex (env, TST, STABLEo
     td.addchildren(AddHref('.%s%s.html' % (TST, '.err'),
                            '%s_%s_body' % (DISTVER, TSTDIR),
                            'err', e))
-    if not env.has_key('_%s_BODY_' % TSTDIR)  or  \
+    if '_%s_BODY_' % TSTDIR not in env  or  \
        not env['_%s_BODY_' % TSTDIR][0]  or  \
        ( (not env['_%s_BODY_' % TSTDIR][1])  and  (o or e) ):
         if e and not o:
@@ -1039,7 +1040,7 @@ def AddSubToHtmlIndex (env, TSTDIR, diff
     td = Element('td', {'class': 'header'})
     td.addchildren(AddHref('%s/.index.html' % url(TSTDIR), '%s__body' % 
DISTVER,
                            TSTDIR, diff))
-    if not env.has_key('__BODY_')  or  \
+    if '__BODY_' not in env  or  \
        not env['__BODY_'][0]  or  \
        ( (not env['__BODY_'][1])  and  diff ):
         env['__BODY_'] = ["%s/.index.html" % TSTDIR, diff]
@@ -1086,7 +1087,7 @@ def SkipTest(env, TST, EXT, REASON, leng
                  Element('a', {'href': '.%s.SKIPPED' % TST,
                                'target': target},
                          Text('(skipped)')))
-    if not env.has_key('_%s_BODY_' % TSTDIR)  or  \
+    if '_%s_BODY_' % TSTDIR not in env  or  \
        not env['_%s_BODY_' % TSTDIR][0]  or  \
        not env['_%s_BODY_' % TSTDIR][1]:
         env['_%s_BODY_' % TSTDIR] = [".%s.SKIPPED" % TST, F_SKIP]
@@ -1176,11 +1177,11 @@ def PerformDir(env, testdir, testlist, B
 
     #STDERR.flush()
     #for v in 'RELSRCDIR':
-    #       print v+" = "+str(env[v])
+    #       print(v+" = "+str(env[v]))
     #STDOUT.flush()
 
     if THISFILE == "Mtest.py":
-        if env.has_key('GDK_DBFARM'):
+        if 'GDK_DBFARM' in env:
             LogDBdir = os.path.join(env['GDK_DBFARM'],TSTDB)
             if not env.get('NOCLEAN') and LogDBdir and 
os.path.exists(LogDBdir):
                 try:
@@ -1206,7 +1207,7 @@ def PerformDir(env, testdir, testlist, B
         body_bad = []
         oktests = []
         if not verbose and not quiet:
-            print '\nRunning in %s' % TSTDIR
+            print('\nRunning in %s' % TSTDIR)
         alllinks = []
         for TST,COND in testlist:
             os.environ['TST'] = TST
@@ -1322,7 +1323,7 @@ def ApproveOutput (env, TST) :
                     open(stableOUTPUT,"w").close()
 
             for d in ('TMPDIR', 'TMP', 'TEMP'):
-                if os.environ.has_key(d):
+                if d in os.environ:
                     patch = os.environ[d]
                     break
             else:
@@ -1331,13 +1332,13 @@ def ApproveOutput (env, TST) :
             f = open(patch + '.0', 'w')
             proc = process.Popen(['diff', '-Bb', '-I^[#=]', '-U0',
                                   stableOUTPUT, testOUTPUT],
-                                 stdout = f)
+                                 stdout = f, universal_newlines = True)
             proc.wait()
             f.close()
             if os.path.getsize(patch + ".0"):
                 if not verbose:
                     oc = ''
-                print "Approving  %s  ->  stable.%s%s%s" % 
(os.path.join(TSTDIR, "%s.test.%s" % (TST, WHAT)), WHAT, SYSTEM, oc)
+                print("Approving  %s  ->  stable.%s%s%s" % 
(os.path.join(TSTDIR, "%s.test.%s" % (TST, WHAT)), WHAT, SYSTEM, oc))
 
                 f = open(patch + ".1", "wb")
                 for l in open(patch + ".0"):
@@ -1367,12 +1368,13 @@ def ApproveOutput (env, TST) :
                 patchcmd = ['patch']
                 if not verbose:
                     patchcmd.append('--quiet')
-                proc = process.Popen(patchcmd + [stableOUTPUT, patch + '.1'])
+                proc = process.Popen(patchcmd + [stableOUTPUT, patch + '.1'],
+                                     universal_newlines = True)
                 proc.wait()
                 f = open(patch, 'w')
                 proc = process.Popen(['diff', '-u', stableOUTPUT + '.ORG',
                                       stableOUTPUT],
-                                     stdout = f)
+                                     stdout = f, universal_newlines = True)
                 proc.wait()
                 f.close()
                 remove(stableOUTPUT + ".ORG")
@@ -1392,14 +1394,14 @@ def ApproveOutput (env, TST) :
                         elif f != thefile and test.match(f):
                             remove(os.path.join(dir or os.curdir, f + '.rej'))
                             remove(os.path.join(dir or os.curdir, f + '.orig'))
-                            proc = process.Popen(patchcmd + ['--forward', 
os.path.join(dir or os.curdir, f)], stdin = open(patch))
+                            proc = process.Popen(patchcmd + ['--forward', 
os.path.join(dir or os.curdir, f)], stdin = open(patch), universal_newlines = 
True)
                             proc.wait()
                             if os.path.exists(os.path.join(dir or os.curdir, f 
+ '.rej')):
                                 list.append(f)
                 if len(list) > 0:
                     Warn('There are other (specific) stable outputs for 
test\n%s for which patching failed:\n  %s\n\n  Look at the *.rej files in 
directory %s.' % (os.path.join(TSTDIR,'Tests',TST), str(list), 
os.path.join(TSTDIR,'Tests')))
             elif verbose:
-                print "No differences detected between  %s and  stable.%s%s  
that are not ignored by Mtest.py." % (os.path.join(TSTDIR, "%s.test.%s" % (TST, 
WHAT)), WHAT, SYSTEM)
+                print("No differences detected between  %s and  stable.%s%s  
that are not ignored by Mtest.py." % (os.path.join(TSTDIR, "%s.test.%s" % (TST, 
WHAT)), WHAT, SYSTEM))
             remove(patch + ".0")
         elif verbose:
             i = TST.rfind('.')
@@ -1517,7 +1519,7 @@ def GetBitsAndOIDsAndModsAndStaticAndThr
                       ignore_errors = True)
         os.makedirs(os.path.join(env['GDK_DBFARM'], TSTPREF + '_transient'))
     if procdebug:
-        print 'GetBitsAndOIDsAndModsAndStaticAndThreads: starting process "%s" 
(inpipe, outpipe, errpipe)\n' % '" "'.join(cmd)
+        print('GetBitsAndOIDsAndModsAndStaticAndThreads: starting process "%s" 
(inpipe, outpipe, errpipe)\n' % '" "'.join(cmd))
     setpgrp = True
     proc = process.Popen(cmd, stdin = process.PIPE, stdout = process.PIPE,
                          stderr = process.PIPE, universal_newlines = True)
@@ -1547,12 +1549,12 @@ def GetBitsAndOIDsAndModsAndStaticAndThr
         qOut, qErr = proc.communicate(input = input)
         t.cancel()
         if procdebug:
-            print 'GetBitsAndOIDsAndModsAndStaticAndThreads: process exited 
"%s" (%s)\n' % ('" "'.join(cmd), proc.returncode)
+            print('GetBitsAndOIDsAndModsAndStaticAndThreads: process exited 
"%s" (%s)\n' % ('" "'.join(cmd), proc.returncode))
     except KeyboardInterrupt:
         t.cancel()
         killProc(proc, proc.stderr, cmd)
         if procdebug:
-            print 'GetBitsAndOIDsAndModsAndStaticAndThreads: process killed 
"%s"\n' % '" "'.join(cmd)
+            print('GetBitsAndOIDsAndModsAndStaticAndThreads: process killed 
"%s"\n' % '" "'.join(cmd))
         raise
     returncode = returnCode(proc)
     if returncode is not None:
@@ -1660,7 +1662,7 @@ def CheckTests(env, TST, oktests):
         test = test.strip()
         if not test or test.startswith('#'):
             continue
-        if not test in oktests:
+        if test not in oktests:
             missing.append(test)
     return missing
 ### CheckTests(env, TST, oktests) #
@@ -1871,7 +1873,7 @@ def RunTest(env, TST, BusyPorts, COND, o
                         reason = "as number of threads is wrong"
                         elem = SkipTest(env, TST, EXT, reason, length)
                         break
-                elif not CONDITIONALS.has_key(cond):
+                elif cond not in CONDITIONALS:
                     reason = "as conditional '%s' is unknown." % cond
                     elem = SkipTest(env, TST, EXT, reason, length)
                     break
@@ -1941,7 +1943,7 @@ def RunTest(env, TST, BusyPorts, COND, o
                     reason = "as number of threads is wrong"
                     elem = SkipTest(env, TST, EXT, reason, length)
                     break
-            elif not CONDITIONALS.has_key(cond):
+            elif cond not in CONDITIONALS:
                 reason = "as conditional '%s' is unknown." % cond
                 elem = SkipTest(env, TST, EXT, reason, length)
                 break
@@ -1997,7 +1999,7 @@ def RunTest(env, TST, BusyPorts, COND, o
                 try:
                     SymlinkOrCopy(os.path.join(RELSRCDIR, f), f)
                     links.append(os.path.join(TSTTRGDIR, f))
-                except IOError, (IOerrNo, IOerrStr):
+                except IOError as err:
                     if not env.get('NOCLEAN'):
                         ErrMsg("SymlinkOrCopy('%s','%s') in '%s' failed with 
#%d: '%s'."
                                % (os.path.join(RELSRCDIR, f), f, os.getcwd(), 
IOerrNo, IOerrStr))
@@ -2020,9 +2022,9 @@ def RunTest(env, TST, BusyPorts, COND, o
                 try:
                     SymlinkOrCopy(TSTSRC, TST + EXT)
                     links.append(TST + EXT)
-                except IOError, (IOerrNo, IOerrStr):
+                except IOError as err:
                     ErrMsg("SymlinkOrCopy('%s','%s') in '%s' failed with #%d: 
'%s'."
-                           % (TSTSRC, TST + EXT, os.getcwd(), IOerrNo, 
IOerrStr))
+                           % (TSTSRC, TST + EXT, os.getcwd(), err.errno, 
err.strerror))
             else:
                 reason = "as source file '%s` is missing." % TSTSRC
                 elem = SkipTest(env, TST, EXT+".src", reason, length)
@@ -2040,9 +2042,9 @@ def RunTest(env, TST, BusyPorts, COND, o
                     try:
                         SymlinkOrCopy(TSTSRC, ff[:-4])
                         links.append(ff[:-4])
-                    except IOError, (IOerrNo, IOerrStr):
+                    except IOError as err:
                         ErrMsg("SymlinkOrCopy('%s','%s') in '%s' failed with 
#%d: '%s'."
-                               % (TSTSRC, ff[:-4], os.getcwd(), IOerrNo, 
IOerrStr))
+                               % (TSTSRC, ff[:-4], os.getcwd(), err.errno, 
err.strerror))
                 else:
                     Warn("source file '"+TSTSRC+"` is missing.")
         test = re.compile("^"+TST+"(_[sp][0-9][0-9])?\..*\.in$", re.MULTILINE)
@@ -2222,22 +2224,18 @@ def RunTest(env, TST, BusyPorts, COND, o
 
         try:
             STDOUT.flush()
-        except IOError, (IOerrNo, IOerrStr):
-            Warn("Flushing STDOUT in RunTest failed with #%d: '%s'." % 
(IOerrNo, IOerrStr))
+        except IOError as err:
+            Warn("Flushing STDOUT in RunTest failed with #%d: '%s'." % 
(err.errno, err.strerror))
 
         if env['exe']['Mtimeout'][0]:
             # reset timeout
             env['exe']['Mtimeout'] = env['exe']['Mtimeout'][0], 'Mtimeout 
-timeout %s ' % str(par['TIMEOUT'])
             SetExecEnv(env['exe'],False)
 
-        try:
-            Mfilter.mFilter(TST+STABLEout,par['IGNORE'])
-            Mfilter.mFilter(TST+STABLEerr,par['IGNORE'])
-            Mfilter.mFilter(TST+".test.out",par['IGNORE'])
-            Mfilter.mFilter(TST+".test.err",par['IGNORE'])
-        except:
-            Warn("mFilter failed\n")
-            pass
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to