예제 #1
0
    def test_tclobj7(self):
        """exercise tohil.tclobj number type (nb_*) methods"""
        x = tohil.expr("5", to=tohil.tclobj)

        self.assertEqual(int(x), 5)
        self.assertEqual(float(x), 5.0)
        self.assertEqual(bool(x), True)
예제 #2
0
    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)
예제 #3
0
    def test_tclobj7(self):
        """exercise tohil.tclobj as_tuple()"""
        x = tohil.expr("5", to=tohil.tclobj)

        self.assertEqual(int(x), 5)
        self.assertEqual(float(x), 5.0)
        self.assertEqual(bool(x), True)
예제 #4
0
    def test_tclvar2(self, x, y):
        """test tclvar tcobj shove stuff into tcl and see it from python and vice versa"""
        ns_name = "::tohil_test"
        xname = ns_name + "::varsync_x"
        yname = ns_name + "::varsync_y"

        tx = tohil.tclvar(xname)
        ty = tohil.tclvar(yname)

        tohil.eval(f"set {xname} {x}")
        tohil.eval(f"set {yname} {y}")

        assert tx == tx
        assert tx == x
        assert ty == ty

        tohil.incr(xname)
        assert tx == x + 1
        assert tx == tohil.expr(f"${xname}")
        tohil.eval(f"incr {xname} -1")
        assert tx == x