示例#1
0
    def test_from_config_null_cache_elem(self):
        inst = MemoryDescriptorSet.from_config({'cache_element': None})
        self.assertIsNone(inst.cache_element)
        self.assertEqual(inst._table, {})

        inst = MemoryDescriptorSet.from_config(
            {'cache_element': {
                'type': None
            }})
        self.assertIsNone(inst.cache_element)
        self.assertEqual(inst._table, {})
示例#2
0
 def test_from_config_null_cache_elem_type(self):
     # An empty cache should not trigger loading on construction.
     expected_empty_cache = DataMemoryElement()
     dme_key = 'smqtk.representation.data_element.memory_element.DataMemoryElement'
     inst = MemoryDescriptorSet.from_config(
         {'cache_element': {
             'type': dme_key,
             dme_key: {
                 'bytes': ''
             }
         }})
     self.assertEqual(inst.cache_element, expected_empty_cache)
     self.assertEqual(inst._table, {})
示例#3
0
 def test_from_config_null_cache_elem_type(self):
     # An empty cache should not trigger loading on construction.
     expected_empty_cache = DataMemoryElement()
     inst = MemoryDescriptorSet.from_config({
         'cache_element': {
             'type': 'DataMemoryElement',
             'DataMemoryElement': {
                 'bytes': ''
             }
         }
     })
     self.assertEqual(inst.cache_element, expected_empty_cache)
     self.assertEqual(inst._table, {})
示例#4
0
 def test_from_config(self):
     # Configured cache with some picked bytes
     # Then convert to "string" (decode -> unicode) for python version used.
     expected_table = dict(a=1, b=2, c=3)
     expected_cache = DataMemoryElement(bytes=pickle.dumps(expected_table))
     expected_cache_json_str = \
         expected_cache.get_bytes().decode(BYTES_CONFIG_ENCODING)
     inst = MemoryDescriptorSet.from_config({
         'cache_element': {
             'type': 'DataMemoryElement',
             'DataMemoryElement': {
                 'bytes': expected_cache_json_str
             }
         }
     })
     self.assertEqual(inst.cache_element, expected_cache)
     self.assertEqual(inst._table, expected_table)
示例#5
0
 def test_default_config(self):
     # Default should be valid for constructing a new instance.
     c = MemoryDescriptorSet.get_default_config()
     self.assertEqual(MemoryDescriptorSet.from_config(c).get_config(), c)