Exemple #1
0
 def test_nested_dict(self):
     self.assertEqual(flatten_dict({
         'foo': 42,
         'bar': {
             'foo': 43
         }
     }), {
         'foo': 42,
         'bar.foo': 43
     })
Exemple #2
0
 def test_conflict(self):
     self.assertEqual(flatten_dict({
         'bar.foo': 42,
         'bar': {
             'foo': 43
         }
     }), {
         'bar.foo': 42,
         'bar.foo.2': 43,
     })
Exemple #3
0
 def get_filename(cls, desc):
     """
     :return: figure output filename
     :rtype: string
     """
     desc = dict((k, v) for k, v in desc.items() if k != 'plotter')
     flatdict = flatten_dict(desc)
     sha256 = hashlib.sha256()
     sha256.update(repr(tuple(sorted(flatdict.items()))).encode('utf-8'))
     return sha256.hexdigest() + '.png'
Exemple #4
0
 def test_list(self):
     self.assertEqual(
         flatten_dict(
             {'foo': [
                 dict(bar=42),
                 dict(pika='plop'),
                 dict(bar=43),
             ]}), {
                 'foo.0.bar': 42,
                 'foo.1.pika': 'plop',
                 'foo.2.bar': 43,
             })
Exemple #5
0
 def test_empty(self):
     self.assertEqual(flatten_dict({}), {})