Exemplo n.º 1
0
    def test_from_config_null_cache_elem(self) -> None:
        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, {})
Exemplo n.º 2
0
 def test_from_config_null_cache_elem_type(self) -> None:
     # An empty cache should not trigger loading on construction.
     expected_empty_cache = DataMemoryElement()
     dme_key = 'smqtk_dataprovider.impls.data_element.memory.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, {})
Exemplo n.º 3
0
 def test_from_config(self) -> None:
     # 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)
     dme_key = 'smqtk_dataprovider.impls.data_element.memory.DataMemoryElement'
     inst = MemoryDescriptorSet.from_config({
         'cache_element': {
             'type': dme_key,
             dme_key: {
                 'bytes': expected_cache_json_str
             }
         }
     })
     self.assertEqual(inst.cache_element, expected_cache)
     self.assertEqual(inst._table, expected_table)
Exemplo n.º 4
0
 def test_default_config(self) -> None:
     # Default should be valid for constructing a new instance.
     c = MemoryDescriptorSet.get_default_config()
     self.assertEqual(MemoryDescriptorSet.from_config(c).get_config(), c)