python-benedict/tests/core/test_rename.py

63 lines
1.2 KiB
Python
Raw Normal View History

import unittest
from benedict.core import rename as _rename
class rename_test_case(unittest.TestCase):
2022-02-13 10:35:43 +00:00
"""
This class describes a rename test case.
"""
def test_rename(self):
d = {
2022-02-13 10:35:43 +00:00
"a": {
"x": 1,
"y": 1,
},
2022-02-13 10:35:43 +00:00
"b": {
"x": 2,
"y": 2,
},
2022-02-13 10:35:43 +00:00
"c": {
"x": 3,
"y": 3,
},
}
2022-02-13 10:35:43 +00:00
_rename(d, "a", "d")
r = {
2022-02-13 10:35:43 +00:00
"b": {
"x": 2,
"y": 2,
},
2022-02-13 10:35:43 +00:00
"c": {
"x": 3,
"y": 3,
},
2022-02-13 10:35:43 +00:00
"d": {
"x": 1,
"y": 1,
},
}
self.assertEqual(d, r)
def test_rename_with_same_key(self):
d = {
2022-02-13 10:35:43 +00:00
"a": 1,
"b": 2,
}
2022-02-13 10:35:43 +00:00
_rename(d, "a", "a")
r = {
2022-02-13 10:35:43 +00:00
"a": 1,
"b": 2,
}
self.assertEqual(d, r)
def test_rename_to_existing_name(self):
d = {
2022-02-13 10:35:43 +00:00
"a": 1,
"b": 2,
"c": 3,
}
with self.assertRaises(KeyError):
2022-02-13 10:35:43 +00:00
_rename(d, "a", "c")