Python SDK uses ~/.config/arvados/settings.conf like other SDKs.
[arvados.git] / sdk / python / test_collections.py
index 64a08058bfb42d8e064ae350f9ebc4d6f96661bc..913c8888304db331681b48c19477caeba402bdaf 100644 (file)
@@ -7,6 +7,7 @@ import arvados
 import os
 import bz2
 import sys
+import subprocess
 
 class KeepLocalStoreTest(unittest.TestCase):
     def setUp(self):
@@ -33,7 +34,7 @@ class LocalCollectionWriterTest(unittest.TestCase):
         cw.set_current_file_name('baz.txt')
         hash = cw.finish()
         self.assertEqual(hash,
-                         'a4d26dddc10ad8b5eb39347c916de16c+112',
+                         '23ca013983d6239e98931cc779e68426+114',
                          'resulting manifest hash is not what I expected')
 
 class LocalCollectionReaderTest(unittest.TestCase):
@@ -41,14 +42,14 @@ class LocalCollectionReaderTest(unittest.TestCase):
         os.environ['KEEP_LOCAL_STORE'] = '/tmp'
         LocalCollectionWriterTest().runTest()
     def runTest(self):
-        cr = arvados.CollectionReader('a4d26dddc10ad8b5eb39347c916de16c+112')
+        cr = arvados.CollectionReader('23ca013983d6239e98931cc779e68426+114')
         got = []
         for s in cr.all_streams():
             for f in s.all_files():
                 got += [[f.size(), f.stream_name(), f.name(), f.read(2**26)]]
         expected = [[3, '.', 'foo.txt', 'foo'],
                     [3, '.', 'bar.txt', 'bar'],
-                    [3, 'baz', 'baz.txt', 'baz']]
+                    [3, './baz', 'baz.txt', 'baz']]
         self.assertEqual(got,
                          expected,
                          'resulting file list is not what I expected')
@@ -71,10 +72,10 @@ class LocalCollectionManifestSubsetTest(unittest.TestCase):
         os.environ['KEEP_LOCAL_STORE'] = '/tmp'
         LocalCollectionWriterTest().runTest()
     def runTest(self):
-        self._runTest('a4d26dddc10ad8b5eb39347c916de16c+112',
+        self._runTest('23ca013983d6239e98931cc779e68426+114',
                       [[3, '.', 'foo.txt', 'foo'],
                        [3, '.', 'bar.txt', 'bar'],
-                       [3, 'baz', 'baz.txt', 'baz']])
+                       [3, './baz', 'baz.txt', 'baz']])
         self._runTest((". %s %s 0:3:foo.txt 3:3:bar.txt\n" %
                        (arvados.Keep.put("foo"),
                         arvados.Keep.put("bar"))),
@@ -175,3 +176,32 @@ class LocalCollectionBZ2DecompressionTest(unittest.TestCase):
         self.assertEqual(got,
                          n_lines_in,
                          "decompression returned %d lines instead of %d" % (got, n_lines_in))
+
+class LocalCollectionGzipDecompressionTest(unittest.TestCase):
+    def setUp(self):
+        os.environ['KEEP_LOCAL_STORE'] = '/tmp'
+    def runTest(self):
+        n_lines_in = 2**18
+        data_in = "abc\n"
+        for x in xrange(0, 18):
+            data_in += data_in
+        p = subprocess.Popen(["gzip", "-1cn"],
+                             stdout=subprocess.PIPE,
+                             stdin=subprocess.PIPE,
+                             stderr=subprocess.PIPE,
+                             shell=False, close_fds=True)
+        compressed_data_in, stderrdata = p.communicate(data_in)
+
+        cw = arvados.CollectionWriter()
+        cw.start_new_file('test.gz')
+        cw.write(compressed_data_in)
+        gzip_manifest = cw.manifest_text()
+
+        cr = arvados.CollectionReader(gzip_manifest)
+        got = 0
+        for x in list(cr.all_files())[0].readlines():
+            self.assertEqual(x, "abc\n", "decompression returned wrong data: %s" % x)
+            got += 1
+        self.assertEqual(got,
+                         n_lines_in,
+                         "decompression returned %d lines instead of %d" % (got, n_lines_in))