Changeset: db0adbfeb395 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/db0adbfeb395
Modified Files:
        clients/Tests/exports.py
        common/stream/Tests/read_tests.py
        common/stream/Tests/testdata.py
        common/stream/Tests/write_tests.py
        sql/test/BugDay_2005-10-06_2.8/Tests/MapiClient-dump.SF-905851.SQL.py
        sql/test/bincopy/Tests/bincopy_support.py
        sql/test/concurrent/Tests/truncate-insert-flood.SQL.py
        sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.py
        sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py
        sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.py
        sql/test/emptydb-previous-upgrade/Tests/upgrade.py
        sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.py
        sql/test/emptydb-upgrade-chain/Tests/upgrade.py
        sql/test/emptydb-upgrade-hge/Tests/upgrade.py
        sql/test/emptydb-upgrade/Tests/upgrade.py
        sql/test/emptydb/Tests/check.SQL.py
        sql/test/remote/Tests/ssbm.SQL.py
        sql/test/testdb-previous-upgrade-chain-hge/Tests/upgrade.py
        sql/test/testdb-previous-upgrade-chain/Tests/upgrade.py
        sql/test/testdb-previous-upgrade-hge/Tests/upgrade.py
        sql/test/testdb-previous-upgrade/Tests/upgrade.py
        sql/test/testdb-reload/Tests/reload.py
        sql/test/testdb-reload2/Tests/reload.py
        sql/test/testdb-upgrade-chain-hge/Tests/upgrade.py
        sql/test/testdb-upgrade-chain/Tests/upgrade.py
        sql/test/testdb-upgrade-hge/Tests/upgrade.py
        sql/test/testdb-upgrade/Tests/upgrade.py
        sql/test/testdb/Tests/dump.SQL.py
        testing/Mtest.py.in
        testing/exportutils.py
        testing/process.py
        testing/sqllogictest.py
        testing/tlstester.py
        tools/merovingian/client/Tests/monetdbd.py
Branch: Mar2025
Log Message:

Improve experience when running Mtest with python-debug.
(sudo dnf install python3-debug)


diffs (truncated from 1060 to 300 lines):

diff --git a/clients/Tests/exports.py b/clients/Tests/exports.py
--- a/clients/Tests/exports.py
+++ b/clients/Tests/exports.py
@@ -1,7 +1,8 @@
 import sys
 import difflib
 import MonetDBtesting.listexports
-stable = open('exports.stable.out').readlines()
+with open('exports.stable.out') as fil:
+    stable = fil.readlines()
 output = MonetDBtesting.listexports.listexports()
 for line in difflib.unified_diff(stable, output):
     sys.stderr.write(line)
diff --git a/common/stream/Tests/read_tests.py 
b/common/stream/Tests/read_tests.py
--- a/common/stream/Tests/read_tests.py
+++ b/common/stream/Tests/read_tests.py
@@ -118,7 +118,8 @@ def all_tests(filename_filter):
 def read_concatenated(ext):
     tf1 = TestFile("concatenated1", ext)
     tf1.write(b"hi")
-    compressed_content = open(tf1.path(), "rb").read()
+    with open(tf1.path(), "rb") as fil:
+        compressed_content = fil.read()
 
     tf2 = TestFile("concatenated2", ext)
     tf2.write_raw(compressed_content + compressed_content)
diff --git a/common/stream/Tests/testdata.py b/common/stream/Tests/testdata.py
--- a/common/stream/Tests/testdata.py
+++ b/common/stream/Tests/testdata.py
@@ -20,7 +20,8 @@ SRCDIR = os.environ.get(
 # The functions we pass this to will pick their own default if None:
 TMPDIR = os.environ.get('TSTTRGDIR')
 
-SHERLOCK = gzip.open(os.path.join(SRCDIR, '1661-0.txt.gz'), 
'rb').read().replace(CRLF, LF)
+with gzip.open(os.path.join(SRCDIR, '1661-0.txt.gz'), 'rb') as fil:
+    SHERLOCK = fil.read().replace(CRLF, LF)
 
 COMPRESSIONS = [None, "gz", "bz2", "xz", "lz4"]
 
@@ -198,32 +199,30 @@ class TestFile:
 
     def write(self, content):
         filename = self.path()
-        fileobj = open(filename, 'wb')
-
-        if not self.compression:
-            f = fileobj
-        elif self.compression == 'gz':
-            f = gzip.GzipFile(filename, 'wb', fileobj=fileobj, 
mtime=131875200, compresslevel=1)
-        elif self.compression == 'bz2':
-            import bz2
-            f = bz2.BZ2File(fileobj, 'wb', compresslevel=1)
-        elif self.compression == 'xz':
-            import lzma
-            f = lzma.LZMAFile(fileobj, 'wb', preset=1)
-        elif self.compression == 'lz4': # ok
-            import lz4.frame
-            f = lz4.frame.LZ4FrameFile(fileobj, 'wb', compression_level=1)
-        else:
-            raise Exception("Unknown compression scheme: " + self.compression)
-        f.write(content)
-        f.close()
+        with open(filename, 'wb') as fileobj:
+            if not self.compression:
+                f = fileobj
+            elif self.compression == 'gz':
+                f = gzip.GzipFile(filename, 'wb', fileobj=fileobj, 
mtime=131875200, compresslevel=1)
+            elif self.compression == 'bz2':
+                import bz2
+                f = bz2.BZ2File(fileobj, 'wb', compresslevel=1)
+            elif self.compression == 'xz':
+                import lzma
+                f = lzma.LZMAFile(fileobj, 'wb', preset=1)
+            elif self.compression == 'lz4': # ok
+                import lz4.frame
+                f = lz4.frame.LZ4FrameFile(fileobj, 'wb', compression_level=1)
+            else:
+                raise Exception("Unknown compression scheme: " + 
self.compression)
+            f.write(content)
+            f.close()
         return filename
 
-
     def write_raw(self, content):
         filename = self.path()
-        f = open(filename, 'wb')
-        f.write(content)
+        with open(filename, 'wb') as f:
+            f.write(content)
         return filename
 
     def read(self):
@@ -244,7 +243,9 @@ class TestFile:
         else:
             raise Exception("Unknown compression scheme: " + self.compression)
 
-        return f.read()
+        data = f.read()
+        f.close()
+        return data
 
 
 
diff --git a/common/stream/Tests/write_tests.py 
b/common/stream/Tests/write_tests.py
--- a/common/stream/Tests/write_tests.py
+++ b/common/stream/Tests/write_tests.py
@@ -46,7 +46,8 @@ class TestCase:
             return False
 
         # Trial run to rule out i/o errors
-        open(filename, 'rb').read()
+        with open(filename, 'rb') as fil:
+            fil.read()
 
         try:
             output = self.tf.read()  # should decompress it
diff --git 
a/sql/test/BugDay_2005-10-06_2.8/Tests/MapiClient-dump.SF-905851.SQL.py 
b/sql/test/BugDay_2005-10-06_2.8/Tests/MapiClient-dump.SF-905851.SQL.py
--- a/sql/test/BugDay_2005-10-06_2.8/Tests/MapiClient-dump.SF-905851.SQL.py
+++ b/sql/test/BugDay_2005-10-06_2.8/Tests/MapiClient-dump.SF-905851.SQL.py
@@ -26,7 +26,8 @@ def main():
                         'JdbcClient_inserts_selects.sql'))
     out = client('sqldump')
     output = out.splitlines(keepends=True)
-    stable = open('MapiClient-dump.SF-905851.stable.out').readlines()
+    with open('MapiClient-dump.SF-905851.stable.out') as fil:
+        stable = fil.readlines()
     for line in difflib.unified_diff(stable, output):
         sys.stderr.write(line)
 
diff --git a/sql/test/bincopy/Tests/bincopy_support.py 
b/sql/test/bincopy/Tests/bincopy_support.py
--- a/sql/test/bincopy/Tests/bincopy_support.py
+++ b/sql/test/bincopy/Tests/bincopy_support.py
@@ -98,7 +98,8 @@ def run_test(side, testcase):
     massage = lambda s: re.sub(r'@(>?(\w|!)+)@', data_maker.substitute_match, 
s)
     code = massage(code)
     code = f"START TRANSACTION;\n{code}\nROLLBACK;\n"
-    open(os.path.join(BINCOPY_FILES, 'test.sql'), "w").write(code)
+    with open(os.path.join(BINCOPY_FILES, 'test.sql'), "w") as fil:
+        fil.write(code)
 
     # generate the required data files
     data_maker.generate_files()
@@ -118,8 +119,10 @@ def run_test(side, testcase):
         for outfile, expected in data_maker.outfiles():
             if not os.path.exists(outfile):
                 tr.fail(f'Output file {outfile} was not created')
-            expected_content = open(expected, 'rb').read()
-            content = open(outfile, 'rb').read()
+            with open(expected, 'rb') as fil:
+                expected_content = fil.read()
+            with open(outfile, 'rb') as fil:
+                content = fil.read()
             if len(content) != len(expected_content):
                 tr.fail(f'Outfile {outfile} has wrong length: {len(content)}, 
expected {len(expected_content)}')
             elif content != expected_content:
diff --git a/sql/test/concurrent/Tests/truncate-insert-flood.SQL.py 
b/sql/test/concurrent/Tests/truncate-insert-flood.SQL.py
--- a/sql/test/concurrent/Tests/truncate-insert-flood.SQL.py
+++ b/sql/test/concurrent/Tests/truncate-insert-flood.SQL.py
@@ -7,6 +7,7 @@ nr_clients = 16
 db = os.getenv("TSTDB")
 port = os.getenv("MAPIPORT")
 
+
 def client(id):
     conn = pymonetdb.connect(
                     database=db,
@@ -34,6 +35,8 @@ def client(id):
     nr_queries = 1600
     for x in range(0, nr_queries):
         cursor.execute(truncate_and_insert_queries)
+    conn.close()
+
 
 with ThreadPoolExecutor(nr_clients) as pool:
     pool.map(client, range(nr_clients))
diff --git a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.py 
b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.py
--- a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.py
+++ b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.py
@@ -72,7 +72,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py 
b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py
--- a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py
+++ b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.py
@@ -72,7 +72,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.py 
b/sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.py
--- a/sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.py
+++ b/sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.py
@@ -71,7 +71,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-previous-upgrade/Tests/upgrade.py 
b/sql/test/emptydb-previous-upgrade/Tests/upgrade.py
--- a/sql/test/emptydb-previous-upgrade/Tests/upgrade.py
+++ b/sql/test/emptydb-previous-upgrade/Tests/upgrade.py
@@ -72,7 +72,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.py 
b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.py
--- a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.py
+++ b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.py
@@ -72,7 +72,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-upgrade-chain/Tests/upgrade.py 
b/sql/test/emptydb-upgrade-chain/Tests/upgrade.py
--- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.py
+++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.py
@@ -72,7 +72,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-upgrade-hge/Tests/upgrade.py 
b/sql/test/emptydb-upgrade-hge/Tests/upgrade.py
--- a/sql/test/emptydb-upgrade-hge/Tests/upgrade.py
+++ b/sql/test/emptydb-upgrade-hge/Tests/upgrade.py
@@ -71,7 +71,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb-upgrade/Tests/upgrade.py 
b/sql/test/emptydb-upgrade/Tests/upgrade.py
--- a/sql/test/emptydb-upgrade/Tests/upgrade.py
+++ b/sql/test/emptydb-upgrade/Tests/upgrade.py
@@ -72,7 +72,8 @@ if len(sys.argv) == 2 and sys.argv[1] ==
                 break
         if found:
             break
-    stable = open(f).readlines()
+    with open(f) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff(stable, srvout, fromfile='test', 
tofile=f):
         sys.stderr.write(line)
diff --git a/sql/test/emptydb/Tests/check.SQL.py 
b/sql/test/emptydb/Tests/check.SQL.py
--- a/sql/test/emptydb/Tests/check.SQL.py
+++ b/sql/test/emptydb/Tests/check.SQL.py
@@ -587,7 +587,8 @@ with process.client('sql', interactive=T
 if check:
     output = ''.join(output).splitlines(keepends=True)
     stableout = 'check.stable.out.32bit' if os.getenv('TST_BITS', '') == 
'32bit' else 'check.stable.out.int128' if os.getenv('HAVE_HGE') else 
'check.stable.out'
-    stable = open(stableout).readlines()
+    with open(stableout) as fil:
+        stable = fil.readlines()
     import difflib
     for line in difflib.unified_diff([x for x in stable if not 
x.startswith('%')], [x for x in output if not x.startswith('%')], 
fromfile='test', tofile=stableout):
         sys.stderr.write(line)
diff --git a/sql/test/remote/Tests/ssbm.SQL.py 
b/sql/test/remote/Tests/ssbm.SQL.py
--- a/sql/test/remote/Tests/ssbm.SQL.py
+++ b/sql/test/remote/Tests/ssbm.SQL.py
@@ -617,7 +617,8 @@ with tempfile.TemporaryDirectory() as tm
             shutil.rmtree(lineorderdir)
         if not os.path.exists(lineorderdir):
             os.makedirs(lineorderdir)
-        inputData = open(lineordertbl, 'r').read().split('\n')
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to