Skip to content

Commit 9274b9c

Browse files
committed
testsuite: update python type check
Problem: In the set_and_check_context() helper function, the test checks that the returned type is not 'bytes'. This is a non-optimal check as it doesn't check for the type we are expecting. In addition, a future test for a 'bytes' type can't be done. Solution: Have set_and_check_context() take an expected type as a parameter. Ensure that the returned type is the type we are expecting.
1 parent 09730c4 commit 9274b9c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

t/python/t0005-kvs.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ def test_kvs_dir_open(self):
3131
with flux.kvs.get_dir(self.f) as d:
3232
self.assertIsNotNone(d)
3333

34-
def set_and_check_context(self, key, value):
34+
def set_and_check_context(self, key, value, type):
3535
kd = flux.kvs.KVSDir(self.f)
3636
kd[key] = value
3737
kd.commit()
3838
nv = kd[key]
3939
self.assertEqual(value, nv)
40-
self.assertFalse(isinstance(nv, bytes))
40+
self.assertTrue(isinstance(nv, type))
4141
return kd
4242

4343
def test_set_int(self):
44-
self.set_and_check_context("int", 10)
44+
self.set_and_check_context("int", 10, int)
4545

4646
def test_set_float(self):
47-
self.set_and_check_context("float", 10.5)
47+
self.set_and_check_context("float", 10.5, float)
4848

4949
def test_set_string(self):
50-
self.set_and_check_context("string", "stuff")
50+
self.set_and_check_context("string", "stuff", str)
5151

5252
def test_set_unicode(self):
53-
self.set_and_check_context("unicode", "\u32db \u263a \u32e1")
53+
self.set_and_check_context("unicode", "\u32db \u263a \u32e1", str)
5454

5555
def test_set_list(self):
56-
self.set_and_check_context("list", [1, 2, 3, 4])
56+
self.set_and_check_context("list", [1, 2, 3, 4], list)
5757

5858
def test_set_dict(self):
5959
self.set_and_check_context(
60-
"dict", {"thing": "stuff", "other thing": "more stuff"}
60+
"dict", {"thing": "stuff", "other thing": "more stuff"}, dict
6161
)
6262

6363
def test_exists_dir(self):
@@ -79,7 +79,7 @@ def test_commit_flags(self):
7979
self.assertTrue(flux.kvs.exists(self.f, "flagcheck"))
8080

8181
def test_remove(self):
82-
kd = self.set_and_check_context("todel", "things to delete")
82+
kd = self.set_and_check_context("todel", "things to delete", str)
8383
del kd["todel"]
8484
kd.commit()
8585
with self.assertRaises(KeyError):
@@ -96,7 +96,7 @@ def test_fill(self):
9696
self.assertEqual(kd["dir"]["other_thing"], "dirstuff")
9797

9898
def test_set_deep(self):
99-
self.set_and_check_context("a.b.c.e.f.j.k", 5)
99+
self.set_and_check_context("a.b.c.e.f.j.k", 5, int)
100100

101101
def test_bad_init(self):
102102
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)