Skip to content

Commit 992459f

Browse files
committed
testsuite: add extra Python kvs tests
Problem: There is no coverage in the Python KVS tests for binary data, an empty "None" value, and illegal JSON strings. Add extra tests for coverage.
1 parent d94e4e2 commit 992459f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

t/python/t0005-kvs.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ def set_and_check_context(self, key, value, type):
3838

3939
kd2 = flux.kvs.KVSDir(self.f)
4040
nv = kd2[key]
41-
self.assertEqual(value, nv)
42-
self.assertTrue(isinstance(nv, type))
41+
if isinstance(value, bytes) and type is str:
42+
self.assertEqual(value.decode('utf-8'), nv)
43+
else:
44+
self.assertEqual(value, nv)
45+
if type is not None:
46+
self.assertTrue(isinstance(nv, type))
4347

4448
return kd2
4549

@@ -52,9 +56,15 @@ def test_set_float(self):
5256
def test_set_string(self):
5357
self.set_and_check_context("string", "stuff", str)
5458

59+
def test_set_none(self):
60+
self.set_and_check_context("none", None, None)
61+
5562
def test_set_unicode(self):
5663
self.set_and_check_context("unicode", "\u32db \u263a \u32e1", str)
5764

65+
def test_set_bytes(self):
66+
self.set_and_check_context("bytes", bytes.fromhex("deadbeef"), bytes)
67+
5868
def test_set_list(self):
5969
self.set_and_check_context("list", [1, 2, 3, 4], list)
6070

@@ -63,6 +73,9 @@ def test_set_dict(self):
6373
"dict", {"thing": "stuff", "other thing": "more stuff"}, dict
6474
)
6575

76+
def test_set_not_legal_json(self):
77+
self.set_and_check_context("badjson", b"{", str)
78+
6679
def test_exists_dir(self):
6780
with flux.kvs.get_dir(self.f) as kd:
6881
kd.mkdir("pytestdir")

0 commit comments

Comments
 (0)