Example #1
0
 def test_category_of_item(self):
     root = RootProjectTreeItem()
     category = CategoryProjectTreeItem("category", "category description")
     root.add_child(category)
     model = ProjectItemModel(self.toolbox, root)
     self.assertEqual(model.category_of_item("nonexistent item"), None)
     project_item = ProjectItem("item", "item description", 0.0, 0.0,
                                self.toolbox.project(), self.toolbox)
     item = LeafProjectTreeItem(project_item, self.toolbox)
     category.add_child(item)
     found_category = model.category_of_item("item")
     self.assertEqual(found_category.name, category.name)
Example #2
0
 def test_RootProjectTreeItem_parent_child_hierarchy(self):
     parent = RootProjectTreeItem()
     toolbox, child = self._category_item()
     parent.add_child(child)
     self.assertEqual(parent.child_count(), 1)
     self.assertEqual(parent.children()[0], child)
     self.assertEqual(child.parent(), parent)
     self.assertEqual(child.row(), 0)
     parent.remove_child(0)
     self.assertEqual(parent.child_count(), 0)
     self.assertFalse(parent.children())
     self.assertIsNone(child.parent())
     self._destroy_toolbox(toolbox)
Example #3
0
 def test_RootProjectTreeItem_parent_child_hierarchy(self):
     parent = RootProjectTreeItem()
     with TemporaryDirectory() as project_dir:
         toolbox, child = self._category_item(project_dir)
         parent.add_child(child)
         self.assertEqual(parent.child_count(), 1)
         self.assertEqual(parent.children()[0], child)
         self.assertEqual(child.parent(), parent)
         self.assertEqual(child.row(), 0)
         parent.remove_child(0)
         self.assertEqual(parent.child_count(), 0)
         self.assertFalse(parent.children())
         self.assertIsNone(child.parent())
         clean_up_toolbox(toolbox)
Example #4
0
 def test_empty_model(self):
     root = RootProjectTreeItem()
     model = ProjectItemModel(self.toolbox, root)
     self.assertEqual(model.rowCount(), 0)
     self.assertEqual(model.columnCount(), 1)
     self.assertEqual(model.n_items(), 0)
     self.assertFalse(model.items())
Example #5
0
 def test_insert_item_category_item(self):
     root = RootProjectTreeItem()
     model = ProjectItemModel(self.toolbox, root)
     category = CategoryProjectTreeItem("category", "category description")
     model.insert_item(category)
     self.assertEqual(model.rowCount(), 1)
     self.assertEqual(model.n_items(), 0)
     category_index = model.find_category("category")
     self.assertTrue(category_index.isValid())
     self.assertEqual(category_index.row(), 0)
     self.assertEqual(category_index.column(), 0)
     self.assertEqual(model.data(category_index, Qt.DisplayRole),
                      "category")
 def test_set_leaf_item_name(self):
     root = RootProjectTreeItem()
     model = ProjectItemModel(root)
     category = CategoryProjectTreeItem("category", "category description")
     model.insert_item(category)
     category_index = model.find_category("category")
     project_item = ProjectItem("item", "item description", 0.0, 0.0,
                                self.toolbox.project())
     leaf = LeafProjectTreeItem(project_item, self.toolbox)
     model.insert_item(leaf, category_index)
     leaf_index = model.find_item("item")
     model.set_leaf_item_name(leaf_index, "new view item name")
     leaf_item = model.get_item("new view item name")
     self.assertIsNotNone(leaf_item)
Example #7
0
 def test_insert_item_leaf_item(self):
     root = RootProjectTreeItem()
     model = ProjectItemModel(self.toolbox, root)
     category = CategoryProjectTreeItem("category", "category description")
     model.insert_item(category)
     category_index = model.find_category("category")
     mock_project_item = NonCallableMagicMock()
     mock_project_item.name = "project item"
     mock_project_item.description = "project item description"
     leaf = LeafProjectTreeItem(mock_project_item, self.toolbox)
     model.insert_item(leaf, category_index)
     self.assertEqual(model.rowCount(), 1)
     self.assertEqual(model.rowCount(category_index), 1)
     self.assertEqual(model.n_items(), 1)
     self.assertEqual(model.items("category"), [leaf])
Example #8
0
 def test_RootProjectTreeItem_initial_name_and_description(self):
     item = RootProjectTreeItem()
     self.assertEqual(item.name, "root")
     self.assertEqual(item.description, "The Root Project Tree Item.")