def test_singledispatch(): """ singledispatch creates three things, a registry, a register and a dispatch fucntion. We have used the singledispatch from functools to create htmlizer. We will test the htmlizer is converting the code properly or not """ # for int assert session9.htmlize( 1 ) == '1(<i>0x1</i>)', 'singledispatch to htmlize is not working as expected for Integral' # for float assert session9.htmlize( 1.1 ) == '1.1', 'singledispatch to htmlize is not working as expected for float types' # for list and tuple assert session9.htmlize( (1, 2) ) == '<ul>\n<li>1(<i>0x1</i>)</li>\n<li>2(<i>0x2</i>)</li>\n</ul>', 'singledispatch to htmlize is not working as expected for list and tuple' # for Decimal a = Decimal('1.4535') assert session9.htmlize( 1.4535 ) == '1.45', 'singledispatch to htmlize is not working as expected for decimal type' # for dict assert session9.htmlize( { 'a': 1, 'b': 2 } ) == '<ul>\n<li>a=1</li>\n<li>b=2</li>\n</ul>', 'singledispatch to htmlize is not working as expected for dic types'
def test_singledispatch_html(): assert s9.htmlize(100) == '100(<i>0x64</i>)' assert s9.htmlize([3, 5]) == '<ul>\n<li>3</li>\n<li>5</li>\n</ul>' assert s9.htmlize(((2, 4), (4, 8))) == '<ul>\n<li>(2, 4)</li>\n<li>(4, 8)</li>\n</ul>' assert s9.htmlize({'x': 6, 'y': 8}) == '<ul>\n<li>x=6</li>\n<li>y=8</li>\n</ul>' assert s9.htmlize('5 < 500') == '5 < 500' assert s9.htmlize('hello, vinay\n') == 'hello, vinay<br/>\n' assert s9.htmlize(4.5632112) == '4.56' assert s9.htmlize(Decimal(6.8769)) == '6.88' assert s9.htmlize({6,8}) == '<ul>\n<li>8</li>\n<li>6</li>\n</ul>' assert s9.htmlize(frozenset((9,5))) == '<ul>\n<li>9</li>\n<li>5</li>\n</ul>'
def test_htmlize(): """ This Function Test the htmplize function for different cases """ a = htmlize(10) b = htmlize(10.0) c = htmlize([10, 20, 30]) d = htmlize((30, 40, 50)) e = htmlize({ "user1": { "password": "******", "PL": 4 }, "user2": { "password": "******", "PL": 3 }, "user3": { "password": "******", "PL": 2 }, "user4": { "password": "******", "PL": 1 } }) f = htmlize("Very Big Line") g = htmlize(Decimal(4.502)) assert a == '10', "htmplize function is not working for Integer" assert b == "10.0", "htmplize function is not working for float" assert c == "<ul>\n<li>10</li>\n<li>20</li>\n<li>30</li>\n</ul>", "htmplize function is not working for List" assert d == "<ul>\n<li>30</li>\n<li>40</li>\n<li>50</li>\n</ul>", "htmplize function is not working for Tuple" assert e == "<ul>\n<li>user1={'password': '******', 'PL': 4}</li>\n<li>user2={'password': '******', 'PL': 3}</li>\n<li>user3={'password': '******', 'PL': 2}</li>\n<li>user4={'password': '******', 'PL': 1}</li>\n</ul>", "htmplize function is not working for Dictionary" assert f == "Very Big Line", "htmplize function is not working for Str" assert g == "4.50", "htmplize function is not working for Decimal"
def test_htmlize_function_check(capsys): assert session9.htmlize(100) == "100(<i>0x64</i>)" assert session9.htmlize([1, 2, 3, 4]) == "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n<li>4</li>\n</ul>" assert session9.htmlize(((1, 2), (2, 3), (3, 4))) == "<ul>\n<li>(1, 2)</li>\n<li>(2, 3)</li>\n<li>(3, 4)</li>\n</ul>" assert session9.htmlize('1 < 100') == '1 < 100' assert session9.htmlize(10.2569) == '10.26'
def test_htmlize(): assert htmlize(100) == '100(<i>0x64</i>)', "htmlize is not working"
def test_htmlize_4(): assert session9.htmlize( ['alpha', 66, {3, 2, 1}] ) == '<ul>\n<li><p>alpha</p></li>\n<li><pre>66 (0x42)</pre></li>\n<li><pre>{1, 2, 3}</pre></li>\n</ul>', 'Your function not working'
def test_htmlize_3(): assert session9.htmlize( 42) == '<pre>42 (0x2a)</pre>', 'Your function not working'
def test_htmlize_2(): assert session9.htmlize( 'Heimlich & Co.\n- a game' ) == '<p>Heimlich & Co.<br>\n- a game</p>', 'Your function not working'
def test_htmlize_1(): assert session9.htmlize( abs ) == '<pre><built-in function abs></pre>', 'Your function not working'
def test_htmlize(): assert session9.htmlize( {1, 2, 3}) == '<pre>{1, 2, 3}</pre>', 'Your function not working'