示例#1
0
 def shouldHandleStringFromApplicationExit(self):
     self._setAppConfig((ExceptionTestAppConfig, ExceptionTestAppConfig(),
                         ExceptionTestAppConfig, ExceptionTestAppConfig()))
     e = FitException("Test003")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "It's magic!"
     assert isExc == KindOfMessage("exception")
     assert doTrace == TraceWanted("trace")
示例#2
0
 def shouldHandleNewMessageAndTraceFromApplicationExit(self):
     self._setAppConfig((ExceptionTestAppConfig, ExceptionTestAppConfig(),
                         ExceptionTestAppConfig, ExceptionTestAppConfig()))
     e = FitException("Test002")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "Insert lightbulb joke here"
     assert isExc == KindOfMessage("exception")
     assert doTrace == TraceWanted("ignore")
示例#3
0
 def shouldHandleTraceOverrideFromApplicationExit(self):
     self._setAppConfig((ExceptionTestAppConfig, ExceptionTestAppConfig(),
                         ExceptionTestAppConfig, ExceptionTestAppConfig()))
     e = FitException("Test001", "snark", "bojum")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "For the snark was a bojum, you see."
     assert isExc == KindOfMessage("wrong")
     assert doTrace == TraceWanted("ignore")
示例#4
0
 def shouldHandleNewMessageAndTraceFromApplicationExit(self):
     self._setAppConfig(
         (ExceptionTestAppConfig, ExceptionTestAppConfig(), ExceptionTestAppConfig, ExceptionTestAppConfig())
     )
     e = FitException("Test002")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "Insert lightbulb joke here"
     assert isExc == KindOfMessage("exception")
     assert doTrace == TraceWanted("ignore")
示例#5
0
 def shouldHandleStringFromApplicationExit(self):
     self._setAppConfig(
         (ExceptionTestAppConfig, ExceptionTestAppConfig(), ExceptionTestAppConfig, ExceptionTestAppConfig())
     )
     e = FitException("Test003")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "It's magic!"
     assert isExc == KindOfMessage("exception")
     assert doTrace == TraceWanted("trace")
示例#6
0
 def shouldHandleTraceOverrideFromApplicationExit(self):
     self._setAppConfig(
         (ExceptionTestAppConfig, ExceptionTestAppConfig(), ExceptionTestAppConfig, ExceptionTestAppConfig())
     )
     e = FitException("Test001", "snark", "bojum")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "For the snark was a bojum, you see."
     assert isExc == KindOfMessage("wrong")
     assert doTrace == TraceWanted("ignore")
 def getImageFileName(self, aString):
     srcPos = aString.lower().find("src=")
     if srcPos == -1:
         raise FitException("NotImgTag", aString)
     delim = aString[srcPos+4]
     endPos = aString.find(delim, srcPos + 5)
     return aString[srcPos+5: endPos]
示例#8
0
 def _verifyClassType(self, aClass, unused, dummy,
                      shouldBeAFixture):
     isItAFixture = issubclass(aClass, fit.Fixture.Fixture)
     if isItAFixture is shouldBeAFixture:
         return
     raise FitException("ClassNotDerivedFromFixture",
                          self.originalNameRequested)
    def _openRangeCheck(self, parts, aFloat):
        a = self._parse(parts[0])
        b = self._parse(parts[2])
        if a is None and b is None:
            raise FitException("invRangeExp", self.value)
        if a is not None and b is not None:
            raise FitException("invRangeExp", self.value)
        if a is None:
            a = aFloat
        else:
            b = aFloat

        result = self._compare(a, parts[1], b)
        if self.checkOptions[2] == "f":
            raise FitException("noFloatCheckRange")
        return result
 def _objEquals(self, a, b):
     if self.checkOptions[0] == "f":
         raise FitException("noFloatCheck1")
     # XXX does not handle NaN properly
     if a == b:
         return True  # hack!
     # same routine unittest supposedly uses.
     return round(a - b, self.precision) == 0
 def doCell(self, cell, column):
     if column >= len(self.columnExecutors):
         raise FitException("RowTooLong")
     a = self.columnBindings[column]
     try:
         self.columnExecutors[column](cell, a)
     except Exception, e:
         self.exception(cell, e)
示例#12
0
 def __init__(self, aString):
     if isinstance(aString, types.StringTypes):
         self._dot = aString
     elif isinstance(aString, LocalFile.LocalFile):
         self._dot = self.getFileContents(aString)  # XXX feature envy!
     else:
         raise FitException("badConstructorType", "DotGraphic",
                            "String or LocalFile", str(type(aString)))
 def _rangeCheck(self, parts, aFloat):
     a = self.parse(parts[0])
     b = self.parse(parts[4])
     result = self._compare(a, parts[1], aFloat)
     if result:
         result = self._compare(aFloat, parts[3], b)
     if self.checkOptions[2] == "f":
         raise FitException("noFloatCheckRange")
     return result
 def getAdapter(self, cell):
     raiseIfNone(cell, "missingMethodNameCell")
     methodName = self.camel(cell.text())
     raiseIf(methodName == "", "missingMethodName")
     raiseIfNone(self.actor, "missingActor")
     try:
         adapter = TypeAdapter(self.actor, methodName)
     except Exception, ex:
         self.exception(cell, ex)
         raise FitException("IgnoreException")
 def _compare(self, a, op, b):
     if op == "<":
         return a < b
     if op in ("<=", u"\u2264"):
         return a <= b
     if op == ">":
         return a > b
     if op in (">=", u"\u2265"):
         return a >= b
     raise FitException("invRangeExp", self.value)  #pragma: no cover
示例#16
0
 def _doLoad(self, parts, pathToModule, className):
     try:
         result = __import__(pathToModule)
     except ImportError, e:
         msg = str(e)
         self.msgFromImportError = msg
         if msg.startswith("No module named "):
             raise FitException("ModuleNotFound", pathToModule)
         else: #pragma: no cover
             raise
 def doCells(self, cells):
     self.cells = cells
     command = cells.text()
     method = getattr(self, command+"_", None)
     if method is None:
         self.exception(cells, FitException("InvalidCommand", command))
         return 
     try:
         method()
     except Exception, e:
         self.exception(cells, e)
 def _epsilonCheck(self, parts, aFloat):
     if self.checkOptions[1] == "f":
         raise FitException("noFloatCheckEpsilon")
     base = self.parse(parts[0])
     epsilon = self.parse(parts[2])
     low = base - epsilon
     high = base + epsilon
     if low < high:
         return low < aFloat < high
     else:
         return high <= aFloat <= low
示例#19
0
 def doRow(self, row):
     if self.methodOK is False:
         self.ignore(row)
         return
     if row.parts is None:
         row.parts = Parse(tag="tr", body="inserted cell")
         self.exception(row.parts,
                 FitException("MissingRowFailureException"))
         return
     if row.parts.size() != self.argCount:
         self.exception(row.parts, FitException("RowIsWrongLength"))
         return
     try:
         result = bool(self.target.invokeWithCells(row.parts))
         if result is self.expected:
             self.right(row)
         else:
             self.wrong(row)
     except Exception, e:
         self.exception(row.parts, e)
 def _checkForShortRows(self, rows):
     minLen = len(self.columnBindings)
     rowList = []
     while rows is not None:
         # !!! Following test is for a condition that gets a Parse exception
         #     See test named:
         #       shouldMarkRowWithoutCellsAsMissingWithExceptiion
         if rows.parts is not None:
             rowLen = rows.parts.size()
             if rowLen < minLen:
                 self.exception(rows.parts, FitException("RowTooShort"))
                 self.missing.append(rows)
             else:
                 rowList.append(rows)
         else:  #pragma: no cover
             newCell = Parse(tag='td colspan="%s"' % minLen,
                             body="[Cell inserted by RowFixture]")
             self.exception(newCell, FitException("noCells"))
             rows.parts = newCell
             self.missing.append(rows)
         rows = rows.more
     return rowList
 def _stringEquals(self, a, b):
     self.value = a
     parts = re.split(ur"(<=|<|>=|>|\+/-|\u00b1|\u2264|\u2265)", a)
     parts = [x.strip() for x in parts]
     if len(parts) == 1:
         if self.checkOptions[0] == "f":
             raise FitException("noFloatCheck1")
         specValue = _floatSpecialValueDict.get(parts[0].lower())
         # XXX does not handle NaN correctly.
         # XXX does not handle case of b being a special value.
         if specValue is not None:
             return specValue == b
         if self.checkOptions[0] == "c":
             return self._objEquals(float(parts[0]), b)
         return self._appendCheck(a, b)
     if len(parts) == 3:
         if parts[1] in ("+/-", u"\u00b1"):
             return self._epsilonCheck(parts, b)
         return self._openRangeCheck(parts, b)
     elif len(parts) == 5:
         return self._rangeCheck(parts, b)
     else:
         raise FitException("floatImproperSyntax", self.value)
示例#22
0
    def doRow(self, row):
        if not self.boundOK:
            self.ignore(row.parts)
            return

        if row.parts.size() != self.rowLength:
            self.exception(row.parts,
                           FitException("RowSBxWide", self.rowLength))
            return

        expectedCell = row.parts.at(self.argCount + 1)
        for theTarget in self.targets:
            theTarget.invokeAndCheck(row.parts, expectedCell)
            expectedCell = expectedCell.more
    def setActualCollection(self):
        collection = self.paramCollection
        #        typeDict = self.paramTypeDict
        if collection is None:
            args = self.getArgCells()
            if len(args) == 2 and self.__class__.__name__ in ("RowFixture",
                                                              "ArrayFixture",
                                                              "SetFixture",
                                                              "SubsetFixture"):
                try:
                    argObj = self.getSymbol(args[1].text())
                except Exception:
                    self.exception(
                        args[1],
                        FitException("SymbolNotDefined", args[1].text()))
                    raise FitException("IgnoreException")
                collection = argObj.collection
                RowFixture._typeDict = argObj.metaData
#                typeDict = argObj.metaData
            else:
                collection = self.query()


#                typeDict = self.getTargetClass()._typeDict
        if isinstance(collection, dict):
            aList = collection.items()
            aList.sort()
            self.actuals = [y for x, y in aList]
        elif (isinstance(collection, types.StringTypes)):
            raise FitException("UnsupportedCollectionType", type(collection))
        else:
            try:
                self.actuals = [x for x in collection]
            except Exception:
                raise FitException("UnsupportedCollectionType",
                                   type(collection))
 def doRows(self, rows):
     self.setActualCollection()
     if rows is None:
         raise FitException("ColumnHeadsMissing")
     try:
         self.bind(rows.parts)
         self.missing = []
         self.surplus = []
         rowList = self._checkForShortRows(rows.more)
         self.match(rowList, self.actuals, 0)
         last = rows.last()
         last.more = self.buildRows(self.surplus)
         self.markRows(last.more, "surplus")
         self.markList(self.missing, "missing")
     except Exception, e:
         self.exception(rows.leaf(), e)
示例#25
0
 def bind(self, row):
     heads = row
     self.argCount = heads.size()
     argNames = ""
     while heads is not None:
         argNames += (heads.text() + " ")
         heads = heads.more
     try:
         methodName = self.camel(argNames, kind = "extended")
         self.target = self.findMethod(methodName, self.argCount)
         if self.target.getReturnType() != "Boolean":
             raise FitException("BooleanMethodFitFailureException", methodName)
         self.target.setRepeatAndExceptionString(self.repeatString, # ???
                                            self.exceptionString)
         self.methodOK = True
     except Exception, e:
         self.exception(row, e)
         return
 def bind(self, labels):
     wasError = False
     #        usedField = [False] * labels.size()
     adapters = []
     fieldNames = []
     symRefs = []
     #        targetClass = self.getTargetClass()
     typeDict = self.paramTypeDict
     typeDict = typeDict or getattr(self, "_typeDict", None)  # legacy
     typeDict = typeDict or self.getTargetClass()._typeDict
     extendedLabelProcess = typeDict.get(".extendedLabelProcess", "off")
     colNum = 0
     while labels is not None:
         fieldName = labels.text()
         if extendedLabelProcess == "on":
             colType, camelName = self.processLabel(fieldName, colNum)
             isSymRef = (colType == "checkSymbol")
         else:
             isSymRef, camelName = self._decodeLabel(fieldName, typeDict)
         if not self._isFieldInAnyObject(camelName, self.actuals):
             self.exception(labels, FitException("FieldNotInCollection"))
             wasError = True
             accessor = None
         else:
             #                metaData = typeDict.get(camelName)
             colType = typeDict.get(camelName + ".columnType")
             if colType == "checkSymbol":
                 isSymRef = True
             try:
                 accessor = TypeAdapter.on(
                     self,
                     camelName,
                     typeDict,
                     #                            {camelName: metaData},
                     accClass=TypeAdapter.AccessorBaseClass)
             except FitException, e:
                 self.exception(labels, e)
                 accessor = None
         adapters.append(accessor)
         fieldNames.append(camelName)
         symRefs.append(isSymRef)
         labels = labels.more
         colNum += 1
示例#27
0
 def mapLabel(self, label, kind=None, default=None):
     result = FitGlobal.appConfigInterface("mapLabel", label)
     if result is None or result[0] is None:
         pass
     elif result[0] == "done":
         return result[1]
     else:
         kind = result[1]
     kind = kind or default or "default"
     if kind == "camel":
         return self._camelLabelMapping(label)
     elif kind == "gracefulNames":
         return self._gracefulNamesLabelMapping(label)
     elif kind == "extended":
         return self._extendedLabelMapping(label)
     elif kind == "default":
         if FitGlobal.Environment == "FitNesse":
             return self._gracefulNamesLabelMapping(label)
         else:
             return self._camelLabelMapping(label)
     raise FitException("InvalidKindForMapLabel", kind)
示例#28
0
 def doRow(self, row):
     cell = row.parts
     try:
         if cell is None: # factor cell is missing
             cell = Parse(tag="td", body="cell added")
             row.parts = cell
             raise FitException("MissingCellsFailureException")
         arg1 = self.method.parameterAdapters[1].parse(cell)
         cell = cell.more
         self._validateCellExists(cell)
         self._validateRowLength(cell, len(self.topValues))
         if self.methodOK is False:
             self.ignore(row)
             return
         i = 0
         while cell != None:
             result = self.method.invokeWithArgs([arg1, self.topValues[i]])
             self.method.checkResult(cell, result)
             cell = cell.more
             i += 1
     except Exception, e:
         self.exception(cell, e)
         self.methodOK = False
示例#29
0
    def bind(self, row):
        heads = row
        phase = 0 # 0: given 1: boundary 2: calculated 3: boundary 4: notes
        cellNumber = -1
        self.rowLength = heads.size()
        argNames = ""
        i = 0
        while heads != None:
            name = heads.text()
            cellNumber += 1
            try:
                if name == "":
                    if phase in (0, 2):
                        phase += 1

                elif phase in (1, 2):
                    if phase == 1:
                        phase = 2
                        self.argCount = cellNumber - 1
                        self.targets = []
                    methodName = self.camel(name+argNames, kind="extended")
                    target = self.findMethod(methodName, self.argCount)
                    if target.getReturnType() is None:
                        raise FitException(
                            "VoidMethodFitFailureException", methodName)
                    self.targets.append(target)
                    self.methods += 1
                    target.setRepeatAndExceptionString(self.repeatString,
                                                       self.exceptionString);
                elif phase == 0:
                    argNames += " " + name
            except Exception, e:
                self.exception(heads, e)
                return
            i += 1
            heads = heads.more
示例#30
0
    def args(self, aTuple):
#        em("\nargs: '%s'" % (aTuple,))
        excObj = FitException(*aTuple)
#        em("argsInFitException: '%s'" % (excObj.args,))
        self.exc, self.trace, self.message = excObj.getMeaningfulMessage()
 def _bindColumnExecutor(self, executorName, kind, i, identifier):
     if executorName is None:
         raise FitException("UnknownColumnType", kind, identifier)
     self.columnExecutors[i] = getattr(self, executorName)
 def testingErrorExecutor(self, unused="cell", dummy="accessor"):
     raise FitException("anException",
                        "This is a test. This is only a test")
示例#33
0
 def shouldRetrieveMessageParameters(self):
     e = FitException("Test001", "snark", "bojum")
     isExc, doTrace, msg = e.getMeaningfulMessage()
     assert msg == "For the snark was a bojum, you see."
     assert isExc == KindOfMessage("wrong")
     assert doTrace == TraceWanted("notrace")
示例#34
0
 def should_badKey(self):
     e = FitException("100tseT", "snark", "bojum")
     result = e.getMeaningfulMessage()
     assert result[2] == "Unknown Message Key: ('100tseT', 'snark', 'bojum')"
示例#35
0
 def shouldGiveMessageForWrongNumberOfParameters(self):
     e = FitException("Test001")
     assert str(e).find("Wrong number of parameters to FitException") > -1
示例#36
0
 def shouldHaveTupleArgsForSingleParamter(self):
     e = FitException("Parse001")
     assert len(e.args) == 1