def test_unset2(self): """unset of array element""" self.assertEqual(tohil.eval("info exists x(d)", to=int), 1) self.assertEqual(tohil.exists("x(d)"), True) tohil.unset("x(c)", "x(d)") self.assertEqual(tohil.eval("info exists x(d)", to=int), 0) self.assertEqual(tohil.exists("x(d)"), False)
def test_tclvar1(self, x, y): """test 'tclvar' tcolbj var sync into tcl and see it from python and vice versa""" ns_name = "::tohil_test" xname = ns_name + "::varsync_x" yname = ns_name + "::varsync_y" tohil.unset(xname, yname) tx = tohil.tclvar(xname, default=x) ty = tohil.tclvar(yname, default=y) # compare the tclvar to tcl via a few different approaches assert tx == x assert tx == tohil.getvar(xname, to=int) assert tx == tohil.eval(f"set {xname}", to=int) assert tx == tohil.eval(f"return ${xname}", to=int) assert tx == tohil.expr(f"${xname}", to=int) # mutate tx tclvar and make sure the variable is changing # on the tcl side tx += ty assert tx == tohil.getvar(xname, to=int) assert tx == x + y assert tx == tohil.getvar(xname, to=int) assert tx == x + tohil.getvar(yname, to=int) tx -= ty assert tx == x assert tx == tohil.getvar(xname, to=int)
def test_tclvar3(self, x): """interoperate python lists back and forth with tcl lists""" ns_name = "::tohil_test" list_name = ns_name + "::varsync_list" tohil.unset(list_name) tl = tohil.tclvar(list_name, default=x) assert(str(tl) == tohil.getvar(list_name)) assert(list(tl) == tohil.getvar(list_name, to=list))
def test_tclvar6(self): """exercise tclobj extend method""" ns_name = "::tohil_test" list_name = ns_name + "::varsync_list" tohil.unset(list_name) tl = tohil.tclvar(list_name, default="1 2 3 4 5") tl.extend(tohil.tclobj("1 2 3")) self.assertEqual(len(tl), 8) self.assertEqual(tl[0], 1) self.assertEqual(tl[7], 3)
def test_tclvar5(self): """exercise tclobj append method""" ns_name = "::tohil_test" list_name = ns_name + "::varsync_list" tohil.unset(list_name) tl = tohil.tclvar(list_name, default="1 2 3 4 5") assert(tl[0] == 1) self.assertEqual(len(tl), 5) tl.append('6') self.assertEqual(len(tl), 6) self.assertEqual(tl[0], 1) self.assertEqual(tl[5], 6)
def test_unset3(self): # make sure unset doesn't do anything if the var or element doesn't exist tohil.unset("x(d)") with self.assertRaises(NameError): tohil.getvar("x(d)")
def test_unset1(self): """unset of scalar""" tohil.unset() tohil.unset("z") tohil.unset("z", "z", "zz") self.assertEqual(tohil.eval("info exists z", to=int), 0)