From bcf127e0472aec90a1569c4bfd9f1c86db88283e Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Wed, 29 Apr 2015 13:43:17 -0400 Subject: combox.silo.ComboxSilo.node_set: added an optional parameter called `num'. - Updated tests as usual. modified: combox/silo.py modified: tests/silo_test.py --- combox/silo.py | 6 +++++- tests/silo_test.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/combox/silo.py b/combox/silo.py index ed2210c..1b3eeac 100644 --- a/combox/silo.py +++ b/combox/silo.py @@ -143,16 +143,20 @@ class ComboxSilo(object): return self.node_dicts - def node_set(self, type_, file_): + def node_set(self, type_, file_, num=-1): """ Update information about the shard of `file_'. type_: 'file_created', 'file_modified', 'file_moved', 'file_deleted' file_: path of the file_ in combox directory. + num: (optional) integer associated with the `file_'. """ self.reload() with self.lock: + if num != -1: + self.db.dadd(type_, (file_, num)) + return try: num = self.db.dget(type_, file_) num += 1 diff --git a/tests/silo_test.py b/tests/silo_test.py index 983ef1b..174dfd5 100644 --- a/tests/silo_test.py +++ b/tests/silo_test.py @@ -129,6 +129,10 @@ class TestSilo(object): assert_equal(3, dict_file_created[self.LOREM]) assert_equal(4, dict_file_created[self.IPSUM]) + silo.node_set('file_created', self.LOREM, 15) + dict_file_created = silo.db.get('file_created') + assert_equal(15, dict_file_created[self.LOREM]) + def test_csilo_nodset_modified(self): """Tests node_set method, in ComboxSilo class, when type is 'file_modified'. @@ -148,6 +152,10 @@ class TestSilo(object): assert_equal(3, dict_file_modified[self.LOREM]) assert_equal(4, dict_file_modified[self.IPSUM]) + silo.node_set('file_modified', self.LOREM, 15) + dict_file_modified = silo.db.get('file_modified') + assert_equal(15, dict_file_modified[self.LOREM]) + def test_csilo_nodset_moved(self): """Tests node_set method, in ComboxSilo class, when type is 'file_moved'. @@ -167,6 +175,9 @@ class TestSilo(object): assert_equal(3, dict_file_moved[self.LOREM]) assert_equal(4, dict_file_moved[self.IPSUM]) + silo.node_set('file_moved', self.LOREM, 15) + dict_file_moved = silo.db.get('file_moved') + assert_equal(15, dict_file_moved[self.LOREM]) def test_csilo_nodset_file_deleted(self): """Tests node_set method in ComboxSilo class, when type is 'file_deleted'. @@ -186,6 +197,10 @@ class TestSilo(object): assert_equal(3, dict_file_deleted[self.LOREM]) assert_equal(4, dict_file_deleted[self.IPSUM]) + silo.node_set('file_deleted', self.LOREM, 15) + dict_file_deleted = silo.db.get('file_deleted') + assert_equal(15, dict_file_deleted[self.LOREM]) + def test_csilo_nodeget(self): """Tests node_get method in ComboxSilo class -- cgit v1.2.3