Improved unflatten tests.

This commit is contained in:
Fabio Caccamo 2020-02-20 11:41:14 +01:00
parent ea3141b769
commit e3b0c115dc
1 changed files with 68 additions and 2 deletions

View File

@ -8,5 +8,71 @@ import unittest
class unflatten_test_case(unittest.TestCase):
def test_unflatten(self):
# TODO
pass
d = {
'a': 1,
'b_c': 2,
'd_e': 3,
}
u = _unflatten(d)
r = {
'a': 1,
'b': {
'c': 2,
},
'd': {
'e': 3,
},
}
self.assertEqual(u, r)
def test_unflatten_with_custom_separator(self):
d = {
'a': 1,
'b|c': 2,
'd|e': 3,
}
u = _unflatten(d, separator='#')
self.assertEqual(u, d)
u = _unflatten(d, separator='|')
r = {
'a': 1,
'b': {
'c': 2,
},
'd': {
'e': 3,
},
}
self.assertEqual(u, r)
def test_unflatten_with_nested_dict(self):
d = {
'a': 1,
'b_c': {
'u_v': 2,
},
'd_e': {
'x_y_z': 3,
},
}
u = _unflatten(d)
r = {
'a': 1,
'b': {
'c': {
'u': {
'v': 2,
},
},
},
'd': {
'e': {
'x': {
'y': {
'z': 3,
},
},
},
},
}
self.assertEqual(u, r)