Пример #1
0
    def test_from_config(self):
        inst = MemoryDescriptorIndex.from_config({'file_cache': None})
        ntools.assert_is_none(inst.file_cache)

        fp = '/doesnt/exist/yet'
        inst = MemoryDescriptorIndex.from_config({'file_cache': fp})
        ntools.assert_equal(inst.file_cache, fp)
Пример #2
0
    def test_from_config(self):
        inst = MemoryDescriptorIndex.from_config({'file_cache': None})
        ntools.assert_is_none(inst.file_cache)

        fp = '/doesnt/exist/yet'
        inst = MemoryDescriptorIndex.from_config({'file_cache': fp})
        ntools.assert_equal(inst.file_cache, fp)
Пример #3
0
    def test_from_config_null_cache_elem(self):
        inst = MemoryDescriptorIndex.from_config({'cache_element': None})
        ntools.assert_is_none(inst.cache_element)
        ntools.assert_equal(inst._table, {})

        inst = MemoryDescriptorIndex.from_config(
            {'cache_element': {
                'type': None
            }})
        ntools.assert_is_none(inst.cache_element)
        ntools.assert_equal(inst._table, {})
Пример #4
0
    def test_from_config_null_cache_elem(self):
        inst = MemoryDescriptorIndex.from_config({'cache_element': None})
        self.assertIsNone(inst.cache_element)
        self.assertEqual(inst._table, {})

        inst = MemoryDescriptorIndex.from_config(
            {'cache_element': {
                'type': None
            }})
        self.assertIsNone(inst.cache_element)
        self.assertEqual(inst._table, {})
Пример #5
0
    def test_from_config_null_cache_elem(self):
        inst = MemoryDescriptorIndex.from_config({'cache_element': None})
        self.assertIsNone(inst.cache_element)
        self.assertEqual(inst._table, {})

        inst = MemoryDescriptorIndex.from_config({
            'cache_element': {
                'type': None
            }
        })
        self.assertIsNone(inst.cache_element)
        self.assertEqual(inst._table, {})
Пример #6
0
 def test_from_config_null_cache_elem_type(self):
     # An empty cache should not trigger loading on construction.
     expected_empty_cache = DataMemoryElement()
     inst = MemoryDescriptorIndex.from_config({
         'cache_element': {
             'type': 'DataMemoryElement',
             'DataMemoryElement': {'bytes': ''}
         }
     })
     self.assertEqual(inst.cache_element, expected_empty_cache)
     self.assertEqual(inst._table, {})
Пример #7
0
 def test_from_config(self):
     # Configured cache with some picked bytes
     expected_table = dict(a=1, b=2, c=3)
     expected_cache = DataMemoryElement(bytes=pickle.dumps(expected_table))
     inst = MemoryDescriptorIndex.from_config({
         'cache_element': {
             'type': 'DataMemoryElement',
             'DataMemoryElement': {'bytes': expected_cache.get_bytes()}
         }
     })
     self.assertEqual(inst.cache_element, expected_cache)
     self.assertEqual(inst._table, expected_table)
Пример #8
0
 def test_from_config_null_cache_elem_type(self):
     # An empty cache should not trigger loading on construction.
     expected_empty_cache = DataMemoryElement()
     inst = MemoryDescriptorIndex.from_config({
         'cache_element': {
             'type': 'DataMemoryElement',
             'DataMemoryElement': {
                 'bytes': ''
             }
         }
     })
     ntools.assert_equal(inst.cache_element, expected_empty_cache)
     ntools.assert_equal(inst._table, {})
Пример #9
0
 def test_from_config(self):
     # Configured cache with some picked bytes
     expected_table = dict(a=1, b=2, c=3)
     expected_cache = DataMemoryElement(bytes=pickle.dumps(expected_table))
     inst = MemoryDescriptorIndex.from_config({
         'cache_element': {
             'type': 'DataMemoryElement',
             'DataMemoryElement': {
                 'bytes': expected_cache.get_bytes()
             }
         }
     })
     ntools.assert_equal(inst.cache_element, expected_cache)
     ntools.assert_equal(inst._table, expected_table)
Пример #10
0
 def test_from_config(self):
     # Configured cache with some picked bytes
     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 = MemoryDescriptorIndex.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)
Пример #11
0
 def test_default_config(self):
     # Default should be valid for constructing a new instance.
     c = MemoryDescriptorIndex.get_default_config()
     ntools.assert_equal(
         MemoryDescriptorIndex.from_config(c).get_config(), c)
Пример #12
0
 def test_default_config(self):
     # Default should be valid for constructing a new instance.
     c = MemoryDescriptorIndex.get_default_config()
     self.assertEqual(MemoryDescriptorIndex.from_config(c).get_config(), c)