Beispiel #1
0
    def testBasic(self):
        b = BlockInfo(None, "/Foo", False, "")

        b1 = BlockInfo(None, "/Foo/bar", False, "")
        b.addChildBlock(b1)
        self.assertEqual(b1.parent, b)
        self.assertIn(b1.name, b.children_list)
        self.assertIn(b1.name, b.children)

        b.types[b1.name] = b1
        b.star_node = b1
        out = b.dump()
        self.assertIn("/Foo/bar", out)
 def createTabs(self, params):
     b = BlockInfo(None, "/Foo")
     for p in params:
         b.addParameter(p)
     t = ParamsByGroup(b, params)
     t.resize(480, 480)
     t.addName("some name")
     t.addUserParam("user_param")
     t.needBlockList.connect(lambda paths: self.needBlockList(t, paths))
     t.updateWatchers()
     if params:
         self.assertEqual(self.block_list_requested, 1)
     t.show()
     return t
Beispiel #3
0
 def createTypes(self):
     b = BlockInfo(None, "Foo")
     b.addParameter(self.createParam("type"))
     b.addParameter(self.createParam("parent0"))
     b.addParameter(self.createParam("parent1"))
     b.addParameter(self.createParam("parent2"))
     for i in range(4):
         bt = BlockInfo(b, "type_%s" % i)
         b.addBlockType(bt)
         self.createParams(bt)
     return b
 def createTabs(self, params):
     b = BlockInfo(None, "/Foo")
     for p in params:
         b.addParameter(p)
     tmap = {"VariableName": ["/Variables"]}
     t = ParamsByGroup(b, params, tmap)
     t.resize(480, 480)
     t.addName("some name")
     t.addUserParam("user_param")
     t.needBlockList.connect(lambda paths: self.needBlockList(t, paths))
     t.updateWatchers()
     if params:
         self.assertEqual(self.block_list_requested, 1)
     t.show()
     return t
Beispiel #5
0
    def testBlockComments(self):
        b = BlockInfo(None, "/Foo", True, "")
        c = "some comments"
        e = BlockEditor(b, self.tree.app_info.type_to_block_map)
        self.checkWidget(e)
        self.assertEqual(b.comments, "")
        e.comment_edit.setComments(c)
        self.checkWidget(e, apply_enabled=True, reset_enabled=True, comments=c)
        # This should get updated after apply is pressed
        self.assertEqual(b.comments, "")
        e.applyChanges()
        self.assertEqual(b.comments, c)
        self.checkWidget(e, comments=c)

        e.resetChanges()
        self.checkWidget(e, comments=c)

        e.comment_edit.setComments("")
        self.checkWidget(e,
                         apply_enabled=True,
                         reset_enabled=True,
                         comments="")
        self.assertEqual(b.comments, c)
        e.resetChanges()
        self.checkWidget(e, comments=c)
        self.assertEqual(b.comments, c)
Beispiel #6
0
 def testEmpty(self):
     b = BlockInfo(None, "/Foo")
     t = ParamsByGroup(b, [], {})
     t.needBlockList.connect(lambda paths: self.needBlockList(t, paths))
     self.assertEqual(t.count(), 0)
     t.setWatchedBlockList(t.count(), [])
     t.save()
     t.reset()
 def createTable(self, params):
     b = BlockInfo(None, "/Foo")
     for p in params:
         b.addParameter(p)
     tmap = {"VariableName": ["/Variables", "/AuxVariables"]}
     t = ParamsTable(b, params, tmap)
     t.resize(480, 480)
     t.addName("some name")
     t.addName("some name")  # shouldn't be a problem
     t.addUserParam("user_param")
     t.needBlockList.connect(lambda paths: self.needBlockList(t, paths))
     t.changed.connect(self.onChanged)
     t.updateWatchers()
     if params:
         self.assertEqual(self.block_list_requested, 1)
     t.show()
     return t
Beispiel #8
0
    def testBasic(self):
        b = BlockInfo(None, "/Foo", False, "")

        b1 = BlockInfo(None, "/Foo/bar", False, "")
        b.addChildBlock(b1)
        self.assertEqual(b1.parent, b)
        self.assertIn(b1.name, b.children_list)
        self.assertIn(b1.name, b.children)

        b.types[b1.name] = b1
        b.star_node = b1
        out = b.dump()
        self.assertIn("/Foo/bar", out)
    def testUserParams(self):
        b = BlockInfo(None, "/Foo", True, "")
        e = BlockEditor(b, self.tree.app_info.type_to_block_map)
        self.checkWidget(e)
        self.assertEqual(len(b.parameters_list), 0)
        e.addUserParamPressed()
        self.checkWidget(e, apply_enabled=True, reset_enabled=True)
        self.assertEqual(len(b.parameters_list), 0)

        e.applyChanges()
        self.checkWidget(e)
        self.assertEqual(len(b.parameters_list), 1)

        e.addUserParamPressed()
        self.checkWidget(e, apply_enabled=True, reset_enabled=True)
        self.assertEqual(len(b.parameters_list), 1)

        e.resetChanges()
        self.checkWidget(e)
        self.assertEqual(len(b.parameters_list), 1)
 def testEmpty(self):
     b = BlockInfo(None, "/Foo")
     t = ParamsTable(b, [], {})
     t.needBlockList.connect(lambda paths: self.needBlockList(t, paths))
     self.assertEqual(t.rowCount(), 0)
     t.setWatchedBlockList("/Bar", [])
Beispiel #11
0
 def createTypes(self):
     b = BlockInfo(None, "Foo")
     b.addParameter(self.createParam("type"))
     b.addParameter(self.createParam("parent0"))
     b.addParameter(self.createParam("parent1"))
     b.addParameter(self.createParam("parent2"))
     for i in range(4):
         bt = BlockInfo(b, "type_%s" % i)
         b.addBlockType(bt)
         self.createParams(bt)
     return b
Beispiel #12
0
 def testEmpty(self):
     b = BlockInfo(None, "Foo")
     t = self.createWidget(b)
     self.assertEqual(t.combo.count(), 0)
     self.assertEqual(t.table_stack.count(), 0)
Beispiel #13
0
    def testChild(self):
        b = BlockInfo(None, "/Foo", False, "")
        b2 = BlockInfo(None, "/Foo/bar", False, "")
        b21 = BlockInfo(None, "/Foo/bar/child", False, "")
        b3 = BlockInfo(None, "/Foo/bar1", False, "")
        b2.addChildBlock(b21)
        b.addChildBlock(b2)
        b.addChildBlock(b3)
        self.assertEqual(b2.parent, b)
        self.assertEqual(b3.parent, b)
        self.assertIn(b2.name, b.children)
        self.assertIn(b2.name, b.children_list)
        self.assertEqual(b.children_list.index(b2.name), 0)
        self.assertEqual(b.children_list.index(b3.name), 1)
        b.moveChildBlock(b3.name, 0)
        self.assertEqual(b.children_list.index(b2.name), 1)
        self.assertEqual(b.children_list.index(b3.name), 0)

        b.renameChildBlock("bar", "foo")
        self.assertEqual(b2.path, "/Foo/foo")
        self.assertEqual(b2.children["child"].path, "/Foo/foo/child")

        b.renameChildBlock("foo", "bar1")
        self.assertEqual(b2.path, "/Foo/foo")

        b.renameChildBlock("foo1", "bar1")
        self.assertEqual(b2.path, "/Foo/foo")

        b2.removeChildBlock("foo")
        b2.removeChildBlock("child")
        self.assertEqual(len(b2.children_list), 0)
        self.assertEqual(len(b2.children.keys()), 0)
Beispiel #14
0
    def testUserParams(self):
        b = BlockInfo(None, "/Foo", False, "")
        p = ParameterInfo(None, "p")
        p.user_added = False
        b.addParameter(p)
        b.addUserParam("bar", "val")
        b.addUserParam("bar", "val")
        p = b.getParamInfo("bar")
        self.assertEqual(p.user_added, True)
        self.assertEqual(b.paramValue("bar"), "val")

        b.setParamValue("bar", "val1")
        self.assertEqual(b.paramValue("bar"), "val1")

        b.removeUserParam("bar1")
        self.assertEqual(b.paramValue("bar"), "val1")

        b.removeUserParam("p")
        self.assertEqual(b.paramValue("p"), "")

        b.removeUserParam("bar")
        self.assertEqual(b.paramValue("bar"), None)
        self.assertNotIn("bar", b.parameters_list)
        self.assertNotIn("bar", b.parameters)

        b.addUserParam("bar", "val")
        b.addUserParam("foo", "val1")
        self.assertEqual(len(b.parameters_list), 3)
        self.assertEqual(b.parameters_list.index("bar"), 1)
        self.assertEqual(b.parameters_list.index("foo"), 2)

        b.moveUserParam("foo", 0)
        self.assertEqual(b.parameters_list.index("bar"), 2)
        self.assertEqual(b.parameters_list.index("foo"), 0)

        b.renameUserParam("bar1", "bar2")
        b.renameUserParam("p", "bar2")
        self.assertEqual(b.paramValue("bar2"), None)
        b.renameUserParam("bar", "bar1")
        self.assertEqual(b.paramValue("bar"), None)
        self.assertEqual(b.paramValue("bar1"), "val")
Beispiel #15
0
 def testTypes(self):
     b = BlockInfo(None, "/Foo", False, "")
     self.assertEqual(b.paramValue("type"), None)
     b.setBlockType("t") # shouldn't do anything
     p = ParameterInfo(None, "type")
     b.addParameter(p)
     self.assertEqual(p.parent, b)
     self.assertEqual(b.paramValue("type"), "")
     b.setBlockType("t") # shouldn't do anything
     self.assertEqual(b.paramValue("type"), "t")
     b1 = BlockInfo(None, "/Foo/t", False, "")
     p = ParameterInfo(None, "p")
     b1.addParameter(p)
     b.types[b1.name] = b1
     self.assertEqual(b.paramValue("p"), "")
     b.setParamValue("p", "val")
     self.assertEqual(b.paramValue("p"), "val")
     b.setBlockType("t1")
     self.assertEqual(b.paramValue("p"), None)
Beispiel #16
0
    def testCopy(self):
        b = BlockInfo(None, "/Foo", False, "")
        b.addUserParam("p0", "val0")
        b.addUserParam("p1", "val1")
        b2 = BlockInfo(None, "/Foo/bar", False, "")
        b2.addUserParam("p2", "val2")
        b2.addUserParam("p3", "val3")
        b3 = BlockInfo(None, "/Foo/bar1", False, "")
        b3.addUserParam("p4", "val4")
        b3.addUserParam("p5", "val5")
        b.addChildBlock(b2)
        b.addChildBlock(b3)
        b.setStarInfo(BlockInfo(None, "Foo/star", False, ""))
        b.addBlockType(BlockInfo(None, "Foo/t", False, ""))
        b_copy = b.copy(None)
        self.assertNotEqual(b_copy, b)
        self.assertEqual(b_copy.name, b.name)
        self.assertEqual(b_copy.types.keys(), b.types.keys())
        self.assertNotEqual(b_copy.types, b.types)
        self.assertEqual(b_copy.children.keys(), b.children.keys())
        self.assertEqual(b_copy.children_list, b.children_list)
        self.assertEqual(b_copy.parameters_list, b.parameters_list)
        self.assertEqual(b_copy.parameters.keys(), b.parameters.keys())

        o = b.dump()
        o1 = b_copy.dump()
        self.assertEqual(o, o1)
Beispiel #17
0
    def testCopy(self):
        b = BlockInfo(None, "/Foo", False, "")
        b.addUserParam("p0", "val0")
        b.addUserParam("p1", "val1")
        b2 = BlockInfo(None, "/Foo/bar", False, "")
        b2.addUserParam("p2", "val2")
        b2.addUserParam("p3", "val3")
        b3 = BlockInfo(None, "/Foo/bar1", False, "")
        b3.addUserParam("p4", "val4")
        b3.addUserParam("p5", "val5")
        b.addChildBlock(b2)
        b.addChildBlock(b3)
        b.setStarInfo(BlockInfo(None, "Foo/star", False, ""))
        b.addBlockType(BlockInfo(None, "Foo/t", False, ""))
        b_copy = b.copy(None)
        self.assertNotEqual(b_copy, b)
        self.assertEqual(b_copy.name, b.name)
        self.assertEqual(b_copy.types.keys(), b.types.keys())
        self.assertNotEqual(b_copy.types, b.types)
        self.assertEqual(b_copy.children.keys(), b.children.keys())
        self.assertEqual(b_copy.children_list, b.children_list)
        self.assertEqual(b_copy.parameters_list, b.parameters_list)
        self.assertEqual(b_copy.parameters.keys(), b.parameters.keys())

        o = b.dump()
        o1 = b_copy.dump()
        self.assertEqual(o, o1)
Beispiel #18
0
 def testTypes(self):
     b = BlockInfo(None, "/Foo", False, "")
     self.assertEqual(b.paramValue("type"), None)
     b.setBlockType("t") # shouldn't do anything
     p = ParameterInfo(None, "type")
     b.addParameter(p)
     self.assertEqual(p.parent, b)
     self.assertEqual(b.paramValue("type"), "")
     b.setBlockType("t") # shouldn't do anything
     self.assertEqual(b.paramValue("type"), "t")
     b1 = BlockInfo(None, "/Foo/t", False, "")
     p = ParameterInfo(None, "p")
     b1.addParameter(p)
     b.types[b1.name] = b1
     self.assertEqual(b.paramValue("p"), "")
     b.setParamValue("p", "val")
     self.assertEqual(b.paramValue("p"), "val")
     b.setBlockType("t1")
     self.assertEqual(b.paramValue("p"), None)
Beispiel #19
0
    def testUserParams(self):
        b = BlockInfo(None, "/Foo", False, "")
        p = ParameterInfo(None, "p")
        p.user_added = False
        b.addParameter(p)
        b.addUserParam("bar", "val")
        b.addUserParam("bar", "val")
        p = b.getParamInfo("bar")
        self.assertEqual(p.user_added, True)
        self.assertEqual(b.paramValue("bar"), "val")

        b.setParamValue("bar", "val1")
        self.assertEqual(b.paramValue("bar"), "val1")

        b.removeUserParam("bar1")
        self.assertEqual(b.paramValue("bar"), "val1")

        b.removeUserParam("p")
        self.assertEqual(b.paramValue("p"), "")

        b.removeUserParam("bar")
        self.assertEqual(b.paramValue("bar"), None)
        self.assertNotIn("bar", b.parameters_list)
        self.assertNotIn("bar", b.parameters)

        b.addUserParam("bar", "val")
        b.addUserParam("foo", "val1")
        self.assertEqual(len(b.parameters_list), 3)
        self.assertEqual(b.parameters_list.index("bar"), 1)
        self.assertEqual(b.parameters_list.index("foo"), 2)

        b.moveUserParam("foo", 0)
        self.assertEqual(b.parameters_list.index("bar"), 2)
        self.assertEqual(b.parameters_list.index("foo"), 0)

        b.renameUserParam("bar1", "bar2")
        b.renameUserParam("p", "bar2")
        self.assertEqual(b.paramValue("bar2"), None)
        b.renameUserParam("bar", "bar1")
        self.assertEqual(b.paramValue("bar"), None)
        self.assertEqual(b.paramValue("bar1"), "val")
Beispiel #20
0
    def testChild(self):
        b = BlockInfo(None, "/Foo", False, "")
        b2 = BlockInfo(None, "/Foo/bar", False, "")
        b21 = BlockInfo(None, "/Foo/bar/child", False, "")
        b3 = BlockInfo(None, "/Foo/bar1", False, "")
        b2.addChildBlock(b21)
        b.addChildBlock(b2)
        b.addChildBlock(b3)
        self.assertEqual(b2.parent, b)
        self.assertEqual(b3.parent, b)
        self.assertIn(b2.name, b.children)
        self.assertIn(b2.name, b.children_list)
        self.assertEqual(b.children_list.index(b2.name), 0)
        self.assertEqual(b.children_list.index(b3.name), 1)
        b.moveChildBlock(b3.name, 0)
        self.assertEqual(b.children_list.index(b2.name), 1)
        self.assertEqual(b.children_list.index(b3.name), 0)

        b.renameChildBlock("bar", "foo")
        self.assertEqual(b2.path, "/Foo/foo")
        self.assertEqual(b2.children["child"].path, "/Foo/foo/child")

        b.renameChildBlock("foo", "bar1")
        self.assertEqual(b2.path, "/Foo/foo")

        b.renameChildBlock("foo1", "bar1")
        self.assertEqual(b2.path, "/Foo/foo")

        b2.removeChildBlock("foo")
        b2.removeChildBlock("child")
        self.assertEqual(len(b2.children_list), 0)
        self.assertEqual(len(b2.children.keys()), 0)