Пример #1
0
    def _parseNodeTestSX(self, parser, inputXS, expectedSX, ignoreChars=None):
        if ignoreChars is None:
            ignoreChars = self.__junk_regex__
        input = DMIOReader.readFromString(inputXS)
        expected = DMIOReader.readFromString(expectedSX)

        result = parser.traceParseNode(input, ignoreChars)

        if not result.isValid():
            print 'PARSE FAILURE while parsing', input
            print 'EXPECTED:'
            print expectedSX
            self._onError(result)
        self.assert_(result.isValid())

        value = DMNode.coerce(result.value)
        expected = DMNode.coerce(expected)

        bSame = value == expected
        if not bSame:
            print 'While parsing', input
            print 'EXPECTED:'
            print expectedSX
            print ''
            print 'RESULT:'
            print DMIOWriter.writeAsString(value)
            self._onError(result)
        self.assert_(bSame)
Пример #2
0
    def _parseNodeTest(self, parser, input, expected, ignoreChars=None):
        if ignoreChars is None:
            ignoreChars = self.__junk_regex__
        result = parser.traceParseNode(input, ignoreChars)

        if not result.isValid():
            print 'PARSE FAILURE while parsing %s' % (input, )
            print 'EXPECTED:'
            print expected
            self._onError(result)
        self.assert_(result.isValid())

        value = DMNode.coerce(result.value)
        expected = DMNode.coerce(expected)

        bSame = value == expected
        if not bSame:
            print 'While parsing', input
            print 'EXPECTED:'
            print expected
            print ''
            print 'RESULT:'
            print value
            self._onError(result)
        self.assert_(bSame)
Пример #3
0
    def _parseRichStringTestSX(self,
                               parser,
                               input,
                               expectedSX,
                               ignoreChars=None):
        if ignoreChars is None:
            ignoreChars = self.__junk_regex__
        expected = DMIOReader.readFromString(expectedSX)

        result = parser.traceParseListItems(input, ignoreChars)

        if not result.isValid():
            print 'PARSE FAILURE while parsing', input
            print 'EXPECTED:'
            print expectedSX
            self._onError(result)
        self.assert_(result.isValid())

        value = DMNode.coerce(result.value)
        expected = DMNode.coerce(expected)

        if result.end != len(input):
            print 'INCOMPLETE PARSE while parsing', input
            print 'Parsed %d/%d items' % (result.end, len(input))
            print input[:result.end]
            print 'EXPECTED:'
            print expectedSX
            print 'RESULT:'
            print DMIOWriter.writeAsString(value)
            self._onError(result)

        bSame = value == expected
        if not bSame:
            print 'While parsing', input
            print 'EXPECTED:'
            print expectedSX
            print ''
            print 'RESULT:'
            print DMIOWriter.writeAsString(value)
            self._onError(result)
        self.assert_(bSame)
Пример #4
0
    def test_coercion_objects(self):
        class MyObject(object):
            def __init__(self):
                pass

        q = MyObject()

        self._testCoerce(
            {1.0: q},
            DictLiteral(values=[
                DictKeyValuePair(key=FloatLiteral(value='1.0'),
                                 value=EmbeddedObjectExpr(
                                     embeddedValue=DMNode.embed(q)))
            ]))
Пример #5
0
def coerceToModel(x, coerceObj=EmbeddedObjectExpr):
    # Primitive values
    t = type(x)
    handler = _primitiveToMethodTypeMap.get(t)
    if handler is not None:
        return handler(x, coerceObj)

    # Object values
    if coerceObj is None:
        raise TypeError, 'Cannot coerce objects with an object coercion function or embedded object schema class'
    elif coerceObj is EmbeddedObjectExpr or coerceObj is EmbeddedObjectLiteral or coerceObj is EmbeddedObjectStmt:
        return coerceObj(embeddedValue=DMNode.embedIsolated(x))
    else:
        return coerceObj(x)
Пример #6
0
    def _parseRichStringTest(self, parser, input, expected, ignoreChars=None):
        if ignoreChars is None:
            ignoreChars = self.__junk_regex__
        result = parser.traceParseRichStringItems(input, ignoreChars)

        if not result.isValid():
            print 'PARSE FAILURE while parsing %s, stopped at %d: %s' % (
                input, result.end, input[:result.end])
            print 'EXPECTED:'
            print expected
            self._onError(result)
        self.assert_(result.isValid())

        value = DMNode.coerce(result.value)
        expected = DMNode.coerce(expected)

        if result.end != len(input):
            print 'INCOMPLETE PARSE while parsing', input
            print 'Parsed %d/%d items' % (result.end, len(input))
            print input[:result.end]
            print 'EXPECTED:'
            print expected
            print 'RESULT:'
            print value
            self._onError(result)

        bSame = value == expected
        if not bSame:
            print 'While parsing', input
            print 'EXPECTED:'
            print expected
            print ''
            print 'RESULT:'
            print value
            self._onError(result)
        self.assert_(bSame)
Пример #7
0
def _readInlineObjectStmt_v2(fieldValues):
    # Version 2 called the field 'resource', rather than 'embeddedValue'
    embeddedValue = fieldValues['resource']
    embeddedValue = DMNode.embed(None)
    return EmbeddedObjectStmt(embeddedValue=embeddedValue)
Пример #8
0
def embeddedStatement(x):
    return Py.EmbeddedObjectStmt(embeddedValue=DMNode.embedIsolated(x))
Пример #9
0
def embeddedExpression(x):
    return Py.EmbeddedObjectExpr(embeddedValue=DMNode.embedIsolated(x))
Пример #10
0
def embeddedLiteral(x):
    return Py.EmbeddedObjectLiteral(embeddedValue=DMNode.embedIsolated(x))
	def newParagraphEmbeddedObjectModel(value):
		embeddedValue = DMNode.embedIsolated( value )
		return Schema.ParagraphEmbeddedObject( embeddedValue=embeddedValue )
	def newInlineEmbeddedObjectModel(value):
		embeddedValue = DMNode.embedIsolated( value )
		return Schema.InlineEmbeddedObject( embeddedValue=embeddedValue )