2020-02-03 17:25:54 +00:00
|
|
|
import unittest
|
|
|
|
|
2022-10-14 14:53:06 +00:00
|
|
|
from benedict.core import swap as _swap
|
|
|
|
|
2020-02-03 17:25:54 +00:00
|
|
|
|
|
|
|
class swap_test_case(unittest.TestCase):
|
2022-02-13 10:35:43 +00:00
|
|
|
"""
|
|
|
|
This class describes a swap test case.
|
|
|
|
"""
|
2020-02-03 17:25:54 +00:00
|
|
|
|
|
|
|
def test_swap(self):
|
|
|
|
d = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
|
|
|
"c": 3,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
2022-02-13 10:35:43 +00:00
|
|
|
_swap(d, "a", "b")
|
2020-02-03 17:25:54 +00:00
|
|
|
r = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 2,
|
|
|
|
"b": 1,
|
|
|
|
"c": 3,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
self.assertEqual(d, r)
|
|
|
|
|
|
|
|
def test_swap_with_same_key(self):
|
|
|
|
d = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
2022-02-13 10:35:43 +00:00
|
|
|
_swap(d, "a", "a")
|
2020-02-03 17:25:54 +00:00
|
|
|
r = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
self.assertEqual(d, r)
|
|
|
|
|
|
|
|
def test_swap_with_invalid_key(self):
|
|
|
|
d = {
|
2022-02-13 10:35:43 +00:00
|
|
|
"a": 1,
|
|
|
|
"b": 2,
|
|
|
|
"c": 3,
|
2020-02-03 17:25:54 +00:00
|
|
|
}
|
|
|
|
with self.assertRaises(KeyError):
|
2022-02-13 10:35:43 +00:00
|
|
|
_swap(d, "a", "d")
|