def diffDictionaries(self, fileNameOne, fileNameTwo): newDataFileOne=dataFile(self.pid, fileNameOne) newDataFileTwo=dataFile(self.pid, fileNameTwo) importDictionaryOne: FictionDict=newDataFileOne.importJSON() importDictionaryTwo: FictionDict=newDataFileTwo.importJSON() diffDict=importDictionaryOne-importDictionaryTwo newDataFileOne.exportOverwriteJSON(diffDict.getSerializableData())
def test_BestCase(self): ''' *creation *export *exportOverwrite *import *delete ''' newDataFile = dataFile(os.getpid(), self.testFile) newFictDict = FictionDict('Test-Dictionary', self.testDict) newDataFile.exportJSON(newFictDict.getSerializableData()) self.assertTrue(os.path.exists(newDataFile.file)) #add a new word and export the dictionary to the same file newWord = { "Bread": ["A grainy food made from wheat and baked in an oven"] } newFictDict.addWord(newWord) newDataFile.exportOverwriteJSON(newFictDict.getSerializableData()) #assert modifed, then test import and assert that the word was added inDict = newDataFile.importJSON() #test imported dict has same data as newFictDict self.assertEqual(inDict.data, newFictDict.data) self.assertEqual(inDict.name, newFictDict.name) #if the insert and import was sucessful we should find bread in the imported dictionary self.assertEqual(["Bread"], inDict.searchDict("Bread")) newDataFile.deleteJSON() self.assertFalse(os.path.exists(newDataFile.file))
def deleteDictionary(self, fileName): ''' Delete a dictionary file from the system :param fileName ''' newDataFile=dataFile(self.pid, fileName) newDataFile.deleteJSON()
def searchDictRightDef(self, dictFile, searchWord): searchTarget=dataFile(self.pid) strList=[] importDict: FictionDict=searchTarget.importJSON() matchList=importDict.right_to_left_match_list(searchWord) for word in matchList: tempStr=importDict.wordToString(word) strList.append(tempStr) return strList
def searchDictWithDef(self, dictFile, searchWord): searchTarget=dataFile(self.pid, dictFile) strList=[] importDict: FictionDict=searchTarget.importJSON() matchList=importDict.searchDict(searchWord) tempStr="" for word in matchList: tempStr=importDict.wordToString(word) strList.append(tempStr) return strList
def test_WorstCase(self): ''' * no pid *no no path dir *test functions do not work without dictionary data *test export IOError *test export Overwrite file does not exist *test import IOError *test delete file does not exist ''' self.assertRaises(ValueError, dataFile, None, self.testFile) self.assertRaises(ValueError, dataFile, os.getpid(), '') newDataFile = dataFile(os.getpid(), self.testFile) self.assertRaises(ValueError, newDataFile.exportOverwriteJSON, None) ioErrorFile = os.path.join(self.currentdir, "fileNotAvailable.json") newDataFileTwo = dataFile(os.getpid(), ioErrorFile) newDataFileThree = dataFile(os.getpid(), self.currentdir) self.assertRaises(IOError, newDataFileThree.exportJSON, self.testDict) self.assertRaises(IOError, newDataFileTwo.exportOverwriteJSON, self.testDict) self.assertRaises(IOError, newDataFileTwo.importJSON) self.assertRaises(IOError, newDataFileTwo.deleteJSON)
def searchLeftDict(self, dictFile, searchWord): searchTarget=dataFile(self.pid, dictFile) matchList=[] importDict: FictionDict=searchTarget.importJSON() matchList=importDict.left_to_right_match_list(searchWord) return matchList
def searchDict(self, dictFile, searchWord): searchTarget=dataFile(self.pid, dictFile ) matchList=[] importDict: FictionDict=searchTarget.importJSON() matchList=importDict.searchDict(searchWord) return matchList
def get_dict_Str(self, srcFile): targetDictionary=dataFile(self.pid, srcFile) importDict: FictionDict=targetDictionary.importJSON() dictStr=importDict.__str__() return dictStr
def get_word_Str(self, srcFile, word): targetDictionary=dataFile(self.pid, srcFile) importDict: FictionDict=targetDictionary.importJSON() wordStr=importDict.wordToString(word) return wordStr
def copyDictionaries(self, srcFile, destFile): oldDataFile=dataFile(self.pid, srcFile) newDataFile=dataFile(self.pid, destFile) importDict: FictionDict=oldDataFile.importJSON() exportDict=importDict.copyDict() newDataFile.exportJSON(exportDict.getSerializableData())
def editDictionary(self, fileName, word, definition, synonm=0): newDataFile=dataFile(self.pid, fileName) importedDictionary: FictionDict=newDataFile.importJSON() importedDictionary.editWord(word,definition, synonm) newDataFile.exportOverwriteJSON(importedDictionary.getSerializableData())
def addWord(self, fileName, word, definition): newDataFile=dataFile(self.pid, fileName) importedDictionary: FictionDict=newDataFile.importJSON() newWord={word:definition} importedDictionary.addWord(newWord) newDataFile.exportOverwriteJSON(importedDictionary.getSerializableData())
def deleteWord(self, fileName, word): newDataFile=dataFile(self.pid, fileName) importDict: FictionDict=newDataFile.importJSON() importDict.deleteWord(word) newDataFile.exportOverwriteJSON(importDict.getSerializableData())
def createDictionary(self, dictName, fileName): newDict=FictionDict(dictName) newDataFile=dataFile(self.pid, fileName) newDataFile.exportJSON(newDict.getSerializableData())