def test_add_with_caching(self): s = MemoryKeyValueStore() s._cache_element = DataMemoryElement() expected_cache_dict = {'a': 'b', 'foo': None, 0: 89} s.add('a', 'b') s.add('foo', None) s.add(0, 89) nose.tools.assert_equal(pickle.loads(s._cache_element.get_bytes()), expected_cache_dict)
def test_add_with_caching(self): """ Test that we can add key-value pairs and they reflect in the cache element. """ c = DataMemoryElement() s = MemoryKeyValueStore(c) expected_cache_dict = {'a': 'b', 'foo': None, 0: 89} s.add('a', 'b') s.add('foo', None) s.add(0, 89) self.assertEqual(pickle.loads(c.get_bytes()), expected_cache_dict)
def test_update_index_existing_descriptors_frozenset(self): """ Same as ``test_update_index_similar_descriptors`` but testing that we can update the index when seeded with structures with existing values. """ # Similar Descriptors to build and update on (different instances) descriptors1 = [ DescriptorMemoryElement('t', 0).set_vector([0]), DescriptorMemoryElement('t', 1).set_vector([1]), DescriptorMemoryElement('t', 2).set_vector([2]), DescriptorMemoryElement('t', 3).set_vector([3]), DescriptorMemoryElement('t', 4).set_vector([4]), ] descriptors2 = [ DescriptorMemoryElement('t', 5).set_vector([0]), DescriptorMemoryElement('t', 6).set_vector([1]), DescriptorMemoryElement('t', 7).set_vector([2]), DescriptorMemoryElement('t', 8).set_vector([3]), DescriptorMemoryElement('t', 9).set_vector([4]), ] descr_set = MemoryDescriptorSet() descr_set.add_many_descriptors(descriptors1) hash_kvs = MemoryKeyValueStore() hash_kvs.add(0, frozenset({0})) hash_kvs.add(1, frozenset({1})) hash_kvs.add(2, frozenset({2})) hash_kvs.add(3, frozenset({3})) hash_kvs.add(4, frozenset({4})) index = LSHNearestNeighborIndex(DummyHashFunctor(), descr_set, hash_kvs) index.update_index(descriptors2) assert descr_set.count() == 10 # Above descriptors should be considered "in" the descriptor set now. for d in descriptors1: assert d in descr_set for d in descriptors2: assert d in descr_set # Known hashes of the above descriptors should be in the KVS assert set(hash_kvs.keys()) == {0, 1, 2, 3, 4} assert hash_kvs.get(0) == {0, 5} assert hash_kvs.get(1) == {1, 6} assert hash_kvs.get(2) == {2, 7} assert hash_kvs.get(3) == {3, 8} assert hash_kvs.get(4) == {4, 9}
def test_update_index_existing_descriptors_frozenset(self): """ Same as ``test_update_index_similar_descriptors`` but testing that we can update the index when seeded with structures with existing values. """ # Similar Descriptors to build and update on (different instances) descriptors1 = [ DescriptorMemoryElement('t', 0).set_vector([0]), DescriptorMemoryElement('t', 1).set_vector([1]), DescriptorMemoryElement('t', 2).set_vector([2]), DescriptorMemoryElement('t', 3).set_vector([3]), DescriptorMemoryElement('t', 4).set_vector([4]), ] descriptors2 = [ DescriptorMemoryElement('t', 5).set_vector([0]), DescriptorMemoryElement('t', 6).set_vector([1]), DescriptorMemoryElement('t', 7).set_vector([2]), DescriptorMemoryElement('t', 8).set_vector([3]), DescriptorMemoryElement('t', 9).set_vector([4]), ] descr_index = MemoryDescriptorIndex() descr_index.add_many_descriptors(descriptors1) hash_kvs = MemoryKeyValueStore() hash_kvs.add(0, frozenset({0})) hash_kvs.add(1, frozenset({1})) hash_kvs.add(2, frozenset({2})) hash_kvs.add(3, frozenset({3})) hash_kvs.add(4, frozenset({4})) index = LSHNearestNeighborIndex(DummyHashFunctor(), descr_index, hash_kvs) index.update_index(descriptors2) assert descr_index.count() == 10 # Above descriptors should be considered "in" the descriptor set now. for d in descriptors1: assert d in descr_index for d in descriptors2: assert d in descr_index # Known hashes of the above descriptors should be in the KVS assert set(hash_kvs.keys()) == {0, 1, 2, 3, 4} assert hash_kvs.get(0) == {0, 5} assert hash_kvs.get(1) == {1, 6} assert hash_kvs.get(2) == {2, 7} assert hash_kvs.get(3) == {3, 8} assert hash_kvs.get(4) == {4, 9}
def test_add_with_caching(self): """ Test that we can add key-value pairs and they reflect in the cache element. """ c = DataMemoryElement() s = MemoryKeyValueStore(c) expected_cache_dict = {'a': 'b', 'foo': None, 0: 89} s.add('a', 'b') s.add('foo', None) s.add(0, 89) self.assertEqual( pickle.loads(c.get_bytes()), expected_cache_dict )
def test_add(self): s = MemoryKeyValueStore() s.add('a', 'b') nose.tools.assert_equal(s._table, {'a': 'b'}) s.add('foo', None) nose.tools.assert_equal(s._table, { 'a': 'b', 'foo': None, }) s.add(0, 89) nose.tools.assert_equal(s._table, { 'a': 'b', 'foo': None, 0: 89, })
def test_add_with_caching_no_cache(self): c = DataMemoryElement() s = MemoryKeyValueStore(c) expected_cache_dict = {'a': 'b', 'foo': None} s.add('a', 'b', False) # No caching means there should be nothign there yet nose.tools.assert_equal(c.get_bytes(), six.b("")) s.add('foo', None, True) # With caching, meaning the state should be cached here, which includes # everything added previously, including the a:b pair. nose.tools.assert_equal(pickle.loads(c.get_bytes()), expected_cache_dict) s.add(0, 89, False) nose.tools.assert_equal(pickle.loads(c.get_bytes()), expected_cache_dict)
def test_add(self): """ Test that we can add key-value pairs. """ s = MemoryKeyValueStore() s.add('a', 'b') self.assertEqual(s._table, {'a': 'b'}) s.add('foo', None) self.assertEqual(s._table, { 'a': 'b', 'foo': None, }) s.add(0, 89) self.assertEqual(s._table, { 'a': 'b', 'foo': None, 0: 89, })