Example #1
0
    def test_utils_markup_overflow_deep_2(self):
        assert isinstance(markup.elements.base.OverflowBarier(),
                          markup.elements.lang.TreeNode)
        assert issubclass(markup.elements.base.OverflowBarier,
                          markup.elements.lang.TreeNode)
        assert isinstance(
            markup.elements.base.SerializationError(text='1', cls='1'),
            markup.elements.lang.TreeNode)
        assert issubclass(markup.elements.base.SerializationError,
                          markup.elements.lang.TreeNode)
        assert not isinstance(markup.elements.base.Markup(),
                              markup.elements.lang.TreeNode)
        assert not issubclass(markup.elements.base.Markup,
                              markup.elements.lang.TreeNode)

        from edgedb.lang.common.markup.serializer.base \
            import OVERFLOW_BARIER, Context

        def gen(deep):
            if deep > 0:
                return SpecialList([gen(deep - 1)])

        assert not str(
            markup.serialize(gen(OVERFLOW_BARIER - 1),
                             ctx=Context())).count('Overflow')
        assert str(markup.serialize(gen(OVERFLOW_BARIER + 10),
                                    ctx=Context())).count('Overflow') == 1
        assert not str(
            markup.serialize(gen(OVERFLOW_BARIER + 10),
                             ctx=Context())).count('SerializationError')
Example #2
0
    def as_markup(cls, self, *, ctx):
        me = markup.elements
        body = []

        delta = delta_schemas(self.schema2, self.schema1)
        title = (f'Schema Delta Diff ({self.schema1_title} -> '
                 f'{self.schema2_title}):')
        body.append(
            me.doc.Section(title=title,
                           body=[markup.serialize(delta, ctx=ctx)]))

        diff = edgedb_debug.get_schema_hash_diff(self.schema1,
                                                 self.schema2,
                                                 a_title=self.schema1_title,
                                                 b_title=self.schema2_title)

        body.append(me.doc.Section(title='Schema Hash Diff', body=[diff]))

        diff = edgedb_debug.get_list_diff(self.schema1_checksums or [],
                                          self.schema2_checksums or [],
                                          a_title=self.schema1_title,
                                          b_title=self.schema2_title)

        body.append(
            me.doc.Section(title='Schema Object Hashes Diff', body=[diff]))

        diff = edgedb_debug.get_schema_text_diff(self.schema1,
                                                 self.schema2,
                                                 a_title=self.schema1_title,
                                                 b_title=self.schema2_title)

        body.append(me.doc.Section(title='Schema Text Diff', body=[diff]))

        return markup.elements.lang.ExceptionContext(title=self.title,
                                                     body=body)
Example #3
0
    def as_markup(cls, self, *, ctx):
        node = markup.elements.lang.TreeNode(name=repr(self))

        for op in self.commands:
            node.add_child(node=markup.serialize(op, ctx=ctx))

        return node
Example #4
0
    def as_markup(cls, self, *, ctx):
        node = markup.elements.lang.TreeNode(name=repr(self))

        for op in self.commands:
            node.add_child(node=markup.serialize(op, ctx=ctx))

        return node
Example #5
0
    def as_markup(cls, self, *, ctx):
        me = markup.elements
        body = []

        delta = delta_schemas(self.schema2, self.schema1)
        title = (f'Schema Delta Diff ({self.schema1_title} -> '
                 f'{self.schema2_title}):')
        body.append(me.doc.Section(
            title=title, body=[markup.serialize(delta, ctx=ctx)]))

        diff = edgedb_debug.get_schema_hash_diff(self.schema1, self.schema2,
                                                 a_title=self.schema1_title,
                                                 b_title=self.schema2_title)

        body.append(me.doc.Section(title='Schema Hash Diff', body=[diff]))

        diff = edgedb_debug.get_list_diff(
            self.schema1_checksums or [],
            self.schema2_checksums or [],
            a_title=self.schema1_title,
            b_title=self.schema2_title)

        body.append(me.doc.Section(title='Schema Object Hashes Diff',
                                   body=[diff]))

        diff = edgedb_debug.get_schema_text_diff(self.schema1, self.schema2,
                                                 a_title=self.schema1_title,
                                                 b_title=self.schema2_title)

        body.append(me.doc.Section(title='Schema Text Diff', body=[diff]))

        return markup.elements.lang.ExceptionContext(title=self.title,
                                                     body=body)
Example #6
0
    def _get_test_markup(self):
        def foobar():
            raise ValueError('foobar: spam ham!')

        exc = None

        try:
            foobar()
        except Exception as ex:
            exc = ex

        return markup.serialize(exc, ctx=markup.Context())
Example #7
0
    def as_markup(cls, self, *, ctx):
        node = markup.elements.lang.TreeNode(name=str(self))

        for dd in self:
            if isinstance(dd, AlterObjectProperty):
                diff = markup.elements.doc.ValueDiff(before=repr(dd.old_value),
                                                     after=repr(dd.new_value))

                node.add_child(label=dd.property, node=diff)
            else:
                node.add_child(node=markup.serialize(dd, ctx=ctx))

        return node
Example #8
0
    def as_markup(cls, self, *, ctx):
        node = markup.elements.lang.TreeNode(name=str(self))

        for dd in self:
            if isinstance(dd, AlterObjectProperty):
                diff = markup.elements.doc.ValueDiff(
                    before=repr(dd.old_value), after=repr(dd.new_value))

                node.add_child(label=dd.property, node=diff)
            else:
                node.add_child(node=markup.serialize(dd, ctx=ctx))

        return node
Example #9
0
    def as_markup(cls, self, *, ctx):
        me = markup.elements

        body = [
            me.doc.Section(
                title='SQL Tree', body=[markup.serialize(self.node, ctx=ctx)])
        ]

        if self.chunks_generated:
            code = markup.serializer.serialize_code(
                ''.join(self.chunks_generated), lexer='sql')
            body.append(
                me.doc.Section(title='SQL generated so far', body=[code]))

        return me.lang.ExceptionContext(title=self.title, body=body)
Example #10
0
    def as_markup(cls, self, *, ctx):
        me = markup.elements

        body = [
            me.doc.Section(title='SQL Tree',
                           body=[markup.serialize(self.node, ctx=ctx)])
        ]

        if self.chunks_generated:
            code = markup.serializer.serialize_code(''.join(
                self.chunks_generated),
                                                    lexer='sql')
            body.append(
                me.doc.Section(title='SQL generated so far', body=[code]))

        return me.lang.ExceptionContext(title=self.title, body=body)
Example #11
0
def _serialize_to_markup(ast, *, ctx):
    node = markup.elements.lang.TreeNode(id=id(ast), name=type(ast).__name__)
    include_meta = ctx.kwargs.get('_ast_include_meta', True)
    exclude_unset = ctx.kwargs.get('_ast_exclude_unset', True)

    fields = iter_fields(ast,
                         include_meta=include_meta,
                         exclude_unset=exclude_unset)
    for fieldname, field in fields:
        if ast._fields[fieldname].hidden:
            continue
        if field is None:
            if ast._fields[fieldname].meta:
                continue
        node.add_child(label=fieldname, node=markup.serialize(field, ctx=ctx))

    return node
Example #12
0
 def as_markup(cls, self, *, ctx):
     title = '{} {:032x}'.format(self.title, self.delta.id)
     body = [
         markup.serialize(delta, ctx=ctx) for delta in self.delta.deltas
     ]
     return markup.elements.lang.ExceptionContext(title=title, body=body)
Example #13
0
def serialize_special(obj, *, ctx):
    if obj and isinstance(obj[0], SpecialList):
        child = markup.serialize(obj[0], ctx=ctx)
        return SpecialListNode(node=child)
    else:
        return SpecialListNode()
Example #14
0
 def as_markup(cls, self, *, ctx):
     tree = markup.serialize(self.tree, ctx=ctx)
     return markup.elements.lang.ExceptionContext(
         title=self.title, body=[tree])
Example #15
0
 def as_markup(cls, self, *, ctx):
     title = '{} {:032x}'.format(self.title, self.delta.id)
     body = [markup.serialize(delta, ctx=ctx)
             for delta in self.delta.deltas]
     return markup.elements.lang.ExceptionContext(title=title, body=body)