Example #1
0
    def test_wrap_multi1(self):
        s = '012345'
        a1 = Ann(1, 3, 'g1', ['c'])
        a2 = Ann(3, 5, 'g2', ['c'])

        self.check(
            html.wrap(s, [a1, a2]),
            '0{a1}12</span>{a2}34</span>5'.format(a1=a1.format(),
                                                  a2=a2.format()))
        self.check(
            html.wrap(s, [a2, a1]),
            '0{a1}12</span>{a2}34</span>5'.format(a1=a1.format(),
                                                  a2=a2.format()))
Example #2
0
    def test_wrap_multi1(self):
        s = '012345'
        a1 = Ann(1, 3, 'g1', ['c'])
        a2 = Ann(3, 5, 'g2', ['c'])

        self.check(
            html.wrap(s, [a1, a2]),
            '0{a1}12</span>{a2}34</span>5'.format(a1=a1.format(),
                                                  a2=a2.format()))
        self.check(
            html.wrap(s, [a2, a1]),
            '0{a1}12</span>{a2}34</span>5'.format(a1=a1.format(),
                                                  a2=a2.format()))
Example #3
0
    def test_wrap_multi2(self):
        s = '012345'
        a1 = Ann(0, len(s), 'g1', ['c'])
        a2 = Ann(2, 4, 'g2', ['c'])

        self.assertEquals(
            html.wrap(s, [a1, a2]),
            '{a1}01{a2}23</span>45</span>'.format(a1=a1.format(),
                                                   a2=a2.format()))
Example #4
0
    def test_wrap_multi2(self):
        s = '012345'
        a1 = Ann(0, len(s), 'g1', ['c'])
        a2 = Ann(2, 4, 'g2', ['c'])

        self.assertEquals(
            html.wrap(s, [a1, a2]),
            '{a1}01{a2}23</span>45</span>'.format(a1=a1.format(),
                                                  a2=a2.format()))
Example #5
0
def testpage():
    query = '''\
SELECT p.Name AS ProductName
       NonDiscountSales = (OrderQty * UnitPrice),
       Discounts = ((OrderQty * UnitPrice) * UnitPriceDiscount)
FROM Production.Product AS p
INNER JOIN Sales.SalesOrderDetail AS sod ON p.ProductID = sod.ProductID
ORDER BY ProductName DESC;

this is a very very very very very very very very very very very very very very very very very very very very very long line'''

    a = []
    a.append(
        Annotation(0, query.index('FROM'), 'select', [structs.decorate.BLOCK]))
    a.append(
        Annotation(query.index('FROM'), query.index('INNER'), 'from',
                   [structs.decorate.BLOCK]))
    a.append(
        Annotation(query.index('INNER'), query.index('ORDER'), 'inner',
                   [structs.decorate.BLOCK]))
    a.append(
        Annotation(query.index('ORDER'), len(query), 'order',
                   [structs.decorate.BLOCK]))
    a.append(
        Annotation(query.index('tName'),
                   query.index('= (Ord') + 5, 'foo', [structs.decorate.UNDER]))

    x = 'n.Prod'
    a.append(
        Annotation(query.index(x),
                   query.index(x) + 9, 'foo', [structs.decorate.UNDER]))
    a.append(Annotation(0, 4, 'bar', [structs.decorate.UNDER]))
    a.append(Annotation(2, 6, 'baz', [structs.decorate.UNDER]))
    a.append(
        Annotation(query.index('.Name'),
                   query.index('AS') + 2, 'foobar', [structs.decorate.BACK]))
    a.append(
        Annotation(query.index('Product'),
                   query.index('tName') + 4, 'foobar',
                   [structs.decorate.BACK]))
    a.append(
        Annotation(query.index('((Or'),
                   query.index('((Or') + 9, 'foobar', [structs.decorate.BACK]))
    a.append(
        Annotation(query.index('ct AS p'),
                   query.index('AS sod') + 5, 'convex',
                   [structs.decorate.UNDER]))

    query = html.wrap(query, a)

    testpage = docs.readone(os.path.join(config.ROOT, 'tests',
                                         'testpage.html'))

    return render_template('query.html',
                           query=markupsafe.Markup(query),
                           docs=[('testpage.html', markupsafe.Markup(testpage))
                                 ])
Example #6
0
    def test_wrap_newline(self):
        #    01 2345
        s = '0\n 1 2'
        a1 = Ann(0, 4, 'g1', [structs.decorate.UNDER])
        a2 = Ann(3, 4, 'g2', [structs.decorate.UNDER])

        self.check(
            html.wrap(s, [a1, a2]),
            '{a1}0</span>\n {a1}{a2}1</span></span> 2'.format(a1=a1.format(),
                                                              a2=a2.format()))
Example #7
0
    def test_wrap_newline(self):
        #    01 2345
        s = '0\n 1 2'
        a1 = Ann(0, 4, 'g1', [structs.decorate.UNDER])
        a2 = Ann(3, 4, 'g2', [structs.decorate.UNDER])

        self.check(
            html.wrap(s, [a1, a2]),
            '{a1}0</span>\n {a1}{a2}1</span></span> 2'.format(a1=a1.format(),
                                                              a2=a2.format()))
Example #8
0
    def test_wrap_overlap(self):
        s = '012345'
        a1 = Ann(1, 3, 'g1', ['c'])
        a2 = Ann(2, 4, 'g2', ['c'])

        self.check(
            html.wrap(s, [a1, a2]),
            '0{a1}1{a2index}2</span></span>{a2}3</span>45'.format(
                a1=a1.format(),
                a2index=a2.format(), #a2.addclass('showdocs-decorate-index-1').format(),
                a2=a2.format()))
Example #9
0
    def test_wrap_multi3(self):
        s = '012'
        a1 = Ann(0, 1, 'g1', ['c'])
        a2 = Ann(1, 2, 'g2', ['c'])
        a3 = Ann(1, 2, 'g3', ['c'])

        self.check(
            html.wrap(s, [a1, a2, a3]),
            '{a1}0</span>{a2}{a3}1</span></span>2'.format(a1=a1.format(),
                                                          a2=a2.format(),
                                                          a3=a3.format()))
Example #10
0
    def test_wrap_multi3(self):
        s = '012'
        a1 = Ann(0, 1, 'g1', ['c'])
        a2 = Ann(1, 2, 'g2', ['c'])
        a3 = Ann(1, 2, 'g3', ['c'])

        self.check(
            html.wrap(s, [a1, a2, a3]),
            '{a1}0</span>{a2}{a3}1</span></span>2'.format(a1=a1.format(),
                                                          a2=a2.format(),
                                                          a3=a3.format()))
Example #11
0
    def test_wrap_overlap(self):
        s = '012345'
        a1 = Ann(1, 3, 'g1', ['c'])
        a2 = Ann(2, 4, 'g2', ['c'])

        self.check(
            html.wrap(s, [a1, a2]),
            '0{a1}1{a2index}2</span></span>{a2}3</span>45'.format(
                a1=a1.format(),
                a2index=a2.format(
                ),  #a2.addclass('showdocs-decorate-index-1').format(),
                a2=a2.format()))
Example #12
0
def annotate(query, lang, formatquery):
    if lang == 'guess':
        pass

    ann = annotators.get(lang)

    if formatquery:
        # TODO: fix me?
        query = ann.format(query, formatoptions().reindent().keywordcase())

    annotations = ann.annotate(query)
    # TODO: verify annotations start/end are inside query

    if not ann.docs:
        raise errors.NoDocsError()

    return html.wrap(query, annotations), ann.docs
Example #13
0
def annotate(query, lang, formatquery):
    if lang == 'guess':
        pass

    ann = annotators.get(lang)

    if formatquery:
        # TODO: fix me?
        query = ann.format(query, formatoptions().reindent().keywordcase())

    annotations = ann.annotate(query)
    # TODO: verify annotations start/end are inside query

    if not ann.docs:
        raise errors.NoDocsError()

    return html.wrap(query, annotations), ann.docs
Example #14
0
def testpage():
    query = '''\
SELECT p.Name AS ProductName
       NonDiscountSales = (OrderQty * UnitPrice),
       Discounts = ((OrderQty * UnitPrice) * UnitPriceDiscount)
FROM Production.Product AS p
INNER JOIN Sales.SalesOrderDetail AS sod ON p.ProductID = sod.ProductID
ORDER BY ProductName DESC;

this is a very very very very very very very very very very very very very very very very very very very very very long line'''

    a = []
    a.append(Annotation(0, query.index('FROM'), 'select', [structs.decorate.BLOCK]))
    a.append(Annotation(query.index('FROM'), query.index('INNER'), 'from', [structs.decorate.BLOCK]))
    a.append(Annotation(query.index('INNER'), query.index('ORDER'), 'inner', [structs.decorate.BLOCK]))
    a.append(Annotation(
        query.index('ORDER'), len(query), 'order', [structs.decorate.BLOCK]))
    a.append(Annotation(query.index('tName'), query.index('= (Ord') + 5, 'foo', [structs.decorate.UNDER]))

    x = 'n.Prod'
    a.append(Annotation(
        query.index(x), query.index(x) + 9, 'foo', [structs.decorate.UNDER]))
    a.append(Annotation(0, 4, 'bar', [structs.decorate.UNDER]))
    a.append(Annotation(2, 6, 'baz', [structs.decorate.UNDER]))
    a.append(Annotation(
        query.index('.Name'), query.index(
            'AS') + 2, 'foobar', [structs.decorate.BACK]))
    a.append(Annotation(
        query.index('Product'), query.index(
            'tName') + 4, 'foobar', [structs.decorate.BACK]))
    a.append(Annotation(
        query.index('((Or'), query.index(
            '((Or') + 9, 'foobar', [structs.decorate.BACK]))
    a.append(Annotation(
        query.index('ct AS p'), query.index(
            'AS sod') + 5, 'convex', [structs.decorate.UNDER]))

    query = html.wrap(query, a)

    testpage = docs.readone(os.path.join(config.ROOT, 'tests', 'testpage.html'))

    return render_template(
        'query.html',
        query=markupsafe.Markup(query),
        docs=[('testpage.html', markupsafe.Markup(testpage))])
Example #15
0
 def test_wrap(self):
     s = '012345'
     a = Ann(0, len(s), 'g', ['c'])
     self.check(
         html.wrap(s, [a]),
         '{a}012345</span>'.format(a=a.format()))
Example #16
0
 def test_wrap(self):
     s = '012345'
     a = Ann(0, len(s), 'g', ['c'])
     self.check(html.wrap(s, [a]), '{a}012345</span>'.format(a=a.format()))