def test100_040_ShouldConstructFixWithExistingFile(self): theFix = F.Fix(self.RANDOM_LOG_FILE) theFix = F.Fix(self.RANDOM_LOG_FILE) try: theLogFile = open(self.RANDOM_LOG_FILE, 'r') numberOfExpectedEntries = 2 for _ in range(numberOfExpectedEntries): entry = theLogFile.readline() self.assertNotEquals(-1, entry.find(self.logStartString), "Minor: first line of log is incorrect") except IOError: self.fail() self.assertIsInstance(theFix, F.Fix, "Major: log file failed to create") self.deleteNamedLogFlag = True
def test300_040_ShouldLogMultipleSightingsInTimeOrder(self): testFile = "CA02_300_ValidMultipleStarSighting.xml" targetStringList = [ ["Sirius", "2016-03-01", "00:05:05"], ["Canopus", "2016-03-02", "23:40:01"] ] theFix = F.Fix(self.RANDOM_LOG_FILE) theFix.setSightingFile(testFile) theFix.getSightings() theLogFile = open(self.RANDOM_LOG_FILE, "r") logFileContents = theLogFile.readlines() theLogFile.close() # find entry with first star entryIndex = self.indexInList(targetStringList[0][0], logFileContents) self.assertLess(-1, entryIndex, "Major: failure to find " + targetStringList[0][0] + " in log") for targetString in targetStringList: if not (targetString[0] in logFileContents[entryIndex]): self.fail("failure to find {} in log".format(targetString[0])) entryIndex += 1 self.deleteNamedLogFlag = True
def test200_960_SholdRaiseExceptionOnMissingFile(self): expectedDiag = self.className + "setSightingFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile(self.RANDOM_LOG_FILE+".xml") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for missing sighting file")
def test200_930_ShouldRaiseExceptionOnNonXmlFile1(self): expectedDiag = self.className + "setSightingFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile("sighting.") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for non.xml sighting file extension")
def test200_940_ShouldRaiseExceptionOnNonXmlFile2(self): expectedDiag = self.className + "setSightingFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile("xml") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to delineate between sighting file name and extension")
def test200_920_ShouldRaiseExceptionOnFileLengthError(self): expectedDiag = self.className + "setSightingFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile(".xml") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for .GE. 1 sighting file name")
def test200_910_ShouldRaiseExceptionOnNonStringFileName(self): expectedDiag = self.className + "setSightingFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile(42) self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for non-string sighting file name")
def test300_910_ShouldRaiseExceptionOnNotSettingSightingsFile(self): expectedDiag = self.className + "getSightings:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.getSightings() self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Major: failure to set sighting file before getSightings()")
def test100_025_ShouldConstructWithKeywordParm(self): try: theFix = F.Fix(logFile=self.RANDOM_LOG_FILE) self.assertTrue(True) except Exception as e: self.fail("Major: " + str(e)) self.deleteNamedLogFlag = True
def test300_920_ShouldRaiseExceptionOnMissingMandatoryTag(self): expectedDiag = self.className + "getSightings:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile("CA02_300_InvalidWithMissingMandatoryTags.xml") theFix.getSightings() self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Major: failure to check for missing mandatory tag")
def test300_995_ShouldRaiseExceptionOnInvalidHorizon(self): expectedDiag = self.className + "getSightings:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile("CA02_300_InvalidHorizon.xml") theFix.getSightings() self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for invalid horizon" )
def test300_010_ShouldIgnoreMixedIndentation(self): testFile = "CA02_300_GenericValidStarSightingFile.xml" expectedResult = ("0d0.0", "0d0.0") theFix = F.Fix() theFix.setSightingFile(testFile) result = theFix.getSightings() self.assertTupleEqual(expectedResult, result, "Minor: incorrect return value from getSightings")
def test200_010_ShouldConstructWithKeywordParm(self): 'Minor: ' theFix = F.Fix(logFile=self.RANDOM_LOG_FILE) try: result = theFix.setSightingFile("CA02_200_ValidStarSightingFile.xml") self.assertEquals(result, "CA02_200_ValidStarSightingFile.xml") except: self.fail("Minor: incorrect keyword specified in setSighting parm") self.deleteNamedLogFlag = True
def test200_020_ShouldSetValidSightingFile(self): theFix = F.Fix() result = theFix.setSightingFile("CA02_200_ValidStarSightingFile.xml") self.assertEquals(result,"CA02_200_ValidStarSightingFile.xml") theLogFile = open(self.DEFAULT_LOG_FILE, "r") logFileContents = theLogFile.readlines() self.assertNotEquals(-1, logFileContents[-1].find(self.logSightingString), "Minor: first setSighting logged entry is incorrect") theLogFile.close()
def test300_020_ShouldIgnoreMixedIndentation(self): testFile = "CA02_300_ValidWithMixedIndentation.xml" theFix = F.Fix() theFix.setSightingFile(testFile) try: theFix.getSightings() self.assertTrue(True) except: self.fail("Major: getSightings failed on valid file with mixed indentation")
def test100_020_ShouldConstructFixWithDefaultFile(self): theFix = F.Fix() try: theLogFile = open(self.DEFAULT_LOG_FILE, 'r') entry = theLogFile.readline() self.assertNotEquals(-1, entry.find("Start of log"), "Minor: first line of log is incorrect") except IOError: self.fail() self.assertIsInstance(theFix, F.Fix, "Major: log file failed to create")
def test100_030_ShouldConstructFixWithNamedFile(self): theFix = F.Fix(self.RANDOM_LOG_FILE) try: theLogFile = open(self.RANDOM_LOG_FILE, 'r') entry = theLogFile.readline() del theLogFile self.assertNotEquals(-1, entry.find(self.logStartString), "Minor: first line of log is incorrect") except IOError: self.fail() self.assertIsInstance(theFix, F.Fix, "Major: log file failed to create") self.deleteNamedLogFlag = True
def test300_090_ShouldLogStarWithDefaultSightingValues(self): testFile = "CA02_300_ValidOneStarWithDefaultValues.xml" targetStringList = ["Hadar", "2016-03-01", "23:40:01", "29d59.9"] theFix = F.Fix(self.RANDOM_LOG_FILE) theFix.setSightingFile(testFile) theFix.getSightings() theLogFile = open(self.RANDOM_LOG_FILE, "r") logFileContents = theLogFile.readlines() theLogFile.close() sightingCount = 0 for logEntryNumber in range(0, len(logFileContents)): if(logFileContents[logEntryNumber].find(targetStringList[0]) > -1): sightingCount += 1 for target in targetStringList: self.assertNotEquals(-1, logFileContents[logEntryNumber].find(target), "Major: Log entry is not correct for getSightings") self.assertEquals(1, sightingCount) self.deleteNamedLogFlag = True
def test300_060_ShouldHandleNoSightings(self): testFile = "CA02_300_ValidWithNoSightings.xml" targetString1 = "End of sighting file" targetString2 = "Start of sighting file" theFix = F.Fix(self.RANDOM_LOG_FILE) theFix.setSightingFile(testFile) theFix.getSightings() theLogFile = open(self.RANDOM_LOG_FILE, "r") logFileContents = theLogFile.readlines() theLogFile.close() endOfSightingFileIndex = self.indexInList(targetString1, logFileContents) self.assertLess(-1,endOfSightingFileIndex, "Major: log file does not contain 'end of sighting file' entry") self.assertLess(1, endOfSightingFileIndex, "Major: log file does not contain sufficient entries") self.assertTrue((targetString2 in logFileContents[endOfSightingFileIndex - 1])) self.deleteNamedLogFlag = True
def test300_070_ShouldIgnoreExtraneousTags(self): testFile = "CA02_300_ValidWithExtraneousTags.xml" targetStringList = [ ["Sirius", "2016-03-01", "00:05:05"], ] theFix = F.Fix(self.RANDOM_LOG_FILE) theFix.setSightingFile(testFile) theFix.getSightings() theLogFile = open(self.RANDOM_LOG_FILE, "r") logFileContents = theLogFile.readlines() theLogFile.close() # find entry with first star entryIndex = self.indexInList(targetStringList[0][0], logFileContents) self.assertLess(-1, entryIndex, "Major: failure to find " + targetStringList[0][0] + " in log") for index in range(entryIndex+1, len(targetStringList)): entryIndex += 1 if(not(targetStringList[index][0] in logFileContents[entryIndex])): self.fail("Major: failure to find star in log") self.deleteNamedLogFlag = True
def test300_050_ShouldLogMultipleSightingsWithSameDateTime(self): testFile = "CA02_300_ValidMultipleStarSightingSameDateTime.xml" targetStringList = [ ["Acrux", "2016-03-01", "00:05:05"], ["Sirius", "2016-03-01", "00:05:05"], ["Canopus", "2016-03-02", "23:40:01"] ] theFix = F.Fix(self.RANDOM_LOG_FILE) theFix.setSightingFile(testFile) theFix.getSightings() theLogFile = open(self.RANDOM_LOG_FILE, "r") logFileContents = theLogFile.readlines() theLogFile.close() # find entry with first star entryIndex = self.indexInList(targetStringList[0][0], logFileContents) self.assertLess(-1, entryIndex, "Major: failure to find " + targetStringList[0][0] + " in log") for index in range(entryIndex+1, len(targetStringList)): entryIndex += 1 if(not(targetStringList[index][0] in logFileContents[entryIndex])): self.fail("Major: failure to find star in log") self.deleteNamedLogFlag = True
def test100_910_ShouldRaiseExceptionOnFileNameLength(self): expectedDiag = self.className + "__init__:" with self.assertRaises(ValueError) as context: F.Fix("") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for log file name length")
def test100_010_ShouldConstructFix(self): 'Fix.__init__' self.assertIsInstance(F.Fix(), F.Fix, "Major error: Fix not created")
import Navigation.prod.fix as fix theFix = fix.Fix() #l=theFix.__init__("log3.txt") k = theFix.setSightingFile("sightings.xml") #approximatePosition = theFix.getSightings() #fix2=logFile.logFile() #l=theFix.Fix.__init__Fix("C:\\Users\ChandrashekarChary\\Desktop\\fold\\log.txt") m = theFix.getSightings()
def test100_920_ShouldRaiseExceptionOnNonStringFile(self): expectedDiag = self.className + "__init__:" with self.assertRaises(ValueError) as context: F.Fix(42) self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for non-string log file name")