Skip to content

Commit fa88026

Browse files
bdracoijl
authored andcommitted
Add test coverage for dict key pop and replace
1 parent e8f4378 commit fa88026

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

test/test_dict.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
2+
3+
import unittest
4+
5+
import orjson
6+
7+
8+
class DictTests(unittest.TestCase):
9+
def test_dict_pop_replace_first(self):
10+
"""Test pop and replace a first key in a dict with other keys."""
11+
data = {"id": "any", "other": "any"}
12+
data.pop("id")
13+
data["id"] = "new"
14+
self.assertEqual(orjson.dumps(data), b'{"other":"any","id":"new"}')
15+
16+
def test_dict_pop_replace_last(self):
17+
"""Test pop and replace a last key in a dict with other keys."""
18+
data = {"other": "any", "id": "any"}
19+
data.pop("id")
20+
data["id"] = "new"
21+
self.assertEqual(orjson.dumps(data), b'{"other":"any","id":"new"}')
22+
23+
def test_dict_pop(self):
24+
"""Test pop and replace a key in a dict with no other keys."""
25+
data = {"id": "any"}
26+
data.pop("id")
27+
data["id"] = "new"
28+
self.assertEqual(orjson.dumps(data), b'{"id":"new"}')

0 commit comments

Comments
 (0)