예제 #1
0
def test_compound2():
    dut = Element(u'ul', u'some text', {u'class': u'some class'})
    dut.child.append(Element(u'li', u'some text', {u'class': u'some class'}))
    dut.child.append(Element(u'li', u'some text', {u'class': u'some class'}))

    expect = {
        u'tag': u'ul',
        u'text': u'some text',
        u'attr': {
            u'class': u'some class'
        },
        u'child': [
            {
                u'tag': u'li',
                u'text': u'some text',
                u'attr': {
                    u'class': u'some class'
                }
            }, {
                u'tag': u'li',
                u'text': u'some text',
                u'attr': {
                    u'class': u'some class'
                }
            }
        ]
    }

    assert dut.render() == expect
예제 #2
0
    def test_compound2(self):
        dut = Element(u'ul', u'some text', {u'class': u'some class'})
        dut.child.append(Element(u'li', u'some text', {u'class': u'some class'}))
        dut.child.append(Element(u'li', u'some text', {u'class': u'some class'}))

        expect = {
            u'tag': u'ul',
            u'text': u'some text',
            u'attr': {
                u'class': u'some class'
            },
            u'child': [
                {
                    u'tag': u'li',
                    u'text': u'some text',
                    u'attr': {
                        u'class': u'some class'
                    }
                }, {
                    u'tag': u'li',
                    u'text': u'some text',
                    u'attr': {
                        u'class': u'some class'
                    }
                }
            ]
        }

        self.assertEqual(dut.render(), expect)
예제 #3
0
    def test_tag(self):
        dut = Element(u'p')

        expect = {
            u'tag': u'p'
        }

        self.assertEqual(dut.render(), expect)
예제 #4
0
def test_tag():
    dut = Element(u'p')

    expect = {
        u'tag': u'p'
    }

    assert dut.render() == expect
예제 #5
0
    def test_text(self):
        dut = Element(u'p', u'some text')

        expect = {
            u'tag': u'p',
            u'text': u'some text'
        }

        self.assertEqual(dut.render(), expect)
예제 #6
0
def test_text():
    dut = Element(u'p', u'some text')

    expect = {
        u'tag': u'p',
        u'text': u'some text'
    }

    assert dut.render() == expect
예제 #7
0
def test_property(env, dut):

    dut.child.append(Element(u'li', u'text', {u'disable': None}))
    dut.child.append(Element(u'li', u'text', {u'disable': u''}))

    result = env.get_template(u'json2html.html').render(root=dut.render())

    expect = u'<ul class="some class">text<li disable>text</li><li disable>text</li></ul>'

    assert result == expect
예제 #8
0
def test_simple_list(env, dut):

    dut.child.append(Element(u'li', u'text', {u'class': u'some class'}))
    dut.child.append(Element(u'li', u'text', {u'class': u'some class'}))

    result = env.get_template(u'json2html.html').render(root=dut.render())

    expect = u'<ul class="some class">text<li class="some class">text</li><li class="some class">text</li></ul>'

    assert result == expect
예제 #9
0
    def test_property(self):
        dut = Element(u'ul', u'text', {u'class': u'some class'})
        dut.child.append(Element(u'li', u'text', {u'disable': None}))
        dut.child.append(Element(u'li', u'text', {u'disable': u''}))

        result = self.env.get_template(u'json2html.html').render(root=dut.render())

        expect = u'<ul class="some class">text<li disable>text</li><li disable>text</li></ul>'

        self.assertEqual(result, expect)
예제 #10
0
    def test_property(self):
        dut = Element(u'ul', u'text', {u'class': u'some class'})
        dut.child.append(Element(u'li', u'text', {u'disable': None}))
        dut.child.append(Element(u'li', u'text', {u'disable': u''}))

        result = self.env.get_template(u'json2html.html').render(
            root=dut.render())

        expect = u'<ul class="some class">text<li disable>text</li><li disable>text</li></ul>'

        self.assertEqual(result, expect)
예제 #11
0
    def test_attr(self):
        dut = Element(u'p', u'some text', {u'class': u'some class'})

        expect = {
            u'tag': u'p',
            u'text': u'some text',
            u'attr': {
                u'class': u'some class'
            }
        }

        self.assertEqual(dut.render(), expect)
예제 #12
0
def test_attr():
    dut = Element(u'p', u'some text', {u'class': u'some class'})

    expect = {
        u'tag': u'p',
        u'text': u'some text',
        u'attr': {
            u'class': u'some class'
        }
    }

    assert dut.render() == expect
예제 #13
0
    def test_attr(self):
        dut = Element(u'p', u'some text', {u'class': u'some class'})

        expect = {
            u'tag': u'p',
            u'text': u'some text',
            u'attr': {
                u'class': u'some class'
            }
        }

        self.assertEqual(dut.render(), expect)
예제 #14
0
    def test_div_with_inline_tag3(self):
        html = u''.join([
            u'<div id="1" class="foo bar">',
            u'<p>sample text with tag <strong>like</strong> this</p>',
            u'<p><strong>with</strong> inline tag</p>',
            u'</div>'
        ])

        json = {
            u'tag': u'div',
            u'attr': {
                u'id': u'1',
                u'class': [u'foo', u'bar']
            },
            u'child': [{
                u'tag': u'p',
                u'text': u'sample text with tag <strong>like</strong> this'
            }, {
                u'tag': u'p',
                u'text': u'<strong>with</strong> inline tag'
            }]
        }

        dut = Element.parse(html)

        # print dut.render()
        self.assertEqual(dut.render(), json)
예제 #15
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_with_inline_tag3(self):
        html = u''.join([
            u'<div id="1" class="foo bar">',
            u'<p>sample text with tag <strong>like</strong> this</p>',
            u'<p><strong>with</strong> inline tag</p>', u'</div>'
        ])

        json = {
            u'tag':
            u'div',
            u'attr': {
                u'id': u'1',
                u'class': [u'foo', u'bar']
            },
            u'child': [{
                u'tag':
                u'p',
                u'text':
                u'sample text with tag <strong>like</strong> this'
            }, {
                u'tag': u'p',
                u'text': u'<strong>with</strong> inline tag'
            }]
        }

        dut = Element.parse(html)

        # print dut.render()
        self.assertEqual(dut.render(), json)
예제 #16
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_tag(self):
        html = u'<div></div>'
        json = {u'tag': u'div'}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.render(), json)
예제 #17
0
def test_div_tag():
    html = u'<div></div>'
    json = {u'tag': u'div'}

    dut = Element.parse(html)

    assert dut.tag == u'div'
    assert dut.render() == json
예제 #18
0
    def test_div_tag(self):
        html = u'<div></div>'
        json = {u'tag': u'div'}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.render(), json)
예제 #19
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_text_gets_stripped(self):
        html = u'<div>this is a div   </div>'
        json = {u'tag': u'div', u'text': u'this is a div'}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.text, u'this is a div')

        self.assertEqual(dut.render(), json)
예제 #20
0
def test_div_with_child():
    html = u'<div><p></p></div>'
    json = {u'tag': u'div', u'child': [{u'tag': u'p'}]}

    dut = Element.parse(html)

    assert dut.tag == u'div'
    assert dut.child[0].tag == u'p'

    assert dut.render() == json
예제 #21
0
    def test_div_with_inline_tag2(self):
        html = u'<p>sample text with tag <strong>like</strong> this</p>'
        json = {
            u'tag': u'p',
            u'text': u'sample text with tag <strong>like</strong> this'
        }

        dut = Element.parse(html)

        self.assertEqual(dut.render(), json)
예제 #22
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_with_inline_tag1(self):
        html = u'<div>this is a <b>div</b></div>'
        json = {u'tag': u'div', u'text': u'this is a <b>div</b>'}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.text, u'this is a <b>div</b>')

        self.assertEqual(dut.render(), json)
예제 #23
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_with_child(self):
        html = u'<div><p></p></div>'
        json = {u'tag': u'div', u'child': [{u'tag': u'p'}]}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.child[0].tag, u'p')

        self.assertEqual(dut.render(), json)
예제 #24
0
def test_div_with_id():
    html = u'<div id="foo"></div>'
    json = {u'tag': u'div', u'attr': {u'id': u'foo'}}

    dut = Element.parse(html)

    assert dut.tag == u'div'
    assert dut.attr[u'id'] == u'foo'

    assert dut.render() == json
예제 #25
0
def test_text_gets_stripped():
    html = u'<div>this is a div   </div>'
    json = {u'tag': u'div', u'text': u'this is a div'}

    dut = Element.parse(html)

    assert dut.tag == u'div'
    assert dut.text == u'this is a div'

    assert dut.render() == json
예제 #26
0
def test_div_with_inline_tag1():
    html = u'<div>this is a <b>div</b></div>'
    json = {u'tag': u'div', u'text': u'this is a <b>div</b>'}

    dut = Element.parse(html)

    assert dut.tag == u'div'
    assert dut.text == u'this is a <b>div</b>'

    assert dut.render() == json
예제 #27
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_with_id(self):
        html = u'<div id="foo"></div>'
        json = {u'tag': u'div', u'attr': {u'id': u'foo'}}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.attr[u'id'], u'foo')

        self.assertEqual(dut.render(), json)
예제 #28
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_with_inline_tag2(self):
        html = u'<p>sample text with tag <strong>like</strong> this</p>'
        json = {
            u'tag': u'p',
            u'text': u'sample text with tag <strong>like</strong> this'
        }

        dut = Element.parse(html)

        self.assertEqual(dut.render(), json)
예제 #29
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_ul(self):
        html = u'<ul><li></li><li></li></ul>'
        json = {u'tag': u'ul', u'child': [{u'tag': u'li'}, {u'tag': u'li'}]}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'ul')
        self.assertEqual(dut.child[0].tag, u'li')
        self.assertEqual(dut.child[1].tag, u'li')

        self.assertEqual(dut.render(), json)
예제 #30
0
def test_ul():
    html = u'<ul><li></li><li></li></ul>'
    json = {u'tag': u'ul', u'child': [{u'tag': u'li'}, {u'tag': u'li'}]}

    dut = Element.parse(html)

    assert dut.tag == u'ul'
    assert dut.child[0].tag == u'li'
    assert dut.child[1].tag == u'li'

    assert dut.render() == json
예제 #31
0
    def test_div_with_id(self):
        html = u'<div id="foo"></div>'
        json = {
            u'tag': u'div',
            u'attr': {u'id': u'foo'}}

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.attr[u'id'], u'foo')

        self.assertEqual(dut.render(), json)
예제 #32
0
    def test_text_gets_stripped(self):
        html = u'<div>this is a div   </div>'
        json = {
            u'tag': u'div',
            u'text': u'this is a div'
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.text, u'this is a div')

        self.assertEqual(dut.render(), json)
예제 #33
0
def test_div_with_h1_child_and_text():
    html = u'<div><h1>text</h1></div>'
    json = {u'tag': u'div', u'child': [{u'tag': u'h1', 'text': 'text'}]}

    dut = Element.parse(html)

    print(dut)

    assert dut.tag == u'div'
    assert dut.child[0].tag == u'h1'
    assert dut.child[0].text == 'text'

    assert dut.render() == json
예제 #34
0
    def test_div_with_inline_tag1(self):
        html = u'<div>this is a <b>div</b></div>'
        json = {
            u'tag': u'div',
            u'text': u'this is a <b>div</b>'
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.text, u'this is a <b>div</b>')

        self.assertEqual(dut.render(), json)
예제 #35
0
    def test_compound(self):
        dut = Element(u'ul', u'some text', {u'class': u'some class'})
        dut.child.append(
            Element(u'li', u'some text', {u'class': u'some class'}))

        expect = {
            u'tag':
            u'ul',
            u'text':
            u'some text',
            u'attr': {
                u'class': u'some class'
            },
            u'child': [{
                u'tag': u'li',
                u'text': u'some text',
                u'attr': {
                    u'class': u'some class'
                }
            }]
        }

        self.assertEqual(dut.render(), expect)
예제 #36
0
    def test_div_with_child(self):
        html = u'<div><p></p></div>'
        json = {
            u'tag': u'div',
            u'child': [{
                u'tag': u'p'
            }]
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.child[0].tag, u'p')

        self.assertEqual(dut.render(), json)
예제 #37
0
def test_div_with_id_and_class():
    html = u'<div id="foo" class="bar goo"></div>'
    json = {
        u'tag': u'div',
        u'attr': {
            u'id': u'foo',
            u'class': [u'bar', u'goo']
        }
    }

    dut = Element.parse(html)

    assert dut.tag == u'div'
    assert dut.attr[u'id'] == u'foo'
    assert dut.attr[u'class'] == [u'bar', u'goo']

    assert dut.render() == json
예제 #38
0
    def test_div_with_id_and_class(self):
        html = u'<div id="foo" class="bar goo"></div>'
        json = {
            u'tag': u'div',
            u'attr': {
                u'id': u'foo',
                u'class': [u'bar', u'goo']
            }
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.attr[u'id'], u'foo')
        self.assertEqual(dut.attr[u'class'], [u'bar', u'goo'])

        self.assertEqual(dut.render(), json)
예제 #39
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_div_with_id_and_class(self):
        html = u'<div id="foo" class="bar goo"></div>'
        json = {
            u'tag': u'div',
            u'attr': {
                u'id': u'foo',
                u'class': [u'bar', u'goo']
            }
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.attr[u'id'], u'foo')
        self.assertEqual(dut.attr[u'class'], [u'bar', u'goo'])

        self.assertEqual(dut.render(), json)
예제 #40
0
def test_figure_with_newlines_and_spaces():
    html = u'<figure>\n      <img src="abc">   \n</figure>'
    json = {
        u'tag': u'figure',
        u'child': [{
            u'tag': u'img',
            u'attr': {
                u'src': u'abc'
            }
        }]
    }

    dut = Element.parse(html)

    assert dut.tag == u'figure'
    assert dut.child[0].tag == u'img'

    assert dut.render() == json
예제 #41
0
def test_figure():
    html = u'<figure><img src="abc"></figure>'
    json = {
        u'tag': u'figure',
        u'child': [{
            u'tag': u'img',
            u'attr': {
                u'src': u'abc'
            }
        }]
    }

    dut = Element.parse(html)

    assert dut.tag == u'figure'
    assert dut.child[0].tag == u'img'

    assert dut.render() == json
예제 #42
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_figure_with_newlines_and_spaces(self):
        html = u'<figure>\n      <img src="abc">   \n</figure>'
        json = {
            u'tag': u'figure',
            u'child': [{
                u'tag': u'img',
                u'attr': {
                    u'src': u'abc'
                }
            }]
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'figure')
        self.assertEqual(dut.child[0].tag, u'img')

        self.assertEqual(dut.render(), json)
예제 #43
0
파일: test_parse.py 프로젝트: rlaneyjr/lib
    def test_parse_what_the_guy_wants(self):

        json = {
            u'tag':
            u'div',
            u'attr': {
                u'id': u'1',
                u'class': [u'foo']
            },
            u'child': [{
                u'tag': u'h2',
                u'text': u'sample text with <code>inline tag</code>'
            }, {
                u'tag': u'pre',
                u'attr': {
                    u'id': u'demo',
                    u'class': [u'foo', u'bar']
                }
            }, {
                u'tag': u'pre',
                u'attr': {
                    u'id': u'output',
                    u'class': [u'goo']
                }
            }, {
                u'tag': u'input',
                u'attr': {
                    u'id': u'execute',
                    u'type': u'button',
                    u'value': u'execute'
                }
            }]
        }

        html = u''.join([
            u'<div id="1" class="foo">',
            u'<h2>sample text with <code>inline tag</code></h2>',
            u'<pre id="demo" class="foo bar"></pre>',
            u'<pre id="output" class="goo"></pre>',
            u'<input id="execute" type="button" value="execute"/>', u'</div>'
        ])

        dut = Element.parse(html)
        self.assertEqual(dut.render(), json)
예제 #44
0
    def test_parse_what_the_guy_wants(self):

        json = {
            u'tag': u'div',
            u'attr': {
                u'id': u'1',
                u'class': [u'foo']
            },
            u'child': [{
                u'tag': u'h2',
                u'text': u'sample text with <code>inline tag</code>'
            }, {
                u'tag': u'pre',
                u'attr': {
                    u'id': u'demo',
                    u'class': [u'foo', u'bar']
                }
            }, {
                u'tag': u'pre',
                u'attr': {
                    u'id': u'output',
                    u'class': [u'goo']
                }
            }, {
                u'tag': u'input',
                u'attr': {
                    u'id': u'execute',
                    u'type': u'button',
                    u'value': u'execute'
                }
            }]
        }

        html = u''.join([
            u'<div id="1" class="foo">',
            u'<h2>sample text with <code>inline tag</code></h2>',
            u'<pre id="demo" class="foo bar"></pre>',
            u'<pre id="output" class="goo"></pre>',
            u'<input id="execute" type="button" value="execute"/>',
            u'</div>'
        ])

        dut = Element.parse(html)
        self.assertEqual(dut.render(), json)
예제 #45
0
    def test_cover(self):

        with open(os.path.join(cwd, u'cover.html'), u'r') as infile:
            html = infile.read()

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'div')
        self.assertEqual(dut.child[0].tag, u'h1')
        self.assertEqual(dut.child[0].text, u'title')
        self.assertEqual(dut.child[1].tag, u'p')
        self.assertEqual(dut.child[1].text, u'content')
        self.assertEqual(dut.child[2].tag, u'figure')
        self.assertEqual(dut.child[2].child[0].tag, u'img')
        self.assertEqual(dut.child[2].child[0].attr[u'src'], u'cover.jpg')

        json = {
            u'tag': u'div',
            u'child': [
                {
                    u'tag': u'h1',
                    u'text': u'title',
                },
                {
                    u'tag': u'p',
                    u'text': u'content',
                },
                {
                    u'tag': u'figure',
                    u'child': [
                        {
                            u'tag': u'img',
                            u'attr': {
                                u'src': u'cover.jpg'
                            }
                        }
                    ]
                }
            ]
        }

        self.assertEqual(dut.render(), json)
예제 #46
0
    def test_ul(self):
        html = u'<ul><li></li><li></li></ul>'
        json = {
            u'tag': u'ul',
            u'child': [
                {
                    u'tag': u'li'
                }, {
                    u'tag': u'li'
                }
            ]
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'ul')
        self.assertEqual(dut.child[0].tag, u'li')
        self.assertEqual(dut.child[1].tag, u'li')

        self.assertEqual(dut.render(), json)
예제 #47
0
    def test_figure_with_newlines_and_spaces(self):
        html = u'<figure>\n      <img src="abc">   \n</figure>'
        json = {
            u'tag': u'figure',
            u'child': [
                {
                    u'tag': u'img',
                    u'attr': {
                        u'src': u'abc'
                    }
                }
            ]
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'figure')
        self.assertEqual(dut.child[0].tag, u'img')

        self.assertEqual(dut.render(), json)
예제 #48
0
    def test_unary(self):
        html = u''.join(
            [
                u'<div id="1" class="foo bar">',
                u'<h2>sample text</h2>',
                u'<input id="execute" type="button" value="execute"/>',
                u'<img src="photo.jpg" alt="photo"/>',
                u'</div>'
            ]
        )

        json = {
            u'tag': u'div',
            u'attr': {
                u'id': u'1',

                u'class': [u'foo', u'bar']

            },
            u'child': [{
                u'tag': u'h2',
                u'text': u'sample text'
            }, {
                u'tag': u'input',
                u'attr': {
                    u'id': u'execute',
                    u'type': u'button',
                    u'value': u'execute'
                }
            }, {
                u'tag': u'img',
                u'attr': {
                    u'src': u'photo.jpg',
                    u'alt': u'photo'
                }
            }]
        }

        dut = Element.parse(html)

        self.assertEqual(dut.render(), json)
예제 #49
0
    def test_figure_with_caption(self):
        html = u'<figure><img src="abc"><figcaption>caption</figcaption></figure>'
        json = {
            u'tag': u'figure',
            u'child': [
                {
                    u'tag': u'img',
                    u'attr': {
                        u'src': u'abc'
                    }
                }, {
                    u'tag': u'figcaption',
                    u'text': u'caption'
                }
            ]
        }

        dut = Element.parse(html)

        self.assertEqual(dut.tag, u'figure')
        self.assertEqual(dut.child[0].tag, u'img')
        self.assertEqual(dut.child[1].tag, u'figcaption')

        self.assertEqual(dut.render(), json)