From 983627daa4f64a59cf6e864df3f8df22b9f6e1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20V=C3=A9zina?= Date: Mon, 14 Mar 2016 15:02:40 -0400 Subject: [PATCH 1/4] Improve PEP8 test_html.py --- gluon/tests/test_html.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/gluon/tests/test_html.py b/gluon/tests/test_html.py index d426ea9c..bb3c24d0 100644 --- a/gluon/tests/test_html.py +++ b/gluon/tests/test_html.py @@ -264,8 +264,8 @@ class TestBareHelpers(unittest.TestCase): def testTHEAD(self): self.assertEqual(THEAD('<>', _a='1', _b='2').xml(), '<>') - #self.assertEqual(THEAD(TRHEAD('<>'), _a='1', _b='2').xml(), - # '<>') + # self.assertEqual(THEAD(TRHEAD('<>'), _a='1', _b='2').xml(), + # '<>') self.assertEqual(THEAD(TR('<>'), _a='1', _b='2').xml(), '<>') @@ -288,10 +288,10 @@ class TestBareHelpers(unittest.TestCase): def testXML(self): # sanitization process self.assertEqual(XML('

HelloWorld

').xml(), - '

HelloWorld

') + '

HelloWorld

') # with sanitize, data-attributes are not permitted self.assertEqual(XML('

HelloWorld

', sanitize=True).xml(), - '

HelloWorld

') + '

HelloWorld

') # stringify by default self.assertEqual(XML(1.3), '1.3') self.assertEqual(XML(u'
è
').xml(), '
\xc3\xa8
') @@ -307,17 +307,17 @@ class TestBareHelpers(unittest.TestCase): self.assertEqual(XML('a') == XML('a'), True) # beware that the comparison is made on the XML repr self.assertEqual(XML('

HelloWorld

', sanitize=True), - XML('

HelloWorld

')) - #bug check for the sanitizer for closing no-close tags + XML('

HelloWorld

')) + # bug check for the sanitizer for closing no-close tags self.assertEqual(XML('

Test


Test


', sanitize=True), - XML('

Test


Test


')) + XML('

Test


Test


')) def testTAG(self): self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(), - 'test') + 'test') # ending in underscore "triggers" style self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(), - '') + '') def testStaticURL(self): # test response.static_version coupled with response.static_version_urls @@ -343,14 +343,17 @@ class TestBareHelpers(unittest.TestCase): request.controller = 'c' request.function = 'f' request.env = {} - from globals import current + + from globals import current # TODO: Check if this import can go at the top of the file with other imports current.request = request + must_return = '/a/c/f' self.assertEqual(URL(), must_return) self.assertEqual(URL('f'), must_return) self.assertEqual(URL('c', 'f'), must_return) self.assertEqual(URL('a', 'c', 'f'), must_return) self.assertEqual(URL('a', 'c', 'f', extension='json'), '/a/c/f.json') + def weird(): pass self.assertEqual(URL('a', 'c', weird), '/a/c/weird') @@ -372,15 +375,15 @@ class TestBareHelpers(unittest.TestCase): current.session = Storage(auth=Storage(hmac_key='key')) self.assertEqual(URL(user_signature=True), '/a/c/f?_signature=c4aed53c08cff08f369dbf8b5ba51889430cf2c2') # hash_vars combination - rtn = URL('a','c','f', args=['x', 'y', 'z'], vars={'p' : (1,3), 'q' : 2}, hmac_key='key') + rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key') self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f') - rtn = URL('a','c','f', args=['x', 'y', 'z'], vars={'p' : (1,3), 'q' : 2}, hmac_key='key', hash_vars=True) + rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars=True) self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f') - rtn = URL('a','c','f', args=['x', 'y', 'z'], vars={'p' : (1,3), 'q' : 2}, hmac_key='key', hash_vars=False) + rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars=False) self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=0b5a0702039992aad23c82794b8496e5dcd59a5b') - rtn = URL('a','c','f', args=['x', 'y', 'z'], vars={'p' : (1,3), 'q' : 2}, hmac_key='key', hash_vars=['p']) + rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars=['p']) self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=5d01b982fd72b39674b012e0288071034e156d7a') - rtn = URL('a','c','f', args=['x', 'y', 'z'], vars={'p' : (1,3), 'q' : 2}, hmac_key='key', hash_vars='p') + rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars='p') self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=5d01b982fd72b39674b012e0288071034e156d7a') # test CRLF detection self.assertRaises(SyntaxError, URL, *['a\n', 'c', 'f']) @@ -434,7 +437,7 @@ class TestData(unittest.TestCase): def testAdata(self): self.assertEqual(A('<>', data=dict(abc='', cde='standard'), _a='1', _b='2').xml(), - '<>') + '<>') if __name__ == '__main__': From 55994c489bc8e078a9182dbd3c1cdb3b8899bf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20V=C3=A9zina?= Date: Mon, 14 Mar 2016 15:09:33 -0400 Subject: [PATCH 2/4] Improve test naming convention test_ --- gluon/tests/test_html.py | 104 +++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/gluon/tests/test_html.py b/gluon/tests/test_html.py index bb3c24d0..f1844f24 100644 --- a/gluon/tests/test_html.py +++ b/gluon/tests/test_html.py @@ -17,33 +17,33 @@ from storage import Storage class TestBareHelpers(unittest.TestCase): - def testBR(self): + def test_BR(self): self.assertEqual(BR(_a='1', _b='2').xml(), '
') - def testEMBED(self): + def test_EMBED(self): self.assertEqual(EMBED(_a='1', _b='2').xml(), '') - def testHR(self): + def test_HR(self): self.assertEqual(HR(_a='1', _b='2').xml(), '
') - def testIMG(self): + def test_IMG(self): self.assertEqual(IMG(_a='1', _b='2').xml(), '') - def testINPUT(self): + def test_INPUT(self): self.assertEqual(INPUT(_a='1', _b='2').xml(), '') - def testLINK(self): + def test_LINK(self): self.assertEqual(LINK(_a='1', _b='2').xml(), '') - def testMETA(self): + def test_META(self): self.assertEqual(META(_a='1', _b='2').xml(), '') - def testA(self): + def test_A(self): self.assertEqual( A('<>', _a='1', _b='2').xml(), '<>' @@ -89,19 +89,19 @@ class TestBareHelpers(unittest.TestCase): 'a' ) - def testB(self): + def test_B(self): self.assertEqual(B('<>', _a='1', _b='2').xml(), '<>') - def testBODY(self): + def test_BODY(self): self.assertEqual(BODY('<>', _a='1', _b='2').xml(), '<>') - def testCENTER(self): + def test_CENTER(self): self.assertEqual(CENTER('<>', _a='1', _b='2').xml(), '
<>
') - def testDIV(self): + def test_DIV(self): self.assertEqual(DIV('<>', _a='1', _b='2').xml(), '
<>
') # attributes can be updated like in a dict @@ -127,87 +127,87 @@ class TestBareHelpers(unittest.TestCase): self.assertEqual(s.sibling().xml(), '
b
') self.assertEqual(s.siblings('a'), []) - def testEM(self): + def test_EM(self): self.assertEqual(EM('<>', _a='1', _b='2').xml(), '<>') - def testFIELDSET(self): + def test_FIELDSET(self): self.assertEqual(FIELDSET('<>', _a='1', _b='2').xml(), '
<>
') - def testFORM(self): + def test_FORM(self): self.assertEqual(FORM('<>', _a='1', _b='2').xml(), '
<>
') - def testH1(self): + def test_H1(self): self.assertEqual(H1('<>', _a='1', _b='2').xml(), '

<>

') - def testH2(self): + def test_H2(self): self.assertEqual(H2('<>', _a='1', _b='2').xml(), '

<>

') - def testH3(self): + def test_H3(self): self.assertEqual(H3('<>', _a='1', _b='2').xml(), '

<>

') - def testH4(self): + def test_H4(self): self.assertEqual(H4('<>', _a='1', _b='2').xml(), '

<>

') - def testH5(self): + def test_H5(self): self.assertEqual(H5('<>', _a='1', _b='2').xml(), '
<>
') - def testH6(self): + def test_H6(self): self.assertEqual(H6('<>', _a='1', _b='2').xml(), '
<>
') - def testHEAD(self): + def test_HEAD(self): self.assertEqual(HEAD('<>', _a='1', _b='2').xml(), '<>') - def testHTML(self): + def test_HTML(self): self.assertEqual(HTML('<>', _a='1', _b='2').xml(), '\n<>') - def testIFRAME(self): + def test_IFRAME(self): self.assertEqual(IFRAME('<>', _a='1', _b='2').xml(), '') - def testLABEL(self): + def test_LABEL(self): self.assertEqual(LABEL('<>', _a='1', _b='2').xml(), '') - def testLI(self): + def test_LI(self): self.assertEqual(LI('<>', _a='1', _b='2').xml(), '
  • <>
  • ') - def testOBJECT(self): + def test_OBJECT(self): self.assertEqual(OBJECT('<>', _a='1', _b='2').xml(), '<>') - def testOL(self): + def test_OL(self): self.assertEqual(OL('<>', _a='1', _b='2').xml(), '
    1. <>
    ') - def testOPTION(self): + def test_OPTION(self): self.assertEqual(OPTION('<>', _a='1', _b='2').xml(), '') - def testP(self): + def test_P(self): self.assertEqual(P('<>', _a='1', _b='2').xml(), '

    <>

    ') # test cr2br self.assertEqual(P('a\nb').xml(), '

    a\nb

    ') self.assertEqual(P('a\nb', cr2br=True).xml(), '

    a
    b

    ') - def testPRE(self): + def test_PRE(self): self.assertEqual(PRE('<>', _a='1', _b='2').xml(), '
    <>
    ') - def testSCRIPT(self): + def test_SCRIPT(self): self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(), '''''') self.assertEqual(SCRIPT().xml(), '') - def testSELECT(self): + def test_SELECT(self): self.assertEqual(SELECT('<>', _a='1', _b='2').xml(), '') - def testSPAN(self): + def test_SPAN(self): self.assertEqual(SPAN('<>', _a='1', _b='2').xml(), '<>') - def testSTYLE(self): + def test_STYLE(self): self.assertEqual(STYLE('<>', _a='1', _b='2').xml(), '') - def testTABLE(self): + def test_TABLE(self): self.assertEqual(TABLE('<>', _a='1', _b='2').xml(), '' + '
    <>
    ') - def testTBODY(self): + def test_TBODY(self): self.assertEqual(TBODY('<>', _a='1', _b='2').xml(), '<>') - def testTD(self): + def test_TD(self): self.assertEqual(TD('<>', _a='1', _b='2').xml(), '<>') - def testTEXTAREA(self): + def test_TEXTAREA(self): self.assertEqual(TEXTAREA('<>', _a='1', _b='2').xml(), '') @@ -253,15 +253,15 @@ class TestBareHelpers(unittest.TestCase): '') - def testTFOOT(self): + def test_TFOOT(self): self.assertEqual(TFOOT('<>', _a='1', _b='2').xml(), '<>') - def testTH(self): + def test_TH(self): self.assertEqual(TH('<>', _a='1', _b='2').xml(), '<>') - def testTHEAD(self): + def test_THEAD(self): self.assertEqual(THEAD('<>', _a='1', _b='2').xml(), '<>') # self.assertEqual(THEAD(TRHEAD('<>'), _a='1', _b='2').xml(), @@ -269,23 +269,23 @@ class TestBareHelpers(unittest.TestCase): self.assertEqual(THEAD(TR('<>'), _a='1', _b='2').xml(), '<>') - def testTITLE(self): + def test_TITLE(self): self.assertEqual(TITLE('<>', _a='1', _b='2').xml(), '<>') - def testTR(self): + def test_TR(self): self.assertEqual(TR('<>', _a='1', _b='2').xml(), '<>') - def testTT(self): + def test_TT(self): self.assertEqual(TT('<>', _a='1', _b='2').xml(), '<>') - def testUL(self): + def test_UL(self): self.assertEqual(UL('<>', _a='1', _b='2').xml(), '
    • <>
    ') - def testXML(self): + def test_XML(self): # sanitization process self.assertEqual(XML('

    HelloWorld

    ').xml(), '

    HelloWorld

    ') @@ -312,14 +312,14 @@ class TestBareHelpers(unittest.TestCase): self.assertEqual(XML('

    Test


    Test


    ', sanitize=True), XML('

    Test


    Test


    ')) - def testTAG(self): + def test_TAG(self): self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(), 'test') # ending in underscore "triggers" style self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(), '') - def testStaticURL(self): + def test_StaticURL(self): # test response.static_version coupled with response.static_version_urls self.assertEqual(URL('a', 'c', 'f'), '/a/c/f') self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css') @@ -331,7 +331,7 @@ class TestBareHelpers(unittest.TestCase): response.static_version_urls = True self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/_1.2.3/design.css') - def testURL(self): + def test_URL(self): self.assertEqual(URL('a', 'c', 'f', args='1'), '/a/c/f/1') self.assertEqual(URL('a', 'c', 'f', args=('1', '2')), '/a/c/f/1/2') self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2') @@ -389,7 +389,7 @@ class TestBareHelpers(unittest.TestCase): self.assertRaises(SyntaxError, URL, *['a\n', 'c', 'f']) self.assertRaises(SyntaxError, URL, *['a\r', 'c', 'f']) - def testverifyURL(self): + def test_verifyURL(self): r = Storage() r.application = 'a' r.controller = 'c' @@ -435,7 +435,7 @@ class TestBareHelpers(unittest.TestCase): class TestData(unittest.TestCase): - def testAdata(self): + def test_Adata(self): self.assertEqual(A('<>', data=dict(abc='', cde='standard'), _a='1', _b='2').xml(), '<>') From 83a3149849a447d93e966d27dbcad8c6102f9ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20V=C3=A9zina?= Date: Tue, 15 Mar 2016 12:40:13 -0400 Subject: [PATCH 3/4] Order tests in test_html.py todo for missing test + add many missing tests --- gluon/tests/test_html.py | 681 ++++++++++++++++++++++----------------- 1 file changed, 378 insertions(+), 303 deletions(-) diff --git a/gluon/tests/test_html.py b/gluon/tests/test_html.py index f1844f24..1bcd755d 100644 --- a/gluon/tests/test_html.py +++ b/gluon/tests/test_html.py @@ -17,307 +17,10 @@ from storage import Storage class TestBareHelpers(unittest.TestCase): - def test_BR(self): - self.assertEqual(BR(_a='1', _b='2').xml(), '
    ') - - def test_EMBED(self): - self.assertEqual(EMBED(_a='1', _b='2').xml(), - '') - - def test_HR(self): - self.assertEqual(HR(_a='1', _b='2').xml(), '
    ') - - def test_IMG(self): - self.assertEqual(IMG(_a='1', _b='2').xml(), - '') - - def test_INPUT(self): - self.assertEqual(INPUT(_a='1', _b='2').xml(), - '') - - def test_LINK(self): - self.assertEqual(LINK(_a='1', _b='2').xml(), - '') - - def test_META(self): - self.assertEqual(META(_a='1', _b='2').xml(), - '') - - def test_A(self): - self.assertEqual( - A('<>', _a='1', _b='2').xml(), - '<>' - ) - self.assertEqual( - A('a', cid='b').xml(), - 'a' - ) - self.assertEqual( - A('a', callback='b', _id='c').xml(), - 'a' - ) - self.assertEqual( - A('a', delete='tr').xml(), - 'a' - ) - self.assertEqual( - A('a', _id='b', target='').xml(), - 'a' - ) - self.assertEqual( - A('a', component='b').xml(), - 'a' - ) - self.assertEqual( - A('a', _id='b', callback='c', noconfirm=True).xml(), - 'a' - ) - self.assertEqual( - A('a', cid='b').xml(), - 'a' - ) - self.assertEqual( - A('a', cid='b', _disable_with='processing...').xml(), - 'a' - ) - self.assertEqual( - A('a', callback='b', delete='tr', noconfirm=True, _id='c').xml(), - 'a' - ) - self.assertEqual( - A('a', callback='b', delete='tr', confirm='Are you sure?', _id='c').xml(), - 'a' - ) - - def test_B(self): - self.assertEqual(B('<>', _a='1', _b='2').xml(), - '<>') - - def test_BODY(self): - self.assertEqual(BODY('<>', _a='1', _b='2').xml(), - '<>') - - def test_CENTER(self): - self.assertEqual(CENTER('<>', _a='1', _b='2').xml(), - '
    <>
    ') - - def test_DIV(self): - self.assertEqual(DIV('<>', _a='1', _b='2').xml(), - '
    <>
    ') - # attributes can be updated like in a dict - div = DIV('<>', _a='1') - div['_b'] = '2' - self.assertEqual(div.xml(), - '
    <>
    ') - # also with a mapping - div.update(_b=2, _c=3) - self.assertEqual(div.xml(), - '
    <>
    ') - # length of the DIV is the number of components - self.assertEqual(len(DIV('a', 'bc')), 2) - # also if empty, DIV is True in a boolean evaluation - self.assertTrue(True if DIV() else False) - # parent and siblings - a = DIV(SPAN('a'), DIV('b')) - s = a.element('span') - d = s.parent - d['_class'] = 'abc' - self.assertEqual(a.xml(), '
    a
    b
    ') - self.assertEqual([el.xml() for el in s.siblings()], ['
    b
    ']) - self.assertEqual(s.sibling().xml(), '
    b
    ') - self.assertEqual(s.siblings('a'), []) - - def test_EM(self): - self.assertEqual(EM('<>', _a='1', _b='2').xml(), - '<>') - - def test_FIELDSET(self): - self.assertEqual(FIELDSET('<>', _a='1', _b='2').xml(), - '
    <>
    ') - - def test_FORM(self): - self.assertEqual(FORM('<>', _a='1', _b='2').xml(), - '
    <>
    ') - - def test_H1(self): - self.assertEqual(H1('<>', _a='1', _b='2').xml(), - '

    <>

    ') - - def test_H2(self): - self.assertEqual(H2('<>', _a='1', _b='2').xml(), - '

    <>

    ') - - def test_H3(self): - self.assertEqual(H3('<>', _a='1', _b='2').xml(), - '

    <>

    ') - - def test_H4(self): - self.assertEqual(H4('<>', _a='1', _b='2').xml(), - '

    <>

    ') - - def test_H5(self): - self.assertEqual(H5('<>', _a='1', _b='2').xml(), - '
    <>
    ') - - def test_H6(self): - self.assertEqual(H6('<>', _a='1', _b='2').xml(), - '
    <>
    ') - - def test_HEAD(self): - self.assertEqual(HEAD('<>', _a='1', _b='2').xml(), - '<>') - - def test_HTML(self): - self.assertEqual(HTML('<>', _a='1', _b='2').xml(), - '\n<>') - - def test_IFRAME(self): - self.assertEqual(IFRAME('<>', _a='1', _b='2').xml(), - '') - - def test_LABEL(self): - self.assertEqual(LABEL('<>', _a='1', _b='2').xml(), - '') - - def test_LI(self): - self.assertEqual(LI('<>', _a='1', _b='2').xml(), - '
  • <>
  • ') - - def test_OBJECT(self): - self.assertEqual(OBJECT('<>', _a='1', _b='2').xml(), - '<>') - - def test_OL(self): - self.assertEqual(OL('<>', _a='1', _b='2').xml(), - '
    1. <>
    ') - - def test_OPTION(self): - self.assertEqual(OPTION('<>', _a='1', _b='2').xml(), - '') - - def test_P(self): - self.assertEqual(P('<>', _a='1', _b='2').xml(), - '

    <>

    ') - # test cr2br - self.assertEqual(P('a\nb').xml(), '

    a\nb

    ') - self.assertEqual(P('a\nb', cr2br=True).xml(), '

    a
    b

    ') - - def test_PRE(self): - self.assertEqual(PRE('<>', _a='1', _b='2').xml(), - '
    <>
    ') - - def test_SCRIPT(self): - self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(), - '''''') - self.assertEqual(SCRIPT('<>').xml(), - '''''') - self.assertEqual(SCRIPT().xml(), '') - - def test_SELECT(self): - self.assertEqual(SELECT('<>', _a='1', _b='2').xml(), - '') - - def test_SPAN(self): - self.assertEqual(SPAN('<>', _a='1', _b='2').xml(), - '<>') - - def test_STYLE(self): - self.assertEqual(STYLE('<>', _a='1', _b='2').xml(), - '') - - def test_TABLE(self): - self.assertEqual(TABLE('<>', _a='1', _b='2').xml(), - '' + - '
    <>
    ') - - def test_TBODY(self): - self.assertEqual(TBODY('<>', _a='1', _b='2').xml(), - '<>') - - def test_TD(self): - self.assertEqual(TD('<>', _a='1', _b='2').xml(), - '<>') - - def test_TEXTAREA(self): - self.assertEqual(TEXTAREA('<>', _a='1', _b='2').xml(), - '') - # override _rows and _cols - self.assertEqual(TEXTAREA('<>', _a='1', _b='2', _rows=5, _cols=20).xml(), - '') - - def test_TFOOT(self): - self.assertEqual(TFOOT('<>', _a='1', _b='2').xml(), - '<>') - - def test_TH(self): - self.assertEqual(TH('<>', _a='1', _b='2').xml(), - '<>') - - def test_THEAD(self): - self.assertEqual(THEAD('<>', _a='1', _b='2').xml(), - '<>') - # self.assertEqual(THEAD(TRHEAD('<>'), _a='1', _b='2').xml(), - # '<>') - self.assertEqual(THEAD(TR('<>'), _a='1', _b='2').xml(), - '<>') - - def test_TITLE(self): - self.assertEqual(TITLE('<>', _a='1', _b='2').xml(), - '<>') - - def test_TR(self): - self.assertEqual(TR('<>', _a='1', _b='2').xml(), - '<>') - - def test_TT(self): - self.assertEqual(TT('<>', _a='1', _b='2').xml(), - '<>') - - def test_UL(self): - self.assertEqual(UL('<>', _a='1', _b='2').xml(), - '
    • <>
    ') - - def test_XML(self): - # sanitization process - self.assertEqual(XML('

    HelloWorld

    ').xml(), - '

    HelloWorld

    ') - # with sanitize, data-attributes are not permitted - self.assertEqual(XML('

    HelloWorld

    ', sanitize=True).xml(), - '

    HelloWorld

    ') - # stringify by default - self.assertEqual(XML(1.3), '1.3') - self.assertEqual(XML(u'
    è
    ').xml(), '
    \xc3\xa8
    ') - # you can calc len on the class, that equals the xml() and the str() - self.assertEqual(len(XML('1.3')), len('1.3')) - self.assertEqual(len(XML('1.3').xml()), len('1.3')) - self.assertEqual(len(str(XML('1.3'))), len('1.3')) - # you can concatenate them to strings (check for __add__ and __radd__ methods) - self.assertEqual(XML('a') + 'b', 'ab') - self.assertEqual(XML('a') + XML('b'), 'ab') - self.assertEqual('a' + XML('b'), 'ab') - # you can compare them - self.assertEqual(XML('a') == XML('a'), True) - # beware that the comparison is made on the XML repr - self.assertEqual(XML('

    HelloWorld

    ', sanitize=True), - XML('

    HelloWorld

    ')) - # bug check for the sanitizer for closing no-close tags - self.assertEqual(XML('

    Test


    Test


    ', sanitize=True), - XML('

    Test


    Test


    ')) - - def test_TAG(self): - self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(), - 'test') - # ending in underscore "triggers" style - self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(), - '') + # TODO: def test_xmlescape(self): + # TODO: def test_call_as_list(self): + # TODO: def test_truncate_string(self): + # TODO: def test_truncate_string(self): def test_StaticURL(self): # test response.static_version coupled with response.static_version_urls @@ -331,20 +34,21 @@ class TestBareHelpers(unittest.TestCase): response.static_version_urls = True self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/_1.2.3/design.css') - def test_URL(self): + def testURL(self): self.assertEqual(URL('a', 'c', 'f', args='1'), '/a/c/f/1') self.assertEqual(URL('a', 'c', 'f', args=('1', '2')), '/a/c/f/1/2') self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2') self.assertEqual(URL('a', 'c', '/f'), '/a/c/f') self.assertEqual(URL('a', 'c', 'f.json'), '/a/c/f.json') self.assertRaises(SyntaxError, URL, *['a']) + request = Storage() request.application = 'a' request.controller = 'c' request.function = 'f' request.env = {} - from globals import current # TODO: Check if this import can go at the top of the file with other imports + from globals import current # Can't be moved with other import current.request = request must_return = '/a/c/f' @@ -432,6 +136,377 @@ class TestBareHelpers(unittest.TestCase): rtn = verifyURL(r, user_signature=True) self.assertEqual(rtn, True) + # TODO: def test_XmlComponent(self): + + def test_XML(self): + # sanitization process + self.assertEqual(XML('

    HelloWorld

    ').xml(), + '

    HelloWorld

    ') + # with sanitize, data-attributes are not permitted + self.assertEqual(XML('

    HelloWorld

    ', sanitize=True).xml(), + '

    HelloWorld

    ') + # stringify by default + self.assertEqual(XML(1.3), '1.3') + self.assertEqual(XML(u'
    è
    ').xml(), '
    \xc3\xa8
    ') + # you can calc len on the class, that equals the xml() and the str() + self.assertEqual(len(XML('1.3')), len('1.3')) + self.assertEqual(len(XML('1.3').xml()), len('1.3')) + self.assertEqual(len(str(XML('1.3'))), len('1.3')) + # you can concatenate them to strings (check for __add__ and __radd__ methods) + self.assertEqual(XML('a') + 'b', 'ab') + self.assertEqual(XML('a') + XML('b'), 'ab') + self.assertEqual('a' + XML('b'), 'ab') + # you can compare them + self.assertEqual(XML('a') == XML('a'), True) + # beware that the comparison is made on the XML repr + self.assertEqual(XML('

    HelloWorld

    ', sanitize=True), + XML('

    HelloWorld

    ')) + # bug check for the sanitizer for closing no-close tags + self.assertEqual(XML('

    Test


    Test


    ', sanitize=True), + XML('

    Test


    Test


    ')) + + # TODO: def test_XML_unpickle(self): + + # TODO: def test_XML_pickle(self): + + def test_DIV(self): + # Empty DIV() + self.assertEqual(DIV().xml(), '
    ') + self.assertEqual(DIV('<>', _a='1', _b='2').xml(), + '
    <>
    ') + # attributes can be updated like in a dict + div = DIV('<>', _a='1') + div['_b'] = '2' + self.assertEqual(div.xml(), + '
    <>
    ') + # also with a mapping + div.update(_b=2, _c=3) + self.assertEqual(div.xml(), + '
    <>
    ') + # length of the DIV is the number of components + self.assertEqual(len(DIV('a', 'bc')), 2) + # also if empty, DIV is True in a boolean evaluation + self.assertTrue(True if DIV() else False) + # parent and siblings + a = DIV(SPAN('a'), DIV('b')) + s = a.element('span') + d = s.parent + d['_class'] = 'abc' + self.assertEqual(a.xml(), '
    a
    b
    ') + self.assertEqual([el.xml() for el in s.siblings()], ['
    b
    ']) + self.assertEqual(s.sibling().xml(), '
    b
    ') + self.assertEqual(s.siblings('a'), []) + + def test_CAT(self): + # Empty CAT() + self.assertEqual(CAT().xml(), '') + # CAT('') + self.assertEqual(CAT('').xml(), '') + # CAT(' ') + self.assertEqual(CAT(' ').xml(), ' ') + + # TODO: def test_TAG_unpickler(self): + + # TODO: def test_TAG_pickler(self): + + def test_TAG(self): + self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(), + 'test') + # ending in underscore "triggers" style + self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(), + '') + + def test_HTML(self): + self.assertEqual(HTML('<>', _a='1', _b='2').xml(), + '\n<>') + + # TODO: def test_XHTML(self): + + def test_HEAD(self): + self.assertEqual(HEAD('<>', _a='1', _b='2').xml(), + '<>') + + def test_TITLE(self): + self.assertEqual(TITLE('<>', _a='1', _b='2').xml(), + '<>') + + def test_META(self): + self.assertEqual(META(_a='1', _b='2').xml(), + '') + + def test_LINK(self): + self.assertEqual(LINK(_a='1', _b='2').xml(), + '') + + def test_SCRIPT(self): + self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(), + '''''') + self.assertEqual(SCRIPT('<>').xml(), + '''''') + self.assertEqual(SCRIPT().xml(), '') + + def test_STYLE(self): + self.assertEqual(STYLE('<>', _a='1', _b='2').xml(), + '') + + def test_IMG(self): + self.assertEqual(IMG(_a='1', _b='2').xml(), + '') + + def test_SPAN(self): + self.assertEqual(SPAN('<>', _a='1', _b='2').xml(), + '<>') + + def test_BODY(self): + self.assertEqual(BODY('<>', _a='1', _b='2').xml(), + '<>') + + def test_H1(self): + self.assertEqual(H1('<>', _a='1', _b='2').xml(), + '

    <>

    ') + + def test_H2(self): + self.assertEqual(H2('<>', _a='1', _b='2').xml(), + '

    <>

    ') + + def test_H3(self): + self.assertEqual(H3('<>', _a='1', _b='2').xml(), + '

    <>

    ') + + def test_H4(self): + self.assertEqual(H4('<>', _a='1', _b='2').xml(), + '

    <>

    ') + + def test_H5(self): + self.assertEqual(H5('<>', _a='1', _b='2').xml(), + '
    <>
    ') + + def test_H6(self): + self.assertEqual(H6('<>', _a='1', _b='2').xml(), + '
    <>
    ') + + def test_P(self): + self.assertEqual(P('<>', _a='1', _b='2').xml(), + '

    <>

    ') + # test cr2br + self.assertEqual(P('a\nb').xml(), '

    a\nb

    ') + self.assertEqual(P('a\nb', cr2br=True).xml(), '

    a
    b

    ') + + def test_STRONG(self): + self.assertEqual(STRONG('<>', _a='1', _b='2').xml(), + '<>') + + def test_B(self): + self.assertEqual(B('<>', _a='1', _b='2').xml(), + '<>') + + def test_BR(self): + # empty BR() + self.assertEqual(BR().xml(), '
    ') + self.assertEqual(BR(_a='1', _b='2').xml(), '
    ') + + def test_HR(self): + self.assertEqual(HR(_a='1', _b='2').xml(), '
    ') + + def test_A(self): + self.assertEqual( + A('<>', _a='1', _b='2').xml(), + '<>' + ) + self.assertEqual( + A('a', cid='b').xml(), + 'a' + ) + self.assertEqual( + A('a', callback='b', _id='c').xml(), + 'a' + ) + self.assertEqual( + A('a', delete='tr').xml(), + 'a' + ) + self.assertEqual( + A('a', _id='b', target='').xml(), + 'a' + ) + self.assertEqual( + A('a', component='b').xml(), + 'a' + ) + self.assertEqual( + A('a', _id='b', callback='c', noconfirm=True).xml(), + 'a' + ) + self.assertEqual( + A('a', cid='b').xml(), + 'a' + ) + self.assertEqual( + A('a', cid='b', _disable_with='processing...').xml(), + 'a' + ) + self.assertEqual( + A('a', callback='b', delete='tr', noconfirm=True, _id='c').xml(), + 'a' + ) + self.assertEqual( + A('a', callback='b', delete='tr', confirm='Are you sure?', _id='c').xml(), + 'a' + ) + + def test_BUTTON(self): + self.assertEqual(BUTTON('test', _type='button').xml(), + '') + + def test_EM(self): + self.assertEqual(EM('<>', _a='1', _b='2').xml(), + '<>') + + def test_EMBED(self): + self.assertEqual(EMBED(_a='1', _b='2').xml(), + '') + + def test_TT(self): + self.assertEqual(TT('<>', _a='1', _b='2').xml(), + '<>') + + def test_PRE(self): + self.assertEqual(PRE('<>', _a='1', _b='2').xml(), + '
    <>
    ') + + def test_CENTER(self): + self.assertEqual(CENTER('<>', _a='1', _b='2').xml(), + '
    <>
    ') + + def test_CODE(self): + self.assertEqual(CODE("print 'hello world'", + language='python', + link=None, + counter=1, + styles={}, + highlight_line=None).xml(), + '
    1.
    print \'hello world\'
    ') + + def test_LABEL(self): + self.assertEqual(LABEL('<>', _a='1', _b='2').xml(), + '') + + def test_LI(self): + self.assertEqual(LI('<>', _a='1', _b='2').xml(), + '
  • <>
  • ') + + def test_UL(self): + self.assertEqual(UL('<>', _a='1', _b='2').xml(), + '
    • <>
    ') + + def test_OL(self): + self.assertEqual(OL('<>', _a='1', _b='2').xml(), + '
    1. <>
    ') + + def test_TD(self): + self.assertEqual(TD('<>', _a='1', _b='2').xml(), + '<>') + + def test_TH(self): + self.assertEqual(TH('<>', _a='1', _b='2').xml(), + '<>') + + def test_TR(self): + self.assertEqual(TR('<>', _a='1', _b='2').xml(), + '<>') + + def test_THEAD(self): + self.assertEqual(THEAD('<>', _a='1', _b='2').xml(), + '<>') + # self.assertEqual(THEAD(TRHEAD('<>'), _a='1', _b='2').xml(), + # '<>') + self.assertEqual(THEAD(TR('<>'), _a='1', _b='2').xml(), + '<>') + + def test_TBODY(self): + self.assertEqual(TBODY('<>', _a='1', _b='2').xml(), + '<>') + + def test_TFOOT(self): + self.assertEqual(TFOOT('<>', _a='1', _b='2').xml(), + '<>') + + # TODO: def test_COL(self): + + # TODO: def test_COLGROUP(self): + + def test_TABLE(self): + self.assertEqual(TABLE('<>', _a='1', _b='2').xml(), + '' + + '
    <>
    ') + + def test_I(self): + self.assertEqual(I('<>', _a='1', _b='2').xml(), + '<>') + + def test_IFRAME(self): + self.assertEqual(IFRAME('<>', _a='1', _b='2').xml(), + '') + + def test_INPUT(self): + self.assertEqual(INPUT(_a='1', _b='2').xml(), + '') + + def test_TEXTAREA(self): + self.assertEqual(TEXTAREA('<>', _a='1', _b='2').xml(), + '') + # override _rows and _cols + self.assertEqual(TEXTAREA('<>', _a='1', _b='2', _rows=5, _cols=20).xml(), + '') + + def test_OPTION(self): + self.assertEqual(OPTION('<>', _a='1', _b='2').xml(), + '') + + def test_OBJECT(self): + self.assertEqual(OBJECT('<>', _a='1', _b='2').xml(), + '<>') + + # TODO: def test_OPTGROUP(self): + + def test_SELECT(self): + self.assertEqual(SELECT('<>', _a='1', _b='2').xml(), + '') + + def test_FIELDSET(self): + self.assertEqual(FIELDSET('<>', _a='1', _b='2').xml(), + '
    <>
    ') + + # TODO: def test_LEGEND(self): + + def test_FORM(self): + self.assertEqual(FORM('<>', _a='1', _b='2').xml(), + '
    <>
    ') + + # TODO: def test_BEAUTIFY(self): + + # TODO: def test_MENU(self): + + # TODO: def test_embed64(self): + + # TODO: def test_web2pyHTMLParser(self): + + # TODO: def test_markdown_serializer(self): + + # TODO: def test_markmin_serializer(self): + + # TODO: def test_MARKMIN(self): + + # TODO: def test_ASSIGNJS(self): + class TestData(unittest.TestCase): From 6e6612a57d41f7ebec1db4411cb74e89a3b2ba70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20V=C3=A9zina?= Date: Tue, 15 Mar 2016 12:41:08 -0400 Subject: [PATCH 4/4] add a todo about remain test() which may be deleted --- gluon/html.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gluon/html.py b/gluon/html.py index b6fc7c0c..8c4be662 100644 --- a/gluon/html.py +++ b/gluon/html.py @@ -2610,6 +2610,7 @@ def embed64( return 'data:%s;base64,%s' % (extension, data) +# TODO: Check if this test() is still relevant now that we have gluon/tests/test_html.py def test(): """ Example: