python-benedict/tests/core/test_swap.py

47 lines
862 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from benedict.core import swap as _swap
import unittest
class swap_test_case(unittest.TestCase):
2022-02-13 10:35:43 +00:00
"""
This class describes a swap test case.
"""
def test_swap(self):
d = {
2022-02-13 10:35:43 +00:00
"a": 1,
"b": 2,
"c": 3,
}
2022-02-13 10:35:43 +00:00
_swap(d, "a", "b")
r = {
2022-02-13 10:35:43 +00:00
"a": 2,
"b": 1,
"c": 3,
}
self.assertEqual(d, r)
def test_swap_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
_swap(d, "a", "a")
r = {
2022-02-13 10:35:43 +00:00
"a": 1,
"b": 2,
}
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,
}
with self.assertRaises(KeyError):
2022-02-13 10:35:43 +00:00
_swap(d, "a", "d")