Changeset: 60f24ef52c9c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/60f24ef52c9c Modified Files: testing/Mtest.py.in Branch: Mar2025 Log Message:
Do not use globally visible temporary changes. I.e., no chdir back and forth, no temporary additions to os.environ, etc. (grafted from 1f9e6a5b71fd95f3ce832c620693c7523c3c715c) diffs (truncated from 1257 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 @@ -547,19 +547,13 @@ def try_open(path, mode) : return f ### try_open(path, mode) # -def CreateHtmlIndex (env, ssout, sserr, *body) : - TSTDIR=env['TSTDIR'] - TSTTRGDIR=env['TSTTRGDIR'] - +def CreateHtmlIndex (env, TSTDIR, TSTTRGDIR, ssout, sserr, *body) : if TSTDIR: INDEX='.index' else: INDEX='index' if body: - BACK = os.getcwd() - os.chdir(TSTTRGDIR) - if TSTDIR: header = Text(TSTDIR) if REV: @@ -570,7 +564,7 @@ def CreateHtmlIndex (env, ssout, sserr, 'title': TSTDIR}, header) th = Element('th', {'class': 'header'}, header) - if os.path.exists('SingleServer.out.html'): + if os.path.exists(os.path.join(TSTTRGDIR, 'SingleServer.out.html')): th.addchild(Element('br')) th.addchildren(AddHref('SingleServer.out.html', '%s_%s_body' % (DISTVER, TSTDIR), @@ -611,7 +605,7 @@ def CreateHtmlIndex (env, ssout, sserr, Element('title', {}, Text(HTMLTITLE)), stylesheet), hbody) - with openutf8('%s.head.html' % INDEX,'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '%s.head.html' % INDEX),'w') as f: html.write(f, True) if TSTDIR: @@ -647,17 +641,15 @@ def CreateHtmlIndex (env, ssout, sserr, 'bordercolor': white, 'marginwidth': '0', 'marginheight': '0'}))) - with openutf8('%s.html' % INDEX, 'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '%s.html' % INDEX), 'w') as f: html.write(f, True) - os.chdir(BACK) ### CreateHtmlIndex (env, ssout, sserr, *body) # bugre = re.compile(r'\.(sf|bug)-(?P<bugno>[1-9]\d+)', re.I) -def CreateTstWhatXhtml (env, TST, stableWHAT, EXT, result) : + +def CreateTstWhatXhtml (env, TST, stableWHAT, EXT, result, TSTDIR, TSTTRGDIR, TSTSRCDIR, RELSRCDIR) : WHAT = stableWHAT[7:11] - TSTDIR = env['TSTDIR'] - TSTSRCDIR = env['TSTSRCDIR'] if result == F_OK: diffclass = 'good' @@ -713,9 +705,9 @@ def CreateTstWhatXhtml (env, TST, stable 'bordercolor': white, 'marginwidth': '0', 'marginheight': '0'}))) - with openutf8('.%s%s.html' % (TST, WHAT), 'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '.%s%s.html' % (TST, WHAT)), 'w') as f: html.write(f, True) - f = openutf8('.%s%s.head.html' % (TST, WHAT),'w') + f = openutf8(os.path.join(TSTTRGDIR, '.%s%s.head.html' % (TST, WHAT)),'w') target = '%s_%s_%s_%s_body' % (DISTVER, TSTDIR, TST, WHAT[1:]) if REV: # implies URLPREFIX is not None urlpref = '%s%s/%s' % (URLPREFIX, url(TSTDIR), TSTSUFF) @@ -739,7 +731,7 @@ def CreateTstWhatXhtml (env, TST, stable d = urlpref if os.path.isfile(TST + stableWHAT + '.src'): # there's only one file like this... - fl = openutf8(TST + stableWHAT + '.src').readline().strip() + fl = openutf8(os.path.join(TSTTRGDIR, TST + stableWHAT + '.src')).readline().strip() if fl.startswith('$RELSRCDIR/'): fl = fl[11:] while fl.startswith('../'): @@ -764,7 +756,7 @@ def CreateTstWhatXhtml (env, TST, stable if REV: d = urlpref if os.path.isfile(TST + EXT + '.src'): - fl = openutf8(TST + EXT + '.src').readline().strip() + fl = openutf8(os.path.join(TSTTRGDIR, TST + EXT + '.src')).readline().strip() if fl.startswith('$RELSRCDIR/'): fl = fl[11:] while fl.startswith('../'): @@ -789,7 +781,7 @@ def CreateTstWhatXhtml (env, TST, stable text.addchild(hg) text.addchild(Text(', ')) text.addchildren([ - Element('a', {'href': url(env['RELSRCDIR']), + Element('a', {'href': url(RELSRCDIR), 'target': target}, Text('src')), Text(')')]) @@ -818,10 +810,7 @@ def CreateTstWhatXhtml (env, TST, stable html.write(f, True) f.close() -def CreateSrcIndex (env, TST, EXT) : - TSTSRCDIR = env['TSTSRCDIR'] - TSTDIR = env['TSTDIR'] - +def CreateSrcIndex (env, TST, EXT, TSTDIR, TSTTRGDIR, TSTSRCDIR) : if REV: framesrc = '%s%s/%s/%s%s' % (URLPREFIX, url(TSTDIR), TSTSUFF, TST, EXT) else: @@ -839,7 +828,7 @@ def CreateSrcIndex (env, TST, EXT) : Element('center', {}, Text('no source available')))) framesrc = '.%s.nosrc.index.html' % TST - with openutf8('.%s.nosrc.index.html' % TST, 'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '.%s.nosrc.index.html' % TST), 'w') as f: html.write(f, True) html = Element('html', {}, Element('head', {}, @@ -867,7 +856,7 @@ def CreateSrcIndex (env, TST, EXT) : 'bordercolor': white, 'marginwidth': '0', 'marginheight': '0'}))) - with openutf8('.%s.src.index.html' % TST,'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '.%s.src.index.html' % TST),'w') as f: html.write(f, True) tr = Element('tr', {}, @@ -901,7 +890,7 @@ def CreateSrcIndex (env, TST, EXT) : 'cellspacing': '0', 'cellpadding': '3'}, tr)))) - with openutf8('.%s.src.index.head.html' % TST, 'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '.%s.src.index.head.html' % TST), 'w') as f: html.write(f, True) ### CreateSrcIndex (env, TST, EXT) # @@ -933,11 +922,9 @@ def AddHref (href, target, linktext, dif return [a] ### AddHref (TSTDIR, TST, WHAT, diff) # -def AddTstToHtmlIndex (env, TST, STABLEout, STABLEerr, EXT, o, e) : - TSTDIR = env['TSTDIR'] - - CreateTstWhatXhtml(env, TST, STABLEout, EXT, o) - CreateTstWhatXhtml(env, TST, STABLEerr, EXT, e) +def AddTstToHtmlIndex (env, TST, STABLEout, STABLEerr, EXT, o, e, TSTDIR, TSTTRGDIR, TSTSRCDIR, RELSRCDIR) : + CreateTstWhatXhtml(env, TST, STABLEout, EXT, o, TSTDIR, TSTTRGDIR, TSTSRCDIR, RELSRCDIR) + CreateTstWhatXhtml(env, TST, STABLEerr, EXT, e, TSTDIR, TSTTRGDIR, TSTSRCDIR, RELSRCDIR) if e == F_RECU: tstclass = 'recursion' @@ -977,7 +964,7 @@ def AddTstToHtmlIndex (env, TST, STABLEo else: env[f'_{TSTDIR}_BODY_'] = ['.%s.out.html' % TST, o] - CreateSrcIndex(env, TST, EXT) + CreateSrcIndex(env, TST, EXT, TSTDIR, TSTTRGDIR, TSTSRCDIR) return td ### AddTstToHtmlIndex (env, TST, STABLEout, STABLEerr, EXT) # @@ -994,8 +981,7 @@ def AddSubToHtmlIndex (env, TSTDIR, diff return elem ### AddSubToHtmlIndex (env, TSTDIR, diff) # -def SkipTest(env, TST, EXT, REASON, length) : - TSTDIR = env['TSTDIR'] +def SkipTest(env, TST, EXT, REASON, length, TSTDIR, TSTTRGDIR, TSTSRCDIR) : TEXT = 'Skipping test %s%s %s' % (TST, EXT, REASON) if verbosity > 1: Warn(TEXT) @@ -1019,7 +1005,7 @@ def SkipTest(env, TST, EXT, REASON, leng if testweb or not produce_html: return None - with openutf8('.%s.SKIPPED.html' % TST, 'w') as f: + with openutf8(os.path.join(TSTTRGDIR, '.%s.SKIPPED.html' % TST), 'w') as f: Element('html', {}, Element('body', {}, Element('p', {}, @@ -1038,7 +1024,7 @@ def SkipTest(env, TST, EXT, REASON, leng not env[f'_{TSTDIR}_BODY_'][0] or \ not env[f'_{TSTDIR}_BODY_'][1]: env[f'_{TSTDIR}_BODY_'] = ['.%s.SKIPPED.html' % TST, F_SKIP] - CreateSrcIndex(env, TST, EXT) + CreateSrcIndex(env, TST, EXT, TSTDIR, TSTTRGDIR, TSTSRCDIR) return td ### SkipTest(env, TST, EXT, REASON) # @@ -1093,7 +1079,7 @@ def PerformDir(env, testdir, testlist, t TSTDB = TSTPREF + '_' + TSTDIR.replace(os.sep, '_') try: - sys.path.insert(0, TSTSRCDIR) + # sys.path.insert(0, TSTSRCDIR) alltests = [] try: @@ -1145,26 +1131,22 @@ def PerformDir(env, testdir, testlist, t if len(tst[0]) > length: length = len(tst[0]) - env['TSTDB'] = TSTDB - env['TSTDIR'] = TSTDIR - env['TSTSRCDIR'] = TSTSRCDIR - env['UTSTSRCDIR'] = 'file://' + url(TSTSRCDIR) - env['TSTTRGDIR'] = TSTTRGDIR if TSTDIR == os.curdir: - env['RELSRCDIR'] = os.path.join(os.pardir, env['RELSRCBASE'], TSTSUFF) + RELSRCDIR = os.path.join(os.pardir, env['RELSRCBASE'], TSTSUFF) else: - env['RELSRCDIR'] = os.path.join(* [os.pardir] * (len(TSTDIR.split(os.sep)) + 1) + [env['RELSRCBASE'], TSTDIR, TSTSUFF]) - os.environ['TSTDB'] = TSTDB - os.environ['TSTDIR'] = TSTDIR - os.environ['TSTSRCDIR'] = TSTSRCDIR - os.environ['TSTTRGDIR'] = TSTTRGDIR - os.environ['RELSRCDIR'] = env['RELSRCDIR'] - os.environ['HAVE_HGE'] = CONDITIONALS['HAVE_HGE'] - os.environ['HAVE_SHP'] = CONDITIONALS['HAVE_SHP'] - os.environ['TST_BITS'] = env['TST_BITS'] - if 'TSTDATAPATH' not in os.environ and TSTDATAPATH: + RELSRCDIR = os.path.join(* [os.pardir] * (len(TSTDIR.split(os.sep)) + 1) + [env['RELSRCBASE'], TSTDIR, TSTSUFF]) + environ = os.environ.copy() + environ['TSTDB'] = TSTDB + environ['TSTDIR'] = TSTDIR + environ['TSTSRCDIR'] = TSTSRCDIR + environ['TSTTRGDIR'] = TSTTRGDIR + environ['RELSRCDIR'] = RELSRCDIR + environ['HAVE_HGE'] = CONDITIONALS['HAVE_HGE'] + environ['HAVE_SHP'] = CONDITIONALS['HAVE_SHP'] + environ['TST_BITS'] = env['TST_BITS'] + if 'TSTDATAPATH' not in environ and TSTDATAPATH: env['TSTDATAPATH'] = TSTDATAPATH - os.environ['TSTDATAPATH'] = TSTDATAPATH + environ['TSTDATAPATH'] = TSTDATAPATH if 'GDK_DBFARM' in env: @@ -1216,7 +1198,7 @@ def PerformDir(env, testdir, testlist, t 30 if par['TIMEOUT'] else 0, os.path.join(LogDBdir, '.started'), TSTDB, dbg=env.get('DBG')) - pSrvr.LaunchIt() + pSrvr.LaunchIt(env=environ) pSrvr.terminate() if not os.path.exists(TSTTRGDIR): os.makedirs(TSTTRGDIR) @@ -1239,11 +1221,11 @@ def PerformDir(env, testdir, testlist, t if o.startswith('embedded'): inmem = False if o == 'odbc_loader': - orig_odbcsysini = os.environ.pop('ODBCSYSINI', None) - orig_odbcini = os.environ.pop('ODBCINI', None) - orig_odbcinstini = os.environ.pop('ODBCINSTINI', None) - os.environ['ODBCSYSINI'] = TSTTRGDIR - os.environ['ODBCINI'] = os.path.join(TSTTRGDIR, 'odbc.ini') + orig_odbcsysini = environ.pop('ODBCSYSINI', None) + orig_odbcini = environ.pop('ODBCINI', None) + orig_odbcinstini = environ.pop('ODBCINSTINI', None) + environ['ODBCSYSINI'] = TSTTRGDIR + environ['ODBCINI'] = os.path.join(TSTTRGDIR, 'odbc.ini') if o != 'nodrop': opts.append(o) if inmem: @@ -1271,8 +1253,7 @@ def PerformDir(env, testdir, testlist, t TSTDB, inmem=inmem, dbg=env.get('DBG')) - os.chdir(TSTTRGDIR) - pSrvr.LaunchIt() + pSrvr.LaunchIt(cwd=TSTTRGDIR, env=environ) if pSrvr.port is None: print('\nFailed to start server.\n') FdOut = FdErr = F_FAIL @@ -1299,16 +1280,16 @@ def PerformDir(env, testdir, testlist, t break except: pass - os.environ['MAPIPORT'] = env['MAPIPORT'] = pSrvr.port - SetExecEnv(env['exe'], pSrvr.port, verbosity > 1) + environ['MAPIPORT'] = pSrvr.port + SetExecEnv(env['exe'], pSrvr.port, verbosity > 1, environ) if global_timeout and start_time + global_timeout < time.time(): if not testweb: print('\nGlobal testing timeout reached\n') break tt, FtOut, FtErr, bodyline, reason = -1,F_SKIP,F_SKIP,None,'as the global timeout has been reached' else: - os.environ['TST'] = TST - tt, FtOut, FtErr, bodyline, reason, links = RunTest(env, TST, COND, oktests, length, pSrvr, total_tests, test_progress, options) + environ['TST'] = TST + tt, FtOut, FtErr, bodyline, reason, links = RunTest(env, TST, COND, oktests, length, pSrvr, total_tests, test_progress, options, environ, TSTDB, TSTDIR, TSTSRCDIR, RELSRCDIR, TSTTRGDIR) alllinks.extend(links) if tt >= 0: t = '%7.3f' % tt @@ -1402,13 +1383,12 @@ def PerformDir(env, testdir, testlist, t _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org