def test500_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 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.cleanup()
def test500_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 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 test400_940_ShouldRaiseExceptionOnNonTxtFile1(self): expectedDiag = self.className + "setStarFile:" theFix = Fix.Fix() with self.assertRaises(ValueError) as context: theFix.setStarFile("star.") self.assertEquals( expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Minor: failure to check for non.xml star file extension")
def test400_910_SholdRaiseExceptionOnMissingFileName(self): expectedDiag = self.className + "setStarFile:" theFix = Fix.Fix() with self.assertRaises(ValueError) as context: theFix.setStarFile() self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Major: failure to check for missing star file")
def test500_990_ShouldRaiseExceptionOnInvalidPressure(self): expectedDiag = self.className + "getSightings:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setSightingFile("CA02_300_InvalidPressure.xml") theFix.getSightings() self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)], "Major: failure to check for invalid body" )
def test400_930_ShouldRaiseExceptionOnNonTXTFile1(self): expectedDiag = self.className + "setStarFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setStarFile("sighting.") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)]) os.remove(self.DEFAULT_LOG_FILE)
def test100_030_ShouldWriteStartLogToLogFile(self): aF = F.Fix("normal.txt") with open(aF.logFile, 'r') as f: lines = f.readlines() last_line = lines[-1] f.close() expectedLine = aF.message("Log file:\t" + os.path.abspath(aF.logFile)) self.assertEquals(last_line, expectedLine)
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_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 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 test400_940_SholdRaiseExceptionOnMissingFileName(self): expectedDiag = self.className + "setStarFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setStarFile('missing.txt') self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)]) os.remove(self.DEFAULT_LOG_FILE)
def test300_920_ShouldRaiseExceptionOnFileLengthError(self): expectedDiag = self.className + "setAriesFile:" theFix = F.Fix() with self.assertRaises(ValueError) as context: theFix.setAriesFile(".txt") self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)]) os.remove(self.DEFAULT_LOG_FILE)
def main(): myFix = Fix.Fix() myFix.setSightingFile("f4.xml") print("Start") approxPos = myFix.getSightings() print approxPos print("End")
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)], "Major: failure to check for missing sighting file")
def test300_020_ShouldReturnTupleOfApproximateLocation(self): theFix = F.Fix() theFix.setSightingFile("CA05_300_ValidSightingFile.xml") theFix.setStarFile("CA03_Valid_Stars.txt") theFix.setAriesFile("CA03_Valid_Aries.txt") result = theFix.getSightings("N27d59.5", "85d33.4") expectedResult = ("S20d15.5", "79d19.9") self.assertTupleEqual(result, expectedResult)
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 test100_030_LatitudeShouldReturnDefaultWithoutParameter(self): expectedLat = "0d0.0" aFix = Fix.Fix('testLogCA05.txt') aFix.setSightingFile('sightingFileCA05.xml') aFix.setStarFile("stars.txt") aFix.setAriesFile("aries.txt") aFix.getSightings() actualLat = aFix.assumedLat self.assertEquals(expectedLat, actualLat)
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 test200_020_ShouldWriteEntryToLogFile(self): fixInstance=Fix.Fix() fixInstance.setSightingFile("2.xml") logFileName=fixInstance.logFileName for line in reversed(open(logFileName).readlines()): string=line.rstrip() break expectedString="Sighting file:"+"\t"+os.path.abspath(fixInstance.xmlFileName) self.assertEqual(string, expectedString)
def test100_910_LatitudeShouldRaiseExceptionWithHAndDefaultAngle(self): expected = "0d0.0" aFix = Fix.Fix('testLogCA05.txt') aFix.setSightingFile('sightingFileCA05.xml') aFix.setStarFile("stars.txt") aFix.setAriesFile("aries.txt") aFix.getSightings("0d0.0", "0d0.0") actual = aFix.assumedLong self.assertEquals(expected, actual)
def test100_070_LongitudeShouldReturnDefault(self): expected = "0d0.0" aFix = Fix.Fix('testLogCA05.txt') aFix.setSightingFile('sightingFileCA05.xml') aFix.setStarFile("stars.txt") aFix.setAriesFile("aries.txt") aFix.getSightings("0d0.0", "0d0.0") actual = aFix.assumedLong self.assertEquals(expected, actual)
def test100_060_LongitudeShouldReturnValidString(self): expected = "85d33.4" aFix = Fix.Fix('testLogCA05.txt') aFix.setSightingFile('sightingFileCA05.xml') aFix.setStarFile("stars.txt") aFix.setAriesFile("aries.txt") aFix.getSightings("N27d59.5", "85d33.4") actual = aFix.assumedLong self.assertEquals(expected, actual)
def test500_020_ShouldWriteToTheLogFile(self): fixInstance=Fix.Fix("test3") fixInstance.setStarFile("stars.txt") logFileName=fixInstance.logFileName for line in reversed(open(logFileName).readlines()): string=line.rstrip() break expectedString="Star file:"+"\t"+os.path.abspath("stars.txt") self.assertEqual(string, expectedString)
def test500_910_ShouldRaiseExceptionOnNotSettingAriesFile(self): expectedDiag = self.className + "getSightings:" theFix = F.Fix() theFix.setSightingFile('CA02_300_ValidOneStarWithDefaultValues.xml') with self.assertRaises(ValueError) as context: theFix.getSightings() self.assertEquals(expectedDiag, context.exception.args[0][0:len(expectedDiag)]) os.remove(self.DEFAULT_LOG_FILE)
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.cleanup()
def test300_010_ShouldDefaultToZeroOnMissingParameter(self): theFix = F.Fix() theFix.setSightingFile("CA05_300_ValidSightingFile.xml") theFix.setStarFile("CA03_Valid_Stars.txt") theFix.setAriesFile("CA03_Valid_Aries.txt") theFix.getSightings() expectedResult = ("0d0.0", "0d0.0") result = theFix.getAssumedLatiLogi() self.assertTupleEqual(result, expectedResult)
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_LatitudeShouldReturnValidStringWhereHIsS(self): expected = "S27d59.5"#hxdy.y aFix = Fix.Fix('testLogCA05.txt') aFix.setSightingFile('sightingFileCA05.xml') aFix.setStarFile("stars.txt") aFix.setAriesFile("aries.txt") aFix.getSightings("S27d59.5", "0d0.0") actual = aFix.assumedLat self.assertEquals(expected, actual)