def test_create_tree_expr(self): ui_setup = UISetup(model=self.m) # Make a tree with constraints data_model = ComponentDataModel(parent=None, ui_setup=ui_setup, components=(Expression,), columns=["name", "value"]) # There should be one root item assert(len(data_model.rootItems)==1) assert(data_model.rootItems[0].data==self.m) # The children should be in the model construction order, # and the indexes are sorted children = data_model.rootItems[0].children assert(children[0].data == self.m.b1) assert(children[0].children[0].data == self.m.b1.e1) children[0].children[0].calculate() # Check the data display role The rows in the tree should be: # 0. Model # 0. b1, # 0. e1, value root_index = data_model.index(0,0) b1_index = data_model.index(0,0,parent=root_index) e1_index0 = data_model.index(0,0,parent=b1_index) e1_index1 = data_model.index(0,1,parent=b1_index) assert(data_model.data(e1_index0)=="b1.e1") assert(abs(data_model.data(e1_index1) - 3.0) < 0.0001)
def test_update_tree_expr(self): ui_data = UIData(model=self.m) # Make a tree with constraints data_model = ComponentDataModel(parent=None, ui_data=ui_data, components=(Expression, ), columns=["name", "value"]) self.m.newe = Expression(expr=self.m.x[0] + self.m.x[1]) data_model._update_tree() # There should be one root item assert (len(data_model.rootItems) == 1) assert (data_model.rootItems[0].data == self.m) # The children should be in the model construction order, # and the indexes are sorted children = data_model.rootItems[0].children assert (children[0].data == self.m.b1) assert (children[0].children[0].data == self.m.b1.e1) ui_data.calculate_expressions() # Check the data display role The rows in the tree should be: # 0. Model # 0. b1, # 0. e1, value root_index = data_model.index(0, 0) b1_index = data_model.index(0, 0, parent=root_index) e1_index0 = data_model.index(0, 0, parent=b1_index) e1_index1 = data_model.index(0, 1, parent=b1_index) assert (data_model.data(e1_index0) == "b1.e1") assert (abs(data_model.data(e1_index1) - 3.0) < 0.0001) # Check that in the update the new expression was added found = False for i in children: if id(i.data) == id(self.m.newe): found = True break assert (found)
def test_create_tree_con(self): ui_setup = UISetup(model=self.m) # Make a tree with constraints data_model = ComponentDataModel(parent=None, ui_setup=ui_setup, components=(Constraint,), columns=["name", "active"]) # There should be one root item assert(len(data_model.rootItems)==1) assert(data_model.rootItems[0].data==self.m) # The children should be in the model construction order, # and the indexes are sorted children = data_model.rootItems[0].children assert(children[0].data == self.m.b1) assert(children[1].data == self.m.c1) assert(children[2].data == self.m.c2) # Check the data display role The rows in the tree should be: # 0. Model # 0. c1, True # 1. c2, True # 2. b1, True root_index = data_model.index(0,0) assert(data_model.data(root_index)=="tm") idx = data_model.index(0,0,parent=root_index) assert(data_model.data(idx)=="b1") idx = data_model.index(0,1,parent=root_index) assert(data_model.data(idx)==True) idx = data_model.index(1,0,parent=root_index) assert(data_model.data(idx)=="c1") idx = data_model.index(2,0,parent=root_index) assert(data_model.data(idx)=="c2")
def test_create_tree_var(self): ui_setup = UISetup(model=self.m) # Defaults to variables and two columns name and value data_model = ComponentDataModel(parent=None, ui_setup=ui_setup) # There should be one root item assert(len(data_model.rootItems)==1) assert(data_model.rootItems[0].data==self.m) # The children should be in the model construction order, # and the indexes are sorted children = data_model.rootItems[0].children assert(children[0].data == self.m.z) assert(children[1].data == self.m.x) assert(children[2].data == self.m.b1) # Check the data display role The rows in the tree should be: # 0. Model # 0. z # 0. z[0], 2 # 1. z[1], 2 # 2. z[2], 2 # 1. x # 0. x[0], 2 # 1. x[1], 1 # 2. b1 root_index = data_model.index(0,0) assert(data_model.data(root_index)=="tm") zidx = data_model.index(0,0,parent=root_index) assert(data_model.data(zidx)=="z") xidx = data_model.index(1,0,parent=root_index) assert(data_model.data(xidx)=="x") b1idx = data_model.index(2,0,parent=root_index) assert(data_model.data(b1idx)=="b1") idx = data_model.index(0,0,parent=zidx) assert(data_model.data(idx)=="z[0]") idx = data_model.index(0,1,parent=zidx) assert(abs(data_model.data(idx) - 2.0) < 0.0001) idx = data_model.index(1,0,parent=zidx) assert(data_model.data(idx)=="z[1]") idx = data_model.index(1,1,parent=zidx) assert(abs(data_model.data(idx) - 2.0) < 0.0001)