[ARVADOS] updated: 130b8d3147af5240ba3118c56b0aa1f19d2d5c59
git at public.curoverse.com
git at public.curoverse.com
Tue Feb 3 16:35:48 EST 2015
Summary of changes:
sdk/python/arvados/arvfile.py | 2 +-
sdk/python/arvados/collection.py | 31 ++++++++++++++++++++++---------
sdk/python/tests/test_arvfile.py | 10 ++++++++--
sdk/python/tests/test_collections.py | 29 +++++++++++++++++++++++++++--
4 files changed, 58 insertions(+), 14 deletions(-)
via 130b8d3147af5240ba3118c56b0aa1f19d2d5c59 (commit)
from a7b16675337995c65b909a7519178efed98a3089 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 130b8d3147af5240ba3118c56b0aa1f19d2d5c59
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date: Tue Feb 3 16:37:57 2015 -0500
4823: Add tests for Collection.clone and Collection.merge
diff --git a/sdk/python/arvados/arvfile.py b/sdk/python/arvados/arvfile.py
index fb761e2..2edd2e9 100644
--- a/sdk/python/arvados/arvfile.py
+++ b/sdk/python/arvados/arvfile.py
@@ -602,7 +602,7 @@ class ArvadosFile(object):
return False
return self._segments == other.segments()
- def __neq__(self, other):
+ def __ne__(self, other):
return not self.__eq__(other)
@_synchronized
diff --git a/sdk/python/arvados/collection.py b/sdk/python/arvados/collection.py
index ddf2eae..1f2974b 100644
--- a/sdk/python/arvados/collection.py
+++ b/sdk/python/arvados/collection.py
@@ -858,8 +858,8 @@ class SynchronizedCollectionBase(CollectionBase):
raise IOError((errno.ENOENT, "File not found"))
def _cloneinto(self, target):
- for k,v in self._items:
- target._items[k] = v.clone(new_parent=target)
+ for k,v in self._items.items():
+ target._items[k] = v.clone(target)
def clone(self):
raise NotImplementedError()
@@ -867,9 +867,22 @@ class SynchronizedCollectionBase(CollectionBase):
@_must_be_writable
@_synchronized
def copy(self, source_path, target_path, source_collection=None, overwrite=False):
- """
- copyto('/foo', '/bar') will overwrite 'foo' if it exists.
- copyto('/foo/', '/bar') will place 'bar' in subcollection 'foo'
+ """Copy a file or subcollection to a new path in this collection.
+
+ :source_path:
+ Source file or subcollection
+
+ :target_path:
+ Destination file or path. If the target path already exists and is a
+ subcollection, the item will be placed inside the subcollection. If
+ the target path already exists and is a file, this will raise an error
+ unless you specify `overwrite=True`.
+
+ :source_collection:
+ Collection to copy `source_path` from (default `self`)
+
+ :overwrite:
+ Whether to overwrite target file if it already exists.
"""
if source_collection is None:
source_collection = self
@@ -934,12 +947,12 @@ class SynchronizedCollectionBase(CollectionBase):
self[k].merge(other[k])
else:
if self[k] != other[k]:
- name = "%s~conflict-%s~" % (k, time.strftime("%Y-%m-%d_%H:%M%:%S",
+ name = "%s~conflict-%s~" % (k, time.strftime("%Y-%m-%d_%H:%M:%S",
time.gmtime()))
- self[name] = other[k].clone(self)
+ self._items[name] = other[k].clone(self)
self.notify(self, name, ADD, self[name])
else:
- self[k] = other[k].clone(self)
+ self._items[k] = other[k].clone(self)
self.notify(self, k, ADD, self[k])
def portable_data_hash(self):
@@ -1143,7 +1156,7 @@ class Collection(SynchronizedCollectionBase):
@_synchronized
def clone(self, new_parent=None, new_sync=SYNC_READONLY, new_config=None):
if new_config is None:
- new_config = self.config
+ new_config = self._config
c = Collection(parent=new_parent, config=new_config, sync=new_sync)
if new_sync == SYNC_READONLY:
c.lock = NoopLock()
diff --git a/sdk/python/tests/test_arvfile.py b/sdk/python/tests/test_arvfile.py
index 06c70f0..6e090e4 100644
--- a/sdk/python/tests/test_arvfile.py
+++ b/sdk/python/tests/test_arvfile.py
@@ -372,8 +372,14 @@ class ArvadosFileReaderTestCase(StreamFileReaderTestCase):
with import_manifest(". 2e9ec317e197819358fbc43afca7d837+8 e8dc4081b13434b45189a720b77b6818+8 0:16:count.txt\n", keep=keep) as c:
r = c.open("count.txt", "r")
self.assertEqual("0123", r.read(4))
- self.assertTrue("2e9ec317e197819358fbc43afca7d837+8" in keep.requests)
- self.assertTrue("e8dc4081b13434b45189a720b77b6818+8" in keep.requests)
+ self.assertIn("2e9ec317e197819358fbc43afca7d837+8", keep.requests)
+ self.assertIn("e8dc4081b13434b45189a720b77b6818+8", keep.requests)
+
+ def test__eq__(self):
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt') as c1:
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt') as c2:
+ self.assertTrue(c1["count1.txt"] == c2["count1.txt"])
+ self.assertFalse(c1["count1.txt"] != c2["count1.txt"])
class ArvadosFileReadTestCase(unittest.TestCase, StreamRetryTestMixin):
diff --git a/sdk/python/tests/test_collections.py b/sdk/python/tests/test_collections.py
index 892f146..5f86fa5 100644
--- a/sdk/python/tests/test_collections.py
+++ b/sdk/python/tests/test_collections.py
@@ -826,9 +826,9 @@ class NewCollectionTestCase(unittest.TestCase, CollectionTestMixin):
def test_remove(self):
with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt 0:10:count2.txt\n', sync=SYNC_EXPLICIT) as c:
self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt 0:10:count2.txt\n", export_manifest(c))
- self.assertTrue("count1.txt" in c)
+ self.assertIn("count1.txt", c)
c.remove("count1.txt")
- self.assertFalse("count1.txt" in c)
+ self.assertNotIn("count1.txt", c)
self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count2.txt\n", export_manifest(c))
def test_remove_in_subdir(self):
@@ -869,6 +869,31 @@ class NewCollectionTestCase(unittest.TestCase, CollectionTestMixin):
c.copy("count1.txt", "count2.txt")
self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt 0:10:count2.txt\n", export_manifest(c))
+ def test_clone(self):
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt\n./foo 781e5e245d69b566979b86e28d23f2c7+10 0:10:count2.txt\n', sync=SYNC_EXPLICIT) as c:
+ cl = c.clone()
+ self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt\n./foo 781e5e245d69b566979b86e28d23f2c7+10 0:10:count2.txt\n", export_manifest(cl))
+
+ def test_merge1(self):
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt', sync=SYNC_EXPLICIT) as c1:
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count2.txt') as c2:
+ c1.merge(c2)
+ self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt 0:10:count2.txt\n", export_manifest(c1))
+
+ def test_merge2(self):
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt', sync=SYNC_EXPLICIT) as c1:
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt') as c2:
+ c1.merge(c2)
+ self.assertEqual(". 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt\n", export_manifest(c1))
+
+ def test_merge3(self):
+ with arvados.import_manifest('. 781e5e245d69b566979b86e28d23f2c7+10 0:10:count1.txt', sync=SYNC_EXPLICIT) as c1:
+ with arvados.import_manifest('. 5348b82a029fd9e971a811ce1f71360b+43 0:10:count1.txt') as c2:
+ c1.merge(c2)
+ self.assertTrue(re.match(r". 781e5e245d69b566979b86e28d23f2c7\+10 5348b82a029fd9e971a811ce1f71360b\+43 0:10:count1.txt 10:10:count1.txt~conflict-\d\d\d\d-\d\d-\d\d_\d\d:\d\d:\d\d~\n", export_manifest(c1)))
+
+
+
if __name__ == '__main__':
unittest.main()
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list