Пример #1
0
 def test_get_config_no_cache_elem(self):
     s = MemoryKeyValueStore()
     s._cache_element = None
     # We expect an default DataElement config (no impl type defined)
     c = s.get_config()
     self.assertIn('cache_element', c)
     self.assertIsNone(c['cache_element']['type'])
 def test_get_config_no_cache_elem(self):
     """
     Test that configuration returned reflects no cache element being set.
     """
     s = MemoryKeyValueStore()
     s._cache_element = None
     # We expect an default DataElement config (no impl type defined)
     c = s.get_config()
     self.assertIn('cache_element', c)
     self.assertIsNone(c['cache_element']['type'])
Пример #3
0
 def test_get_config_no_cache_elem(self):
     """
     Test that configuration returned reflects no cache element being set.
     """
     s = MemoryKeyValueStore()
     s._cache_element = None
     # We expect an default DataElement config (no impl type defined)
     c = s.get_config()
     self.assertIn('cache_element', c)
     self.assertIsNone(c['cache_element']['type'])
Пример #4
0
    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)
Пример #5
0
 def test_get_config_mem_cache_elem(self):
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement('someBytes', 'text/plain', False)
     expected_config = {
         'cache_element': {
             "DataMemoryElement": {
                 'bytes': 'someBytes',
                 'content_type': 'text/plain',
                 'readonly': False,
             },
             'type': 'DataMemoryElement'
         }
     }
     nose.tools.assert_equal(s.get_config(), expected_config)
Пример #6
0
 def test_get_config_mem_cache_elem(self):
     """
     Test that configuration returned reflects the cache element that is
     set.
     """
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(six.b('someBytes'), 'text/plain', False)
     expected_config = {'cache_element': {
         "DataMemoryElement": {
             'bytes': six.b('someBytes'),
             'content_type': 'text/plain',
             'readonly': False,
         },
         'type': 'DataMemoryElement'
     }}
     self.assertEqual(s.get_config(), expected_config)
 def test_get_config_mem_cache_elem(self):
     """
     Test that configuration returned reflects the cache element that is
     set.
     """
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(b'someBytes',
                                          'text/plain',
                                          readonly=False)
     dme_key = 'smqtk.representation.data_element.memory_element.DataMemoryElement'
     expected_config = {
         'cache_element': {
             dme_key: {
                 'bytes': 'someBytes',
                 'content_type': 'text/plain',
                 'readonly': False,
             },
             'type': dme_key
         }
     }
     self.assertEqual(s.get_config(), expected_config)
Пример #8
0
    def test_add_read_only(self):
        s = MemoryKeyValueStore()
        s._cache_element = DataMemoryElement(readonly=True)

        nose.tools.assert_raises(ReadOnlyError, s.add, 'a', 'b')
        nose.tools.assert_raises(ReadOnlyError, s.add, 'foo', None)
Пример #9
0
 def test_read_only_with_read_only_cache(self):
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(readonly=True)
     nose.tools.assert_true(s.is_read_only())
Пример #10
0
 def test_read_only_with_writable_cache(self):
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(readonly=False)
     nose.tools.assert_false(s.is_read_only())
Пример #11
0
 def test_get_config_no_cache_elem(self):
     s = MemoryKeyValueStore()
     s._cache_element = None
     expected_config = {'cache_element': None}
     nose.tools.assert_equal(s.get_config(), expected_config)
 def test_read_only_with_read_only_cache(self):
     """ Test that read-only status reflects a read-only cache """
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(readonly=True)
     self.assertTrue(s.is_read_only())
 def test_read_only_with_writable_cache(self):
     """ Test that read-only status reflects a non-read-only cache """
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(readonly=False)
     self.assertFalse(s.is_read_only())
Пример #14
0
 def test_read_only_with_read_only_cache(self):
     """ Test that read-only status reflects a read-only cache """
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(readonly=True)
     self.assertTrue(s.is_read_only())
Пример #15
0
 def test_read_only_with_writable_cache(self):
     """ Test that read-only status reflects a non-read-only cache """
     s = MemoryKeyValueStore()
     s._cache_element = DataMemoryElement(readonly=False)
     self.assertFalse(s.is_read_only())