Esempio n. 1
0
    def test_remove_children(self):
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(-1, 1)  # should return False (it is not possible)
        self.assertFalse(s)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(2, 1)  # should return False (it is not possible)
        self.assertFalse(s)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(1, 2)  # should return False (it is not possible)
        self.assertFalse(s)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(0, 1)
        self.assertTrue(s)
        self.assertListEqual([self.item2], self.item3.childItems)

        s = self.item3.remove_children(0, 1)
        self.assertTrue(s)
        self.assertListEqual([], self.item3.childItems)

        s = self.item3.remove_children(0, 1)
        self.assertFalse(s)
        self.assertListEqual([], self.item3.childItems)

        # test remove multiple
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        s = self.item3.remove_children(0, 2)
        self.assertTrue(s)
        self.assertListEqual([], self.item3.childItems)
Esempio n. 2
0
    def test_count_marker_genes(self):
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = "dr3"

        self.assertEqual(3, self.item3.count_marker_genes())
        self.assertEqual(1, self.item1.count_marker_genes())
        self.assertEqual(1, self.item2.count_marker_genes())

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = None

        self.assertEqual(2, self.item3.count_marker_genes())
        self.assertEqual(1, self.item1.count_marker_genes())
        self.assertEqual(1, self.item2.count_marker_genes())

        self.item1.data_row = "dr1"
        self.item2.data_row = None
        self.item3.data_row = None

        self.assertEqual(1, self.item3.count_marker_genes())
        self.assertEqual(1, self.item1.count_marker_genes())
        self.assertEqual(0, self.item2.count_marker_genes())
Esempio n. 3
0
    def test_get_data_rows(self):
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = "dr3"

        self.assertListEqual(sorted(["dr1", "dr2", "dr3"]), sorted(self.item3.get_data_rows()))
        self.assertListEqual(["dr1"], self.item1.get_data_rows())
        self.assertListEqual(["dr2"], self.item2.get_data_rows())

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = None

        self.assertListEqual(sorted(["dr1", "dr2"]), sorted(self.item3.get_data_rows()))
        self.assertListEqual(["dr1"], self.item1.get_data_rows())
        self.assertListEqual(["dr2"], self.item2.get_data_rows())

        self.item1.data_row = "dr1"
        self.item2.data_row = None
        self.item3.data_row = None

        self.assertListEqual(["dr1"], self.item3.get_data_rows())
        self.assertListEqual(["dr1"], self.item1.get_data_rows())
        self.assertListEqual([], self.item2.get_data_rows())
Esempio n. 4
0
    def test_children_count(self):
        self.assertEqual(0, self.item3.children_count())

        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertEqual(2, self.item3.children_count())

        self.item3.remove_children(0, 1)
        self.assertEqual(1, self.item3.children_count())

        self.item3.remove_children(0, 1)
        self.assertEqual(0, self.item3.children_count())
Esempio n. 5
0
    def test_child_from_name_index(self):
        self.assertTupleEqual((None, None), self.item3.child_from_name_index("item 1"))
        TreeItem.change_parents([self.item1, self.item2], self.item3)

        self.assertTupleEqual((0, self.item1), self.item3.child_from_name_index("item 1"))
        self.assertTupleEqual((1, self.item2), self.item3.child_from_name_index("item 2"))

        self.item3.remove_children(0, 2)
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.assertTupleEqual((1, self.item1), self.item3.child_from_name_index("item 1"))
        self.assertTupleEqual((0, self.item2), self.item3.child_from_name_index("item 2"))
    def test_contains_text(self):
        # simulate RowItem with dictionary
        self.item1.data_row = {
            "Name": "item1",
            "Cell Type": "type1",
            "Function": "function1"
        }
        self.item2.data_row = {
            "Name": "item2",
            "Cell Type": "type2",
            "Function": "function2"
        }
        filter_columns = ["Name", "Cell Type", "Function"]
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.assertTrue(self.item1.contains_text("item1", filter_columns))
        self.assertFalse(self.item2.contains_text("item1", filter_columns))
        self.assertFalse(self.item3.contains_text("item1", filter_columns))

        self.assertTrue(self.item1.contains_text("type1", filter_columns))
        self.assertFalse(self.item2.contains_text("type1", filter_columns))
        self.assertFalse(self.item3.contains_text("type1", filter_columns))

        self.assertTrue(self.item1.contains_text("function1", filter_columns))
        self.assertFalse(self.item2.contains_text("function1", filter_columns))
        self.assertFalse(self.item3.contains_text("function1", filter_columns))

        self.assertFalse(self.item1.contains_text("item2", filter_columns))
        self.assertTrue(self.item2.contains_text("item2", filter_columns))
        self.assertFalse(self.item3.contains_text("item2", filter_columns))

        self.assertFalse(self.item1.contains_text("type2", filter_columns))
        self.assertTrue(self.item2.contains_text("type2", filter_columns))
        self.assertFalse(self.item3.contains_text("type2", filter_columns))

        self.assertFalse(self.item1.contains_text("function2", filter_columns))
        self.assertTrue(self.item2.contains_text("function2", filter_columns))
        self.assertFalse(self.item3.contains_text("function2", filter_columns))

        # test case sensitivity
        self.assertTrue(self.item1.contains_text("Item1", filter_columns))
        self.assertFalse(self.item2.contains_text("Item1", filter_columns))

        self.assertTrue(self.item1.contains_text("Type1", filter_columns))
        self.assertFalse(self.item2.contains_text("Type1", filter_columns))

        self.assertFalse(self.item1.contains_text("Item2", filter_columns))
        self.assertTrue(self.item2.contains_text("Item2", filter_columns))

        self.assertFalse(self.item1.contains_text("Type2", filter_columns))
        self.assertTrue(self.item2.contains_text("Type2", filter_columns))
Esempio n. 7
0
    def test_row(self):
        # when no parent it is assumed that the item is a root item - its row is 0
        self.assertEqual(0, self.item1.row())
        self.assertEqual(0, self.item2.row())
        self.assertEqual(0, self.item3.row())

        # add parent
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertEqual(0, self.item1.row())
        self.assertEqual(1, self.item2.row())
        self.assertEqual(0, self.item3.row())

        # different order
        self.item3.remove_children(0, 2)
        TreeItem.change_parents([self.item2, self.item1], self.item3)
        self.assertEqual(1, self.item1.row())
        self.assertEqual(0, self.item2.row())
        self.assertEqual(0, self.item3.row())
Esempio n. 8
0
 def change_parents(self):
     TreeItem.change_parents([self.item1, self.item2], self.item3)
     self.assertEqual(self.item1.parentItem, self.item3)
     self.assertIn(self.item1, self.item3.childItems)
     self.assertEqual(self.item2.parentItem, self.item3)
     self.assertIn(self.item2, self.item3.childItems)
Esempio n. 9
0
 def setUp(self) -> None:
     self.item1 = TreeItem("item 1", False, None, None)
     self.item2 = TreeItem("item 2", False, None, None)
     self.item3 = TreeItem("item 3", False, None, None)
Esempio n. 10
0
class TestTreeItem(unittest.TestCase):
    def setUp(self) -> None:
        self.item1 = TreeItem("item 1", False, None, None)
        self.item2 = TreeItem("item 2", False, None, None)
        self.item3 = TreeItem("item 3", False, None, None)

    def test_change_parent(self):
        self.item1.change_parent(self.item2)
        self.assertEqual(self.item1.parentItem, self.item2)
        self.assertIn(self.item1, self.item2.childItems)

    def test_change_parent_none(self):
        self.item1.change_parent(None)
        self.assertEqual(self.item1.parentItem, None)
        self.assertListEqual([], self.item2.childItems)

    def change_parents(self):
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertEqual(self.item1.parentItem, self.item3)
        self.assertIn(self.item1, self.item3.childItems)
        self.assertEqual(self.item2.parentItem, self.item3)
        self.assertIn(self.item2, self.item3.childItems)

    def test_append_child(self):
        self.item1.append_child(self.item3)
        self.assertIn(self.item3, self.item1.childItems)

    def test_remove_children(self):
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(-1, 1)  # should return False (it is not possible)
        self.assertFalse(s)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(2, 1)  # should return False (it is not possible)
        self.assertFalse(s)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(1, 2)  # should return False (it is not possible)
        self.assertFalse(s)
        self.assertListEqual([self.item1, self.item2], self.item3.childItems)

        s = self.item3.remove_children(0, 1)
        self.assertTrue(s)
        self.assertListEqual([self.item2], self.item3.childItems)

        s = self.item3.remove_children(0, 1)
        self.assertTrue(s)
        self.assertListEqual([], self.item3.childItems)

        s = self.item3.remove_children(0, 1)
        self.assertFalse(s)
        self.assertListEqual([], self.item3.childItems)

        # test remove multiple
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        s = self.item3.remove_children(0, 2)
        self.assertTrue(s)
        self.assertListEqual([], self.item3.childItems)

    def test_children_count(self):
        self.assertEqual(0, self.item3.children_count())

        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertEqual(2, self.item3.children_count())

        self.item3.remove_children(0, 1)
        self.assertEqual(1, self.item3.children_count())

        self.item3.remove_children(0, 1)
        self.assertEqual(0, self.item3.children_count())

    def test_row(self):
        # when no parent it is assumed that the item is a root item - its row is 0
        self.assertEqual(0, self.item1.row())
        self.assertEqual(0, self.item2.row())
        self.assertEqual(0, self.item3.row())

        # add parent
        TreeItem.change_parents([self.item1, self.item2], self.item3)
        self.assertEqual(0, self.item1.row())
        self.assertEqual(1, self.item2.row())
        self.assertEqual(0, self.item3.row())

        # different order
        self.item3.remove_children(0, 2)
        TreeItem.change_parents([self.item2, self.item1], self.item3)
        self.assertEqual(1, self.item1.row())
        self.assertEqual(0, self.item2.row())
        self.assertEqual(0, self.item3.row())

    def test_child_from_name_index(self):
        self.assertTupleEqual((None, None), self.item3.child_from_name_index("item 1"))
        TreeItem.change_parents([self.item1, self.item2], self.item3)

        self.assertTupleEqual((0, self.item1), self.item3.child_from_name_index("item 1"))
        self.assertTupleEqual((1, self.item2), self.item3.child_from_name_index("item 2"))

        self.item3.remove_children(0, 2)
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.assertTupleEqual((1, self.item1), self.item3.child_from_name_index("item 1"))
        self.assertTupleEqual((0, self.item2), self.item3.child_from_name_index("item 2"))

    def test_contains_text(self):
        # simulate RowItem with dictionary
        self.item1.data_row = {"Name": "item1", "Cell Type": "type1", "Function": "function1"}
        self.item2.data_row = {"Name": "item2", "Cell Type": "type2", "Function": "function2"}
        filter_columns = ["Name", "Cell Type", "Function"]
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.assertTrue(self.item1.contains_text("item1", filter_columns))
        self.assertFalse(self.item2.contains_text("item1", filter_columns))
        self.assertFalse(self.item3.contains_text("item1", filter_columns))

        self.assertTrue(self.item1.contains_text("type1", filter_columns))
        self.assertFalse(self.item2.contains_text("type1", filter_columns))
        self.assertFalse(self.item3.contains_text("type1", filter_columns))

        self.assertTrue(self.item1.contains_text("function1", filter_columns))
        self.assertFalse(self.item2.contains_text("function1", filter_columns))
        self.assertFalse(self.item3.contains_text("function1", filter_columns))

        self.assertFalse(self.item1.contains_text("item2", filter_columns))
        self.assertTrue(self.item2.contains_text("item2", filter_columns))
        self.assertFalse(self.item3.contains_text("item2", filter_columns))

        self.assertFalse(self.item1.contains_text("type2", filter_columns))
        self.assertTrue(self.item2.contains_text("type2", filter_columns))
        self.assertFalse(self.item3.contains_text("type2", filter_columns))

        self.assertFalse(self.item1.contains_text("function2", filter_columns))
        self.assertTrue(self.item2.contains_text("function2", filter_columns))
        self.assertFalse(self.item3.contains_text("function2", filter_columns))

        # test case sensitivity
        self.assertTrue(self.item1.contains_text("Item1", filter_columns))
        self.assertFalse(self.item2.contains_text("Item1", filter_columns))

        self.assertTrue(self.item1.contains_text("Type1", filter_columns))
        self.assertFalse(self.item2.contains_text("Type1", filter_columns))

        self.assertFalse(self.item1.contains_text("Item2", filter_columns))
        self.assertTrue(self.item2.contains_text("Item2", filter_columns))

        self.assertFalse(self.item1.contains_text("Type2", filter_columns))
        self.assertTrue(self.item2.contains_text("Type2", filter_columns))

    def test_get_data_rows(self):
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = "dr3"

        self.assertListEqual(sorted(["dr1", "dr2", "dr3"]), sorted(self.item3.get_data_rows()))
        self.assertListEqual(["dr1"], self.item1.get_data_rows())
        self.assertListEqual(["dr2"], self.item2.get_data_rows())

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = None

        self.assertListEqual(sorted(["dr1", "dr2"]), sorted(self.item3.get_data_rows()))
        self.assertListEqual(["dr1"], self.item1.get_data_rows())
        self.assertListEqual(["dr2"], self.item2.get_data_rows())

        self.item1.data_row = "dr1"
        self.item2.data_row = None
        self.item3.data_row = None

        self.assertListEqual(["dr1"], self.item3.get_data_rows())
        self.assertListEqual(["dr1"], self.item1.get_data_rows())
        self.assertListEqual([], self.item2.get_data_rows())

    def test_count_marker_genes(self):
        TreeItem.change_parents([self.item2, self.item1], self.item3)

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = "dr3"

        self.assertEqual(3, self.item3.count_marker_genes())
        self.assertEqual(1, self.item1.count_marker_genes())
        self.assertEqual(1, self.item2.count_marker_genes())

        self.item1.data_row = "dr1"
        self.item2.data_row = "dr2"
        self.item3.data_row = None

        self.assertEqual(2, self.item3.count_marker_genes())
        self.assertEqual(1, self.item1.count_marker_genes())
        self.assertEqual(1, self.item2.count_marker_genes())

        self.item1.data_row = "dr1"
        self.item2.data_row = None
        self.item3.data_row = None

        self.assertEqual(1, self.item3.count_marker_genes())
        self.assertEqual(1, self.item1.count_marker_genes())
        self.assertEqual(0, self.item2.count_marker_genes())