def testCreateWord(self): """ Test creating a new word """ # Try some bad inputs word_dets = None self.assertRaises(cf.EtymExceptWord, cf.createWord, word_dets) word_dets = {} self.assertRaises(cf.EtymExceptWord, cf.createWord, word_dets) word_dets = {"lang": "English"} self.assertRaises(cf.EtymExceptWord, cf.createWord, word_dets) word_dets = {"lang": "English", "text": "banana", "morpheme": "bannana", "def": "A fruity thing"} self.assertRaises(cf.EtymExceptWord, cf.createWord, word_dets) # Now a good input, test the output word_dets = { "lang": "English", "text": ["banana", "pineapple"], "morpheme": "bannana", "def": "A fruity thing", "tag": "word", } new_word = cf.createWord(word_dets) new_word_details = cf.loadWordDetails(new_word) self.assertEqual(word_dets, new_word_details) # Try creating a word with a specified parent/children child_dets = {"lang": "Spanglish", "text": ["strawberry"], "morpheme": "strawberry", "def": "A fruity thing"} parent_dets = {"lang": "Fromesian", "text": ["raspberry"], "morpheme": "raspberry", "def": "A fruity thing"} word_dets = {"lang": "English", "text": ["banana"], "morpheme": "banana", "def": "A fruity thing"} new_child = cf.createWord(child_dets) new_parent = cf.createWord(parent_dets) new_word = cf.createWord(word_dets, word_parent=new_parent, word_children=new_child) self.assertEqual(cf.loadWordChildren(new_word)[0], new_child) self.assertEqual(cf.loadWordParents(new_word), new_parent)
def testChangeChildren(self): """ Tests modifying the children of a word """ chosen_word = self.getWord("far") real_children = cf.loadWordChildren(chosen_word) word_dets = {"lang": "English", "text": ["banana", "pineapple"], "morpheme": "bannana", "def": "A fruity thing"} test_child = cf.createWord(word_dets) cf.validateWord(test_child) # Test output with good input # (chosen_word only has one child) new_children = list(real_children) new_children.append(test_child) cf.editWordChildren(chosen_word, new_children) self.assertEqual(cf.countWordChildren(chosen_word), 2) # This removes children from chosen_word cf.editWordChildren(chosen_word, None) self.assertEqual(cf.countWordChildren(chosen_word), 0) self.assertEqual(cf.loadWordParents(real_children[0]), None) self.assertEqual(cf.loadWordParents(test_child), None) # Let's add a child back on cf.editWordChildren(chosen_word, test_child) self.assertEqual(cf.countWordChildren(chosen_word), 1) self.assertEqual(cf.loadWordParents(test_child), chosen_word)
def TreeItemAddChild(self, event): """ Add a child to the selected tree item """ # Create a word with some default values #wordDets = cf.loadWordDetails(self.current_node) word_dets = {'text': ['NEW WORD'], 'morpheme': 'NEW WORD', 'lang': 'UNKNOWN', 'def': 'Change me!'} new_word = cf.createWord(word_dets, word_parent=self.current_node) # Refresh the tree self.DisplayTree(self.search_root, self.search_words, select=new_word)
def testChangeParent(self): """ Tests modifying the parent of a word """ # This word has a parent, 'equinus' chosen_word = self.getWord("equine") # Make sure it can read the parent test_parent = cf.loadWordParents(chosen_word) parent_details = cf.loadWordDetails(test_parent) self.assertEqual(parent_details["text"], ["equinus"]) self.assertEqual(parent_details["lang"], "Latin") # Add a new word and set its parent word_dets = {"lang": "English", "text": ["banana", "pineapple"], "morpheme": "bannana", "def": "A fruity thing"} new_word = cf.createWord(word_dets) cf.editWordParent(new_word, test_parent) self.assertEqual(cf.countWordChildren(test_parent), 2) self.assertEqual(cf.countWordChildren(chosen_word), 0) cf.editWordParent(new_word, chosen_word) self.assertEqual(cf.countWordChildren(chosen_word), 1) # Add a new word and it to be parent to a word new_word = cf.createWord(word_dets) cf.editWordParent(chosen_word, new_word) self.assertEqual(new_word, cf.loadWordParents(chosen_word))
def OnNewTree(self, event): """ Create a new tree """ # Create a tree with some default values tree_dets = {'text': ['NEW ROOT'], 'morpheme': 'NEW ROOT', 'lang': 'UNKNOWN', 'def': 'Change me!', 'tag': 'tree'} word_dets = {'text': ['NEW WORD'], 'morpheme': 'NEW WORD', 'lang': 'UNKNOWN', 'def': 'Change me!'} new_word = cf.createWord(word_dets) new_tree = cf.addTree(self.words_tree, tree_dets, [new_word]) # Refresh the tree self.search_root = new_tree self.search_words = None self.DisplayTree(self.search_root, self.search_words)
def testAddTree(self): """ Test adding a tree """ # Create a test word to attach to the new tree word_dets = { "lang": "English", "text": ["banana", "pineapple"], "morpheme": "banana", "def": "A fruity thing", "tag": "word", } new_word = cf.createWord(word_dets) new_word_details = cf.loadWordDetails(new_word) self.assertEqual(word_dets, new_word_details) # Create the new tree db = self.getDB() tree_dets = {"lang": "PIE", "text": ["bane"], "morpheme": "bane", "def": "Some fruit", "tag": "tree"} cf.addTree(db, tree_dets, [new_word]) # Test that it was created num_trees, matched_words = cf.searchDB(db, "banana") search_word = matched_words[0][1] search_root = matched_words[0][0] search_root_dets = cf.loadWordDetails(search_root) self.assertEqual(search_word, new_word) self.assertEqual(search_root_dets["lang"], "PIE") self.assertEqual(search_root_dets["def"], "Some fruit") self.assertEqual(search_root_dets["morpheme"], "bane") self.assertEqual(search_root_dets["text"], ["bane"]) # Okay, now test some bad input # second arg not a list self.assertRaises(cf.EtymExceptWord, cf.addTree, db, tree_dets, new_word) # No word given self.assertRaises(cf.EtymExceptWord, cf.addTree, db, tree_dets, [None]) self.assertRaises(cf.EtymExceptWord, cf.addTree, db, tree_dets, []) # Invalid db self.assertRaises(cf.EtymExceptDB, cf.addTree, None, tree_dets, [new_word]) # Bad tree details tree_dets = {"lang": "PIE", "text": "bane", "morpheme": "bane", "tag": "tree"} self.assertRaises(cf.EtymExceptWord, cf.addTree, db, tree_dets, [new_word])