Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 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))
Exemplo n.º 3
0
 def deleteDictionary(self, fileName):
     '''
     Delete a dictionary file from the system
     :param fileName
     '''
     newDataFile=dataFile(self.pid, fileName)
     newDataFile.deleteJSON()
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 def searchDict(self, dictFile, searchWord):
     searchTarget=dataFile(self.pid, dictFile )
     matchList=[]
     importDict: FictionDict=searchTarget.importJSON()
     matchList=importDict.searchDict(searchWord)
     return matchList
Exemplo n.º 9
0
 def get_dict_Str(self, srcFile):
     targetDictionary=dataFile(self.pid, srcFile)
     importDict: FictionDict=targetDictionary.importJSON()
     dictStr=importDict.__str__()
     return dictStr
Exemplo n.º 10
0
 def get_word_Str(self, srcFile, word):
     targetDictionary=dataFile(self.pid, srcFile)
     importDict: FictionDict=targetDictionary.importJSON()
     wordStr=importDict.wordToString(word)
     return wordStr
Exemplo n.º 11
0
 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())
Exemplo n.º 12
0
 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())
Exemplo n.º 13
0
 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())
Exemplo n.º 14
0
 def deleteWord(self, fileName, word):
     newDataFile=dataFile(self.pid, fileName)
     importDict: FictionDict=newDataFile.importJSON()
     importDict.deleteWord(word)
     newDataFile.exportOverwriteJSON(importDict.getSerializableData())
Exemplo n.º 15
0
 def createDictionary(self, dictName, fileName):
     newDict=FictionDict(dictName)
     newDataFile=dataFile(self.pid, fileName)
     newDataFile.exportJSON(newDict.getSerializableData())