Changeset: ab1c32f0550b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ab1c32f0550b
Added Files:
        common/stream/Tests/read_concatenated_bz2.py
        common/stream/Tests/read_concatenated_gz.py
        common/stream/Tests/read_concatenated_lz4.py
        common/stream/Tests/read_concatenated_xz.py
Modified Files:
        common/stream/Tests/All
        common/stream/Tests/read_tests.py
        common/stream/Tests/testdata.py
Branch: default
Log Message:

Add tests for reading concatenated compressed files


diffs (107 lines):

diff --git a/common/stream/Tests/All b/common/stream/Tests/All
--- a/common/stream/Tests/All
+++ b/common/stream/Tests/All
@@ -14,3 +14,7 @@ HAVE_CURL?urlstream
 read_iconv
 write_iconv
 
+HAVE_LIBBZ2?read_concatenated_bz2
+HAVE_LIBZ?read_concatenated_gz
+HAVE_LIBLZ4&HAVE_PYTHON_LZ4?read_concatenated_lz4
+HAVE_LIBLZMA?read_concatenated_xz
diff --git a/common/stream/Tests/read_concatenated_bz2.py 
b/common/stream/Tests/read_concatenated_bz2.py
new file mode 100644
--- /dev/null
+++ b/common/stream/Tests/read_concatenated_bz2.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sys, os
+sys.path.append(os.environ.get('TSTSRCDIR','.'))
+import read_tests
+
+read_tests.read_concatenated('bz2')
diff --git a/common/stream/Tests/read_concatenated_gz.py 
b/common/stream/Tests/read_concatenated_gz.py
new file mode 100644
--- /dev/null
+++ b/common/stream/Tests/read_concatenated_gz.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sys, os
+sys.path.append(os.environ.get('TSTSRCDIR','.'))
+import read_tests
+
+read_tests.read_concatenated('gz')
diff --git a/common/stream/Tests/read_concatenated_lz4.py 
b/common/stream/Tests/read_concatenated_lz4.py
new file mode 100644
--- /dev/null
+++ b/common/stream/Tests/read_concatenated_lz4.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sys, os
+sys.path.append(os.environ.get('TSTSRCDIR','.'))
+import read_tests
+
+read_tests.read_concatenated('lz4')
diff --git a/common/stream/Tests/read_concatenated_xz.py 
b/common/stream/Tests/read_concatenated_xz.py
new file mode 100644
--- /dev/null
+++ b/common/stream/Tests/read_concatenated_xz.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import sys, os
+sys.path.append(os.environ.get('TSTSRCDIR','.'))
+import read_tests
+
+read_tests.read_concatenated('xz')
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
@@ -115,6 +115,27 @@ def all_tests(filename_filter):
     return failures
 
 
+def read_concatenated(ext):
+    tf1 = TestFile("concatenated1", ext)
+    tf1.write(b"hi")
+    compressed_content = open(tf1.path(), "rb").read()
+
+    tf2 = TestFile("concatenated2", ext)
+    tf2.write_raw(compressed_content + compressed_content)
+
+    cmd = ['streamcat', 'read', tf2.path(), "rstream"]
+    results = subprocess.run(
+        cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    if results.returncode != 0 or results.stderr:
+        raise SystemExit(f"Command {cmd} returned with exit code 
{results.returncode}:\n{results.stderr or ''}")
+
+    output = results.stdout
+
+    expected = b'hihi'
+    if output != expected:
+        raise SystemExit(f"Expected {expected!r}, got {output!r}")
+
+
 if __name__ == "__main__":
     # generate test data for manual testing
     if len(sys.argv) == 1:
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
@@ -218,6 +218,13 @@ class TestFile:
         f.write(content)
         return filename
 
+
+    def write_raw(self, content):
+        filename = self.path()
+        f = open(filename, 'wb')
+        f.write(content)
+        return filename
+
     def read(self):
         filename = self.path()
         if not self.compression:
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to