コード例 #1
0
ファイル: test_etym.py プロジェクト: richli/etymdendron
    def testDelWord(self):
        """ Test deleting a word """
        # This parent I've chosen has only one child
        db = self.getDB()
        num_trees, matched_words = cf.searchDB(db, "varch")
        test_parent = matched_words[0][1]
        num_trees, matched_words = cf.searchDB(db, "ferkel")
        test_word = matched_words[0][1]

        #        # Test deleting a word that's not in the tree?
        #        word_dets = {'lang': 'English', 'text': ['banana', 'pineapple'],
        #                'morpheme': 'bannana', 'def': 'A fruity thing'}
        #        orphan_word = cf.createWord(word_dets)
        #        self.assertRaises(cf.EtymExceptWord, cf.deleteWord, orphan_word)

        # Test deleting a word
        cf.deleteWord(test_word)
        self.assertEqual(cf.loadWordChildren(test_parent), [])
        num_trees, matched_words = cf.searchDB(db, "ferkel")
        self.assertEqual(num_trees, 0)

        # Reload the db, delete the parent and ensure the child moves up
        db = self.getDB()
        num_trees, matched_words = cf.searchDB(db, "varch")
        test_parent = matched_words[0][1]
        num_trees, matched_words = cf.searchDB(db, "ferkel")
        test_word = matched_words[0][1]
        test_grandparent = cf.loadWordParents(test_parent)
        cf.deleteWord(test_parent)
        self.assertEqual(cf.loadWordParents(test_word), test_grandparent)
コード例 #2
0
ファイル: gui_funcs.py プロジェクト: richli/etymdendron
 def TreeItemDelete(self, event):
     """ Delete the selected tree item """
     # Find what type of node it is (word or tree root)
     node_type = cf.checkNode(self.current_node)
     # Delete the word or tree
     if node_type == 'word':
         cf.deleteWord(self.current_node)
     elif node_type == 'tree':
         cf.deleteTree(self.current_node)
         self.search_root = self.search_words = None
     # Refresh the tree
     self.DisplayTree(self.search_root, self.search_words)