Best Python code snippet using stestr_python
tests.py
Source:tests.py  
...34        interwiki_links_base_urls={'Ohana': inter_wiki_url},35        no_wiki_monospace=False36        )37    )38def wrap_result(expected):39    if isinstance(expected, six.text_type):40        return force_b("<p>%s</p>\n" % expected)41    else:42        raise TypeError43def force_b(s):44    if isinstance(s, six.text_type):45        return s.encode('utf-8')46    else:47        return s48class SloppyBytesTestCase(unittest.TestCase):49            50    def assertEqual(self, x, y, msg=None):51        return self.assertEquals(x, y, msg=msg)52    def assertEquals(self, x, y, msg=None):53        # Hack around the Python 2 vs 3 unicode vs bytes expectations in the test cases.54        x = force_b(x)55        y = force_b(y)56        return super(SloppyBytesTestCase, self).assertEquals(x, y, msg=msg)57    def assertEqualTag(self, x, y):58        # test cases assume unimportant things about attribute order: ignore that.59        x_words = set(force_b(x).replace(six.b('>'), six.b(' >')).split(six.b(' ')))60        y_words = set(force_b(y).replace(six.b('>'), six.b(' >')).split(six.b(' ')))61        return self.assertEquals(x_words, y_words)62        63        64class BaseTest(object):65    """66    """67    #parse = lambda x: None68    def test_newlines(self):69        self.assertEquals(70            self.parse("\na simple line"),71            wrap_result("a simple line"))72        self.assertEquals(73            self.parse("\n\na simple line\n\n"),74            wrap_result("a simple line"))75    def test_line_breaks(self):76        self.assertEquals(77            self.parse(r"break\\this"),78            wrap_result("break<br />this"))79    def test_horizontal_line(self):80        self.assertEquals(81            self.parse(r"----"),82            "<hr />\n")83    def test_raw_links(self):84        self.assertEquals(85            self.parse("http://www.google.com"),86            wrap_result("""<a href="http://www.google.com">http://www.google.com</a>"""))87        self.assertEquals(88            self.parse(r"http://www.google.com\\foo"),89            wrap_result("""<a href="http://www.google.com">http://www.google.com</a><br />foo"""))90        self.assertEquals(91            self.parse("~http://www.google.com"),92            wrap_result("""http://www.google.com"""))93        self.assertEquals(94            self.parse(r"<http://www.google.com>."),95            wrap_result("""<<a href="http://www.google.com">http://www.google.com</a>>."""))96        self.assertEquals(97            self.parse(r"(http://www.google.com) foo"),98            wrap_result("""(<a href="http://www.google.com">http://www.google.com</a>) foo"""))99        self.assertEquals(100            self.parse(r"http://www.google.com/#"),101            wrap_result("""<a href="http://www.google.com/#">http://www.google.com/#</a>"""))102        self.assertEquals(103            self.parse(r"//http://www.google.com//"),104            wrap_result("""<em><a href="http://www.google.com">http://www.google.com</a></em>"""))105        self.assertEquals(106            self.parse(r"ftp://www.google.com"),107            wrap_result("""ftp://www.google.com"""))108    def test_links(self):109        self.assertEquals(110            self.parse("[[http://www.google.com ]]"),111            wrap_result("""<a href="http://www.google.com">http://www.google.com</a>"""))112        self.assertEquals(113            self.parse("[[http://www.google.com/search\n?source=ig&hl=en&rlz=&q=creoleparser&btnG=Google+Search&aq=f]]"),114            wrap_result("""<a href="http://www.google.com/search\n?source=ig&hl=en&rlz=&q=creoleparser&btnG=Google+Search&aq=f">http://www.google.com/search\n?source=ig&hl=en&rlz=&q=creoleparser&btnG=Google+Search&aq=f</a>"""))115        self.assertEquals(116            self.parse("[[http://www.google.com|google]]"),117            wrap_result("""<a href="http://www.google.com">google</a>"""))118        #self.assertEquals(119        #    self.parse("[[http://www.google.com|google|]]"),120        #    wrap_result("""[[http://www.google.com|google|]]"""))121        self.assertEquals(122            self.parse("[[http://www.google.com|]]"),123            wrap_result("""<a href="http://www.google.com">http://www.google.com</a>"""))124        self.assertEquals(125            self.parse(u"[[α]]"),126            wrap_result("""<a href="%CE%B1">α</a>"""))127    def test_image(self):128        self.assertEqualTag(129            self.parse("{{http://www.google.com/pic.png}}"),130            wrap_result("""<img src="http://www.google.com/pic.png" alt="pic.png" title="pic.png" />"""))131        self.assertEqualTag(132            self.parse("{{http://www.google.com/pic.png|google}}"),133            wrap_result("""<img src="http://www.google.com/pic.png" alt="google" title="google" />"""))134        self.assertEqualTag(135            self.parse("{{http://www.google.com/pic.png/}}"),136            wrap_result("""<img src="http://www.google.com/pic.png/" alt="" title="" />"""))137        self.assertEqualTag(138            self.parse("{{http://www.google.com/pic.png|}}"),139            wrap_result("""<img src="http://www.google.com/pic.png" alt="" title="" />"""))140        #self.assertEquals(141        #    self.parse("{{http://www.google.com/pic.png|name|}}"),142        #    wrap_result("""{{http://www.google.com/pic.png|name|}}"""))143    def test_links_with_spaces(self):144        self.assertEquals(145            self.parse("[[This Page Here]]"),146            wrap_result("""<a href="This_Page_Here">This Page Here</a>"""))147        self.assertEquals(148            self.parse("[[New Page|this]]"),149            wrap_result("""<a href="New_Page">this</a>"""))150        self.assertEquals(151            self.parse("[[badname: Home]]"),152            wrap_result("""<a href="badname%3A_Home">badname: Home</a>"""))153    def test_interwiki_links(self):154        self.assertEquals(155            self.parse("[[Ohana:Home|This one]]"),156            wrap_result("""<a href="http://wikiohana.net/cgi-bin/wiki.pl/Home">This one</a>"""))157        self.assertEquals(158            self.parse("[[ :Home|This one]]"),159            wrap_result("""<a href="%3AHome">This one</a>"""))160        self.assertEquals(161            self.parse("[[badname:Home|This one]]"),162            wrap_result("""[[badname:Home|This one]]"""))163        164class Creole2HTMLTest(SloppyBytesTestCase, BaseTest):165    """166    """167    def setUp(self):168        creole2html = Parser(169            dialect=create_dialect(creole10_base,170                wiki_links_base_url=base_url,171                interwiki_links_base_urls={'Ohana': inter_wiki_url},172                #use_additions=False,173                no_wiki_monospace=True,174                )175            )176        self.parse = creole2html177        178    def test_links(self):179        super(Creole2HTMLTest, self).test_links()180        self.assertEquals(181            self.parse("[[http://www.google.com| <<luca Google>>]]"),182            wrap_result("""<a href="http://www.google.com"><<luca Google>></a>"""))183class Text2HTMLTest(SloppyBytesTestCase, BaseTest):184    """185    """186    def setUp(self):187        self.parse = Parser(188        dialect=create_dialect(creole11_base,189        wiki_links_base_url='',190        interwiki_links_base_urls={'Ohana': inter_wiki_url},191        #use_additions=True,192        no_wiki_monospace=False193           )194        )195    def test_links(self):196        super(Text2HTMLTest, self).test_links()197        self.assertEquals(198            self.parse("[[foobar]]"),199            wrap_result("""<a href="foobar">foobar</a>"""))200        self.assertEquals(201            self.parse("[[foo bar]]"),202            wrap_result("""<a href="foo_bar">foo bar</a>"""))203        self.assertEquals(204            self.parse("[[foo  bar]]"),205            wrap_result("[[foo  bar]]"))206        self.assertEquals(207            self.parse("[[mailto:someone@example.com]]"),208            wrap_result("""<a href="mailto:someone@example.com">mailto:someone@example.com</a>"""))209        self.assertEquals(210            self.parse("[[http://www.google.com| <<luca Google>>]]"),211            wrap_result("""<a href="http://www.google.com"><code class="unknown_macro"><<<span class="macro_name">luca</span><span class="macro_arg_string"> Google</span>>></code></a>"""))212    def test_bold(self):213        self.assertEquals(214            self.parse("the **bold** is bolded"),215            wrap_result("""the <strong>bold</strong> is bolded"""))216        self.assertEquals(217            self.parse("**this is bold** {{{not **this**}}}"),218            wrap_result("""<strong>this is bold</strong> <span>not **this**</span>"""))219        self.assertEquals(220            self.parse("**this is bold //this is bold and italic//**"),221            wrap_result("""<strong>this is bold <em>this is bold and italic</em></strong>"""))222    def test_italics(self):223        self.assertEquals(224            self.parse("the //italic// is italiced"),225            wrap_result("""the <em>italic</em> is italiced"""))226        self.assertEquals(227            self.parse("//this is italic// {{{//not this//}}}"),228        wrap_result("""<em>this is italic</em> <span>//not this//</span>"""))229        self.assertEquals(230            self.parse("//this is italic **this is italic and bold**//"),231        wrap_result("""<em>this is italic <strong>this is italic and bold</strong></em>"""))232    def test_macro_markers(self):233        self.assertEquals(234            self.parse("This is the <<sue sue macro!>>"),235            wrap_result('This is the <code class="unknown_macro"><<<span class="macro_name">sue</span><span class="macro_arg_string"> sue macro!</span>>></code>'))236        self.assertEqualTag(237            self.parse('<<bad name>>foo<</bad>>'),238            wrap_result('<code class="unknown_macro" style="white-space:pre-wrap"><<<span class="macro_name">bad</span><span class="macro_arg_string"> name</span>>><span class="macro_body">foo</span><</bad>></code>'))239        self.assertEqualTag(240            self.parse('<<unknown>>foo<</unknown>>'),241            wrap_result('<code class="unknown_macro" style="white-space:pre-wrap"><<<span class="macro_name">unknown</span><span class="macro_arg_string"></span>>><span class="macro_body">foo</span><</unknown>></code>'))242        self.assertEqualTag(243            self.parse('<<unknown>>foo with\na line break<</unknown>>'),244            wrap_result('<code class="unknown_macro" style="white-space:pre-wrap"><<<span class="macro_name">unknown</span><span class="macro_arg_string"></span>>><span class="macro_body">foo with\na line break</span><</unknown>></code>'))245        self.assertEqualTag(246            self.parse('<<unknown>>\nfoo\n<</unknown>>'),247            '<pre class="unknown_macro"><<<span class="macro_name">unknown</span><span class="macro_arg_string"></span>>>\n<span class="macro_body">foo\n</span><</unknown>></pre>')248        self.assertEqualTag(249            self.parse('start\n\n<<unknown>>\n\nend'),250            wrap_result('start</p>\n<p><code class="unknown_macro"><<<span class="macro_name">unknown</span><span class="macro_arg_string"></span>>></code></p>\n<p>end'))251    def test_monotype(self):252        pass253    def test_table(self):254        self.assertEquals(255            self.parse(r"""256  |= Item|= Size|= Price|257  | fish | **big**  |cheap|258  | crab | small|expesive|259  |= Item|= Size|= Price260  | fish | big  |//cheap//261  | crab | small|**very\\expesive**"""),262            """<table><tr><th>Item</th><th>Size</th><th>Price</th></tr>263<tr><td>fish</td><td><strong>big</strong></td><td>cheap</td></tr>264<tr><td>crab</td><td>small</td><td>expesive</td></tr>265</table>266<table><tr><th>Item</th><th>Size</th><th>Price</th></tr>267<tr><td>fish</td><td>big</td><td><em>cheap</em></td></tr>268<tr><td>crab</td><td>small</td><td><strong>very<br />expesive</strong></td></tr>269</table>\n""")270    def test_headings(self):271        self.assertEquals(272            self.parse("= Level 1 (largest)"),273            "<h1>Level 1 (largest)</h1>\n")274        self.assertEquals(275            self.parse("== Level 2"),276            "<h2>Level 2</h2>\n")277        self.assertEquals(278            self.parse("=== Level 3"),279            "<h3>Level 3</h3>\n")280        self.assertEquals(281            self.parse("==== Level 4"),282            "<h4>Level 4</h4>\n")283        self.assertEquals(284            self.parse("===== Level 5"),285            "<h5>Level 5</h5>\n")286        self.assertEquals(287            self.parse("====== Level 6"),288            "<h6>Level 6</h6>\n")289        self.assertEquals(290            self.parse("=== Also Level 3 ="),291            "<h3>Also Level 3</h3>\n")292        self.assertEquals(293            self.parse("=== Also Level 3 =="),294            "<h3>Also Level 3</h3>\n")295        self.assertEquals(296            self.parse("=== Also Level 3 ==="),297            "<h3>Also Level 3</h3>\n")298        self.assertEquals(299            self.parse("= Also Level = 1 ="),300            "<h1>Also Level = 1</h1>\n")301        302        self.assertEquals(303            self.parse("=== This **is** //parsed// ===\n"),304            "<h3>This <strong>is</strong> <em>parsed</em></h3>\n")305    def test_escape(self):306        self.assertEquals(307            self.parse("a lone escape ~ in the middle of a line"),308            wrap_result("a lone escape ~ in the middle of a line"))309        self.assertEquals(310            self.parse("or at the end ~\nof a line"),311            wrap_result("or at the end ~\nof a line"))312        self.assertEquals(313            self.parse("a double ~~ in the middle"),314            wrap_result("a double ~ in the middle"))315        self.assertEquals(316            self.parse("or at the end ~~"),317            wrap_result("or at the end ~"))318        self.assertEquals(319            self.parse("preventing markup for ~**bold~** and ~//italics~//"),320            wrap_result("preventing markup for **bold** and //italics//"))321        self.assertEquals(322            self.parse("preventing markup for ~= headings"),323            wrap_result("preventing markup for = headings"))324        self.assertEquals(325            self.parse("|preventing markup|for a pipe ~| in a table|\n"),326            "<table><tr><td>preventing markup</td><td>for a pipe | in a table</td></tr>\n</table>\n")327    def test_preformat(self):328        self.assertEquals(329            self.parse("""{{{330** some ** unformatted {{{ stuff }}} ~~~331 }}}332}}}"""),333            """\334<pre>** some ** unformatted {{{ stuff }}} ~~~335}}}336</pre>337""")338    def test_inline_unformatted(self):339        self.assertEquals(340            self.parse("""341            {{{** some ** unformatted {{{ stuff ~~ }}}}}}342            """),343            wrap_result("            <span>** some ** unformatted {{{ stuff ~~ }}}</span>"))344    def test_link_in_table(self):345        self.assertEquals(346            self.parse("|http://www.google.com|Google|\n"),347            """<table><tr><td><a href="http://www.google.com">http://www.google.com</a></td><td>Google</td></tr>\n</table>\n""")348    def test_link_in_bold(self):349        self.assertEquals(350            self.parse("**[[http://www.google.com|Google]]**"),351            wrap_result("""<strong><a href="http://www.google.com">Google</a></strong>"""))352    def test_link_in_heading(self):353        self.assertEquals(354            self.parse("= [[http://www.google.com|Google]]\n"),355            """<h1><a href="http://www.google.com">Google</a></h1>\n""")356        self.assertEquals(357            self.parse("== http://www.google.com\n"),358            """<h2><a href="http://www.google.com">http://www.google.com</a></h2>\n""")359        self.assertEquals(360            self.parse("== ~http://www.google.com\n"),361            "<h2>http://www.google.com</h2>\n")362    def test_unordered_lists(self):363        self.assertEquals(364            self.parse("""365* this is list **item one**366** //subitem 1//367** //subitem 2//368*** A369*** B370** //subitem 3//371* **item two372* **item three**373*# item four374            """),375            "<ul><li>this is list <strong>item one</strong>\n<ul><li><em>subitem 1</em>\n</li><li><em>subitem 2</em>\n<ul><li>A\n</li><li>B\n</li></ul></li><li><em>subitem 3</em>\n</li></ul></li><li><strong>item two</strong>\n</li><li><strong>item three</strong>\n</li><li># item four\n</li></ul>\n")376    def test_ordered_lists(self):377        self.assertEquals(378            self.parse("""379# this is list **item one**380## //subitem 1//381## //subitem 2//382### A383### B384# **item two385# **item three**386            """),387            "<ol><li>this is list <strong>item one</strong>\n<ol><li><em>subitem 1</em>\n</li><li><em>subitem 2</em>\n<ol><li>A\n</li><li>B\n</li></ol></li></ol></li><li><strong>item two</strong>\n</li><li><strong>item three</strong>\n</li></ol>\n")388    def test_mixed_lists(self):389        self.assertEquals(390            self.parse("""391# this is list **item one**392** //unordered subitem 1//393** //unordered subitem 2//394# **item two395** Unorder subitem 1396** Unorder subitem 2397# **item three**"""),398            "<ol><li>this is list <strong>item one</strong>\n<ul><li><em>unordered subitem 1</em>\n</li><li><em>unordered subitem 2</em>\n</li></ul></li>\399<li><strong>item two</strong>\n<ul><li>Unorder subitem 1\n</li><li>Unorder subitem 2\n</li></ul></li><li><strong>item three</strong></li></ol>\n")400    def test_definition_lists(self):401        self.assertEquals(402            self.parse("""403; This is a title:404: this is its entry405; Another title : it's definition entry406; This is ~: a another title:407: this is its entry408** and this emphasized!409; Title410: definition 1411: defintioins 2412"""),413            "<dl><dt>This is a title:</dt>\n<dd>this is its entry</dd>\n<dt>Another title</dt>\n<dd>it's definition entry</dd>\n<dt>This is : a another title:</dt>\n<dd>this is its entry\n<strong> and this emphasized!</strong></dd>\n<dt>Title</dt>\n<dd>definition 1</dd>\n<dd>defintioins 2</dd>\n</dl>\n")414    def test_image(self):415        self.assertEqualTag(416            self.parse("{{campfire.jpg}}"),417            wrap_result("""<img src="campfire.jpg" alt="campfire.jpg" title="campfire.jpg" />"""))418    def test_image_in_link(self):419        self.assertEqualTag(420            self.parse("[[http://google.com | {{ campfire.jpg | Nice Pic }}]]"),421            wrap_result("""<a href="http://google.com"><img src="campfire.jpg" alt="Nice Pic" title="Nice Pic" /></a>"""))422        self.assertEqualTag(423            self.parse("[[http://google.com | {{ campfire.jpg }}]]"),424            wrap_result("""<a href="http://google.com"><img src="campfire.jpg" alt="campfire.jpg" title="campfire.jpg" /></a>"""))425    def test_image_in_table(self):426        self.assertEqualTag(427            self.parse("|nice picture |{{campfire.jpg}}|\n"),428            """<table><tr><td>nice picture</td><td><img src="campfire.jpg" alt="campfire.jpg" title="campfire.jpg" /></td></tr>\n</table>\n""")429    def test_super_and_sub_scripts(self):430        self.assertEquals(431            self.parse("^^superscript^^"),432            wrap_result("<sup>superscript</sup>"))433        self.assertEquals(434            self.parse(",,subscript,,"),435            wrap_result("<sub>subscript</sub>"))436        self.assertEquals(437            self.parse("__underline__"),438            wrap_result("<u>underline</u>"))439        self.assertEquals(440            self.parse("//^^superscript^^,,subscript,,**__underline__**//"),441            wrap_result("<em><sup>superscript</sup><sub>subscript</sub><strong><u>underline</u></strong></em>"))442        self.assertEquals(443            self.parse("^^//superscript//\\hello^^\n,,sub**scr**ipt,,"),444            wrap_result("<sup><em>superscript</em>\\hello</sup>\n<sub>sub<strong>scr</strong>ipt</sub>"))445        self.assertEquals(446            self.parse("__underline__"),447            wrap_result("<u>underline</u>"))448class DialectOptionsTest(SloppyBytesTestCase):449    def test_no_wiki_monospace_option(self):450        dialect = create_dialect(creole10_base, no_wiki_monospace=True)451        parse = Parser(dialect)452        self.assertEquals(453            parse("This block of {{{no_wiki **shouldn't** be monospace}}} now"),454            wrap_result("This block of <code>no_wiki **shouldn't** be monospace</code> now"))455    def test_use_additions_option(self):456        dialect = create_dialect(creole11_base) #, use_additions=True)457        parse = Parser(dialect)458        self.assertEquals(459            parse("This block of ##text **should** be monospace## now"),460            wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"))461    def test_blog_style_endings_option(self):462        dialect = create_dialect(creole10_base, blog_style_endings=True)463        parse = Parser(dialect)464        self.assertEquals(465            parse("The first line\nthis text **should** be on the second line\n now third"),466            wrap_result("The first line<br />this text <strong>should</strong> be on the second line<br /> now third"))467        self.assertEquals(468            parse("The first line\\\\\nthis text **should** be on the second line\\\\\n now third"),469            wrap_result("The first line<br />this text <strong>should</strong> be on the second line<br /> now third"))470    def test_wiki_links_base_url_option(self):471        dialect = create_dialect(creole10_base, wiki_links_base_url='http://www.example.com')472        parse = Parser(dialect)473        self.assertEquals(474            parse("[[foobar]]"),475            wrap_result("""<a href="http://www.example.com/foobar">foobar</a>"""))476    def test_image_link_options(self):477        dialect = create_dialect(creole10_base, wiki_links_base_url=['/pages/',478                                                                     '/files/'],479                                 wiki_links_space_char=['_',' '],480                                 wiki_links_path_func=[lambda s:s.upper(),481                                                       lambda s:s.capitalize()])482        parse = Parser(dialect)483        self.assertEquals(484            parse("[[foo bar]]"),485            wrap_result("""<a href="/pages/FOO_BAR">foo bar</a>"""))486        self.assertEqualTag(487            parse("{{foo bar}}"),488            wrap_result("""<img src="/files/Foo bar" alt="foo bar" title="foo bar" />"""))489    def test_interwiki_image_link_options(self):490        dialect = create_dialect(creole10_base,491                                 interwiki_links_base_urls={'a': ['/pages/','/files/']},492                                 interwiki_links_space_chars={'a': ['_',' ']},493                                 interwiki_links_path_funcs={'a': [lambda s:s.upper(),494                                                                    lambda s:s.capitalize()]})495        parse = Parser(dialect)496        self.assertEquals(497            parse("[[a:foo bar|Foo]]"),498            wrap_result("""<a href="/pages/FOO_BAR">Foo</a>"""))499        self.assertEqualTag(500            parse("{{a:foo bar|Foo}}"),501            wrap_result("""<img src="/files/Foo bar" alt="Foo" title="Foo" />"""))502    def test_disable_external_content(self):503        dialect = create_dialect(creole10_base, disable_external_content=True)504        parse = Parser(dialect)505        self.assertEqualTag(506            parse("{{campfire.jpg}}"),507            wrap_result("""<img src="campfire.jpg" alt="campfire.jpg" title="campfire.jpg" />"""))508        self.assertEqualTag(509            parse("{{/campfire.jpg}}"),510            wrap_result("""<span class="external_image">External images are disabled</span>"""))511        self.assertEqualTag(512            parse("{{http://www.somesite.com/campfire.jpg}}"),513            wrap_result("""<span class="external_image">External images are disabled</span>"""))514    def test_custom_markup_option(self):515        def wikiword(mo, e):516            return builder.tag.a(mo.group(1),href=mo.group(1))517        dialect = create_dialect(creole10_base,518                                 custom_markup=[('(c)','©'),519                                                (re.compile(esc_neg_look + r'\b([A-Z]\w+[A-Z]+\w+)'),wikiword)])520        parse = Parser(dialect)521        self.assertEquals(522            parse("The copyright symbol (c), escaped ~(c)"),523            wrap_result("The copyright symbol ©, escaped (c)"))524        self.assertEquals(525            parse("A WikiPage name that is a ~WikiWord"),526            wrap_result('A <a href="WikiPage">WikiPage</a> name that is a WikiWord'))527    def test_simple_markup_option(self):528        MyDialect = create_dialect(creole10_base, simple_markup=[('*','strong'),('#','code')])529        parse = Parser(MyDialect)530        self.assertEquals(531            parse("This block of #text *should* be monospace# now"),532            wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"))533    def test_bodied_macros_option(self):534        def red(macro,e,*args,**kw):535            return builder.tag.__getattr__(macro.isblock and 'div' or 'span')(536                macro.parsed_body(),style='color:red')537        red.parse_body = True538            #return {'style':'color:red'}539        def blockquote(macro,e,*args,**kw):540            return builder.tag.blockquote(macro.parsed_body())541        blockquote.parse_body = True542            #return {'tag':'blockquote'}543        MyDialect = create_dialect(creole11_base, bodied_macros=dict(red=red, blockquote=blockquote))544        parse = Parser(MyDialect)545        self.assertEquals(546            parse("This block of <<red>>text **should** be monospace<</red>> now"),547            wrap_result('This block of <span style="color:red">text <strong>should</strong> be monospace</span> now'))548        self.assertEquals(549            parse("<<red>>\ntext **should** be monospace\n<</red>>"),550            '<div style="color:red"><p>text <strong>should</strong> be monospace</p>\n</div>')551        self.assertEquals(552            parse("This block of <<blockquote>>text **should** be monospace<</blockquote>> now"),553            wrap_result('This block of </p><blockquote>text <strong>should</strong> be monospace</blockquote><p> now'))554        self.assertEquals(555            parse("<<blockquote>>\ntext **should** be monospace\n<</blockquote>>"),556            '<blockquote><p>text <strong>should</strong> be monospace</p>\n</blockquote>')557    def test_external_links_class_option(self):558        dialect = create_dialect(creole10_base, external_links_class='external')559        parse = Parser(dialect)560        self.assertEquals(561            parse("[[campfire.jpg]]"),562            wrap_result("""<a href="campfire.jpg">campfire.jpg</a>"""))563        self.assertEqualTag(564            parse("[[/campfire.jpg]]"),565            wrap_result("""<a class="external" href="/campfire.jpg">/campfire.jpg</a>"""))566        self.assertEqualTag(567            parse("[[http://www.somesite.com/campfire.jpg]]"),568            wrap_result("""<a class="external" href="http://www.somesite.com/campfire.jpg">http://www.somesite.com/campfire.jpg</a>"""))569    def test_add_heading_ids(self):570        dialect = create_dialect(creole10_base, add_heading_ids=True)571        parse = Parser(dialect)572        self.assertEquals(573            parse("== Level 2"),574            '<h2 id="!level-2">Level 2</h2>\n')575        self.assertEquals(576            parse("= Level 1\n= Level 1"),577            '<h1 id="!level-1">Level 1</h1>\n<h1 id="!level-1_1">Level 1</h1>\n')578        self.assertEquals(579            parse("= [[http://www.google.com|Google]]\n"),580            """<h1 id="!google"><a href="http://www.google.com">Google</a></h1>\n""")581        self.assertEquals(582            parse("== http://www.google.com\n"),583            """<h2 id="!http-www-google-com"><a href="http://www.google.com">http://www.google.com</a></h2>\n""")584        self.assertEquals(585            parse("== ~http://www.google.com\n"),586            '<h2 id="!http-www-google-com">http://www.google.com</h2>\n')587        self.assertEquals(588            parse("[[foo bar#!a-heading_1]]"),589            wrap_result("""<a href="foo_bar#!a-heading_1">foo bar#!a-heading_1</a>"""))590        self.assertEquals(591            parse("[[#!a-heading]]"),592            wrap_result("""<a href="#!a-heading">#!a-heading</a>"""))593        self.assertEquals(594            parse("[[foo bar#1]]"),595            wrap_result("""<a href="foo_bar%231">foo bar#1</a>"""))596        self.assertEquals(597            parse("[[#1]]"),598            wrap_result("""<a href="%231">#1</a>"""))599        dialect = create_dialect(creole10_base, add_heading_ids='')600        parse = Parser(dialect)601        self.assertEquals(602            parse("== Level 2"),603            '<h2 id="level-2">Level 2</h2>\n')604        605       606class ExtendingTest(SloppyBytesTestCase):607    608    def test_simple_tokens_option(self):609        Base = creole10_base()610        class MyDialect(Base):611            simple_element = SimpleElement(token_dict={'*':'strong','#':'code'})612        parse = Parser(MyDialect)613        self.assertEquals(614            parse("This block of #text *should* be monospace# now"),615            wrap_result("This block of <code>text <strong>should</strong> be monospace</code> now"))616    def test_disable_images(self):617        Base = creole10_base()618        class MyDialect(Base):619            @property620            def inline_elements(self):621                l = super(MyDialect,self).inline_elements622                l.remove(self.img)623                return l624        parse = Parser(MyDialect)625        self.assertEquals(626            parse("{{somefile.jpg}}"),627            wrap_result("{{somefile.jpg}}"))628       629class NoSpaceDialectTest(SloppyBytesTestCase, BaseTest):630    def setUp(self):631        noSpaces = Parser(632            dialect=create_dialect(creole11_base,633                wiki_links_base_url=base_url,634                wiki_links_space_char='',635                interwiki_links_base_urls={'Ohana': inter_wiki_url},636                no_wiki_monospace=False,637                wiki_links_class_func=class_name_function,638                wiki_links_path_func=path_name_function639                )640            )641        self.parse = noSpaces642    def test_links_with_spaces(self):643        self.assertEquals(644            self.parse("[[This Page Name Has Spaces]]"),645            wrap_result("""<a href="ThisPageNameHasSpaces">This Page Name Has Spaces</a>"""))646    def test_special_link(self):647        self.assertEquals(648            self.parse("[[This Page Here]]"),649            wrap_result("""<a href="Special/ThisPageHere">This Page Here</a>"""))650    def test_new_page(self):651        self.assertEqualTag(652            self.parse("[[New Page|this]]"),653            wrap_result("""<a class="nonexistent" href="NewPage">this</a>"""))654class MacroTest(SloppyBytesTestCase, BaseTest):655    """656    """657    def setUp(self):658        dialect = create_dialect(creole11_base,659            wiki_links_base_url='',660            wiki_links_space_char='_',661            interwiki_links_base_urls={'Ohana': inter_wiki_url},662            no_wiki_monospace=False,663            macro_func=self.macroFactory,664            bodied_macros=dict(span=self.span, div=self.div),665            non_bodied_macros=dict(luca=self.luca),                                 666                                 )667        self.parse = Parser(dialect)668    class Wiki(object):669        page_title='Home'670    671    def getFragment(self, text):672        wrapped = Markup(text)673        fragment = builder.tag(wrapped)674        return fragment675    def getStream(self, text):676        wrapped = Markup(text)677        fragment = builder.tag(wrapped)678        return fragment.generate()679    def span(self, macro, e, id_=None):680        return builder.tag.span(macro.parsed_body(),id_=id_)681    def div(self, macro, e, id_=None):682        return builder.tag.div(macro.parsed_body('block'),id_=id_)683    684    def luca(self, macro, e, *pos, **kw):685        return builder.tag.strong(macro.arg_string)686    def macroFactory(self, macro_name, arg_string, body, context,wiki):687        if macro_name == 'html':688            return self.getFragment(body)689        elif macro_name == 'title':690            return wiki.page_title691#        elif macro_name == 'span':692#            return builder.tag.span(self.parse.generate(body,context='inline'),id_=arg_string.strip())693#        elif macro_name == 'div':694#            return builder.tag.div(self.parse.generate(body),id_=arg_string.strip())695        elif macro_name == 'html2':696            return Markup(body)697        elif macro_name == 'htmlblock':698            return self.getStream(body)699        elif macro_name == 'pre':700            return builder.tag.pre('**' + body + '**')701        elif macro_name == 'steve':702            return '**' + arg_string + '**'703#        elif macro_name == 'luca':704#            return builder.tag.strong(arg_string)705        elif macro_name == 'mateo':706            return builder.tag.em(body)707        elif macro_name == 'ReverseFrag':708            return builder.tag(body[::-1])709        elif macro_name == 'Reverse':710            return body[::-1]711        elif macro_name == 'Reverse-it':712            return body[::-1]713        elif macro_name == 'ReverseIt':714            return body[::-1]715        elif macro_name == 'lib.ReverseIt-now':716            return body[::-1]717        elif macro_name == 'ifloggedin':718            return body719        elif macro_name == 'username':720            return 'Joe Blow'721        elif macro_name == 'center':722            return builder.tag.span(body, class_='centered')723        elif macro_name == 'footer':724            return '<<center>>This is a footer.<</center>>'725        elif macro_name == 'footer2':726            return '<<center>>\nThis is a footer.\n<</center>>'727        elif macro_name == 'reverse-lines':728            if body is not None:729                l = reversed(body.rstrip().split('\n'))730                if arg_string.strip() == 'output=wiki':731                    return '\n'.join(l) + '\n'732                else:733                    return builder.tag('\n'.join(l) + '\n')734    def test_macros(self):735        self.assertEquals(736            self.parse('<<title>>',environ=self.Wiki),737            wrap_result('Home'))738        self.assertEquals(739            self.parse('<<html>><q cite="http://example.org">foo</q><</html>>'),740            wrap_result('<q cite="http://example.org">foo</q>'))741        self.assertEquals(742            self.parse('<<html2>><b>hello</b><</html2>>'),743            '<b>hello</b>\n')744        self.assertEquals(745            self.parse('<<htmlblock>><q cite="http://example.org">foo</q><</htmlblock>>'),746                '<q cite="http://example.org">foo</q>\n')747        self.assertEquals(748            self.parse('<<pre>>//no wiki//<</pre>>'),749            '<pre>**//no wiki//**</pre>\n')750        self.assertEquals(751            self.parse('<<pre>>one<</pre>>\n<<pre>>two<</pre>>'),752            '<pre>**one**</pre>\n<pre>**two**</pre>\n')753        self.assertEquals(754            self.parse('<<pre>>one<<pre>>\n<</pre>>two<</pre>>'),755            '<pre>**one<<pre>>\n<</pre>>two**</pre>\n')756        self.assertEquals(757            self.parse(u'<<mateo>>fooα<</mateo>>'),758            wrap_result(u'<em>fooα</em>'))759        self.assertEquals(760            self.parse(u'<<steve fooα>>'),761            wrap_result(u'<strong> fooα</strong>'))762        self.assertEquals(763            self.parse('<<ReverseFrag>>**foo**<</ReverseFrag>>'),764            wrap_result('**oof**'))765        self.assertEquals(        766            self.parse('<<Reverse>>**foo**<</Reverse>>'),767            wrap_result('<strong>oof</strong>'))768        self.assertEquals(769            self.parse('<<Reverse>>foo<</Reverse>>'),770            wrap_result('oof'))771        self.assertEquals(772            self.parse('<<Reverse-it>>foo<</Reverse-it>>'),773            wrap_result('oof'))774        self.assertEquals(775            self.parse('<<ReverseIt>>foo<</ReverseIt>>'),776            wrap_result('oof'))777        self.assertEquals(778            self.parse('<<lib.ReverseIt-now>>foo<</lib.ReverseIt-now>>'),779            wrap_result('oof'))780        self.assertEquals(781            self.parse(u'<<luca boo>>foo<</unknown>>'),782            wrap_result('<strong> boo</strong>foo<</unknown>>'))783        self.assertEquals(784            self.parse('Hello<<ifloggedin>> <<username>><</ifloggedin>>!'),785            wrap_result('Hello Joe Blow!'))786        self.assertEquals(787            self.parse(' <<footer>>'),788            wrap_result(' <span class="centered">This is a footer.</span>'))789        self.assertEquals(790            self.parse('<<footer2>>'),791            wrap_result('<span class="centered">\nThis is a footer.\n</span>'))792        self.assertEquals(793            self.parse('<<luca foobar />>'),794            wrap_result('<strong> foobar </strong>'))795        self.assertEquals(796            self.parse("<<reverse-lines>>one<</reverse-lines>>"),797            wrap_result("one\n"))798        self.assertEquals(799            self.parse("<<reverse-lines>>one\ntwo\n<</reverse-lines>>"),800            wrap_result("two\none\n"))801        self.assertEquals(802            self.parse("<<reverse-lines>>\none\ntwo<</reverse-lines>>"),803            wrap_result("two\none\n\n"))804        self.assertEquals(805            self.parse(806"""\807<<reverse-lines>>808one809two810<</reverse-lines>>811"""),812 """\813<p>two814one815</p>""")816        self.assertEquals(817            self.parse(u"\n<<div one>>\nblaa<</div>>"),818            '<div id="one"><p>blaa</p>\n</div>\n')819        self.assertEquals(820            self.parse("<<reverse-lines>>one\n{{{two}}}\n<</reverse-lines>>"),821            wrap_result("{{{two}}}\none\n"))822        self.assertEquals(823            self.parse("<<reverse-lines>>one\n{{{\ntwo}}}\n<</reverse-lines>>"),824            wrap_result("two}}}\n{{{\none\n"))825        self.assertEquals(826            self.parse("<<reverse-lines>>one\n{{{\ntwo\n}}}<</reverse-lines>>"),827            wrap_result("}}}\ntwo\n{{{\none\n"))828        self.assertEquals(829            self.parse("<<reverse-lines>>\none\n{{{\ntwo\n}}}\n<</reverse-lines>>"),830            "<p>}}}\ntwo\n{{{\none\n</p>")831        self.assertEquals(832            self.parse("<<reverse-lines output=wiki>>one\n{{{\ntwo\n}}}<</reverse-lines>>"),833            wrap_result("}}}\ntwo\n{{{\none\n"))834        self.assertEquals(835            self.parse("<<reverse-lines output=wiki>>one\n}}}\ntwo\n{{{<</reverse-lines>>"),836            wrap_result("<span>\ntwo\n</span>\none\n"))837        self.assertEquals(838            self.parse("<<reverse-lines output=wiki>>one\n}}}\ntwo\n{{{\n<</reverse-lines>>"),839            wrap_result("<span>\ntwo\n</span>\none\n"))840        self.assertEquals(841            self.parse("<<reverse-lines output=wiki>>\none\n}}}\n\ntwo\n{{{\n<</reverse-lines>>"),842            "<pre>two\n\n</pre>\n<p>one</p>\n")843        self.assertEquals(844            self.parse("<<reverse-lines output=wiki>>\none\n\n}}}\ntwo\n{{{\n<</reverse-lines>>"),845            "<pre>two\n</pre>\n<p>one</p>\n")846    def test_nesting_macros(self):847        self.assertEquals(848            self.parse('<<span one>>part 1<</span>><<span two>>part 2<</span>>'),849            wrap_result('<span id="one">part 1</span><span id="two">part 2</span>'))850        self.assertEquals(851            self.parse('<<span>>part 1a<<span two>>part 2<</span>>part 1b<</span>>'),852            wrap_result('<span>part 1a<span id="two">part 2</span>part 1b</span>'))853        self.assertEquals(854            self.parse('<<span>>part 1a<<span>>part 2<</span>>part 1b<</span>>'),855            wrap_result('<span>part 1a<span>part 2</span>part 1b</span>'))856        self.assertEquals(857            self.parse('<<span one>>part 1a<<span two>>part 2<</span>>part 1b<</span>>'),858            wrap_result('<span id="one">part 1a<span id="two">part 2</span>part 1b</span>'))859        self.assertEquals(860            self.parse("""861<<div one>>862part 1a863<<div two>>864part 2865<</div>>866part 1b867<</div>>"""),'<div id="one"><p>part 1a</p>\n<div id="two"><p>part 2</p>\n</div><p>part 1b</p>\n</div>')868        self.assertEquals(869            self.parse("""870<<div one>>871part 1872<</div>>873<<div one>>874part 2875<</div>>"""),'<div id="one"><p>part 1</p>\n</div><div id="one"><p>part 2</p>\n</div>')876        877    def test_links(self):878        super(MacroTest, self).test_links()879        self.assertEquals(880            self.parse("[[http://www.google.com| <<luca Google>>]]"),881            wrap_result("""<a href="http://www.google.com"><strong> Google</strong></a>"""))882    def test_links_with_spaces(self):883        super(MacroTest, self).test_links_with_spaces()884        self.assertEquals(885            self.parse("[[This Page Here|<<steve the steve macro!>>]]"),886            wrap_result("""<a href="This_Page_Here"><strong> the steve macro!</strong></a>"""))887    def test_argument_error(self):888        self.assertTrue(self.parse("<<span error here>>This is bad<</span>>").startswith(six.b('''<p><code class="macro_error">Macro error: 'span' ''')))889        self.assertTrue(self.parse("<<span a=1>>This is bad<</span>>").startswith(six.b('''<p><code class="macro_error">Macro error: 'span' ''')))890    def test_slow_reg_exp(self):891        t = timeit.Timer('text2html("<<aaaaaaaaaaaaaaaaa>>")','from creoleparser.tests import text2html')892        t2 = timeit.Timer('a = "a" * 100')893        rel_time = t.timeit(number=10)/t2.timeit(100000)894        self.assertTrue(rel_time < 10)895class InterWikiLinksTest(SloppyBytesTestCase,BaseTest):896    def setUp(self):897        def inter_wiki_link_maker(name):898            return name[::-1]899        def simple_class_maker(name):900            return name.lower()901        functions = {902            'moo':inter_wiki_link_maker,903            'goo':inter_wiki_link_maker,904            }905        base_urls = {906            'goo': 'http://example.org',907            'poo': 'http://example.org',908            'Ohana': inter_wiki_url,909            }910        space_characters = {911            'goo': '+',912            'poo': '+',913            }914        class_functions = {915            'moo':simple_class_maker,916            'goo':simple_class_maker,917            }918        dialect = create_dialect(creole10_base,919            interwiki_links_path_funcs=functions,920            interwiki_links_class_funcs=class_functions,921            interwiki_links_base_urls=base_urls,922            interwiki_links_space_chars=space_characters923            )924        self.parse = Parser(dialect)925    def test_interwiki_links(self):926        super(InterWikiLinksTest,self).test_interwiki_links()927        self.assertEqualTag(928            self.parse("[[moo:foo bar|Foo]]"),929            wrap_result("""<a class="foo_bar" href="rab_oof">Foo</a>"""))930        self.assertEqualTag(931            self.parse("[[goo:foo|Foo]]"),932            wrap_result("""<a class="foo" href="http://example.org/oof">Foo</a>"""))933        self.assertEqualTag(934            self.parse("[[poo:foo|Foo]]"),935            wrap_result("""<a href="http://example.org/foo">Foo</a>"""))936        self.assertEqualTag(937            self.parse("[[poo:foo bar|Foo]]"),938            wrap_result("""<a href="http://example.org/foo%2Bbar">Foo</a>"""))939        self.assertEqualTag(940            self.parse("[[goo:foo bar|Foo]]"),941            wrap_result("""<a class="foo+bar" href="http://example.org/rab+oof">Foo</a>"""))942        self.assertEquals(943            self.parse("[[roo:foo bar|Foo]]"),944            wrap_result("""<a href="roo%3Afoo_bar">Foo</a>"""))945            #wrap_result("""[[roo:foo bar|Foo]]"""))946class TaintingTest(SloppyBytesTestCase):947    """948    """949    def setUp(self):950        self.parse = text2html951    def test_cookies(self):952        self.assertEquals(953            self.parse("{{javascript:alert(document.cookie)}}"),954            wrap_result("{{javascript:alert(document.cookie)}}"))955        self.assertEquals(956            self.parse("[[javascript:alert(document.cookie)]]"),957            wrap_result("[[javascript:alert(document.cookie)]]"))958class IndentTest(SloppyBytesTestCase):959    """960    """961    def setUp(self):962        #Base = creole11_base()963        #class MyDialect(Base):964        #    indented = IndentedBlock('div','>', class_=None, style=None)965        self.parse = Parser(creole11_base(indent_style=None))#Parser(MyDialect)966    def test_simple(self):967        self.assertEquals(968            self.parse("""\969Foo970>Boo971>972>Boo2973"""),974            """<p>Foo</p>\n<div><p>Boo</p>\n<p>Boo2</p>\n</div>\n""")975        self.assertEquals(976            self.parse("""\977Foo978>Boo979>Too980>>Poo981>>>Foo982"""),983            """<p>Foo</p>\n<div><p>Boo\nToo</p>\n<div><p>Poo</p>\n<div><p>Foo</p>\n</div>\n</div>\n</div>\n""")984        self.assertEquals(985            self.parse("""\986Foo987>Boo988>Too989>>Poo990>Foo991>>Blaa992"""),993            """<p>Foo</p>\n<div><p>Boo\nToo</p>\n<div><p>Poo</p>\n</div>\n<p>Foo</p>\n</div>\n<div><div><p>Blaa</p>\n</div>\n</div>\n""")        994class LongDocumentTest(SloppyBytesTestCase):995    """996    """997    def test_very_long_document(self):998        lines = [str(x)+' blaa blaa' for x in range(2000)]999        lines[50] = '{{{'1000        lines[500] = '}}}'1001        lines[1100] = '{{{'1002        lines[1400] = '}}}'1003        doc = '\n\n'.join(lines) + '\n'1004        pre = False1005        expected_lines = []1006        for line in lines:1007            if line == '{{{':1008                expected_lines.append('<pre>\n')1009                pre = True1010            elif line == '}}}':1011                expected_lines.append('</pre>\n')1012                pre = False1013            elif pre:1014                expected_lines.append(line+'\n\n')1015            else:1016                expected_lines.append('<p>'+line+'</p>\n')1017        expected = ''.join(expected_lines)1018        rendered = text2html(doc)1019        self.assertEquals(text2html(doc), expected)1020    def test_very_long_list(self):1021        lines = ['* blaa blaa' for x in range(1000)]1022        doc = '\n'.join(lines) + '\n'1023        expected_lines = ['<ul>']1024        for line in lines:1025            expected_lines.append('<li>'+'blaa blaa'+'\n</li>')1026        expected_lines.append('</ul>\n')        1027        expected = ''.join(expected_lines)1028        rendered = text2html(doc)1029        self.assertEquals(text2html(doc), expected)1030    def test_very_long_table(self):1031        lines = ['| blaa blaa' for x in range(1000)]1032        doc = '\n'.join(lines) + '\n'1033        expected_lines = ['<table>']1034        for line in lines:1035            expected_lines.append('<tr><td>'+'blaa blaa'+'</td></tr>\n')1036        expected_lines.append('</table>\n')        1037        expected = ''.join(expected_lines)1038        rendered = text2html(doc)1039        self.assertEquals(text2html(doc), expected)1040class ContextTest(SloppyBytesTestCase):1041    """1042    """1043    def setUp(self):1044        self.markup = "steve //rad//"1045    def test_block_context(self):1046        result = text2html.render(self.markup, context="block")1047        self.assertEqual(result, wrap_result("steve <em>rad</em>"))1048    def test_inline_context(self):1049        result = text2html.render(self.markup, context="inline")1050        self.assertEqual(result, "steve <em>rad</em>")1051    def test_inline_elements_context(self):1052        context = text2html.dialect.inline_elements1053        result = text2html.render(self.markup, context=context)1054        self.assertEqual(result, "steve <em>rad</em>")1055    def test_block_elements_context(self):1056        context = text2html.dialect.block_elements1057        result = text2html.render(self.markup+'\n', context=context)1058        self.assertEqual(result, wrap_result("steve <em>rad</em>"))1059def test_suite():1060    return unittest.TestSuite((1061        unittest.makeSuite(Creole2HTMLTest),1062        unittest.makeSuite(Text2HTMLTest),1063        unittest.makeSuite(DialectOptionsTest),1064        unittest.makeSuite(NoSpaceDialectTest),1065        unittest.makeSuite(MacroTest),1066        unittest.makeSuite(InterWikiLinksTest),1067        unittest.makeSuite(TaintingTest),1068        unittest.makeSuite(LongDocumentTest),1069        unittest.makeSuite(ContextTest),1070        unittest.makeSuite(ExtendingTest),1071        unittest.makeSuite(IndentTest),1072        ))...main.py
Source:main.py  
...11    response.headers["Access-Control-Allow-Methods"] = "*"12    return response13@app.route('/rpc/base-price', methods=['GET'])14def getWFTMPrice():15  return wrap_result(pwcalc.getWFTMPrice())16@app.route('/rpc/owned/base-pool-lps', methods=['GET'])17def getFtmGtonGCpolLP():18  return wrap_result(pwcalc.getFtmGtonGCpolLP())19@app.route('/rpc/owned/usd-pool-lps', methods=['GET'])20def getUsdGtonGCpolLP():21  return wrap_result(pwcalc.getUsdGtonGCpolLP())22@app.route('/rpc/base-liquidity', methods=['GET'])23def getFtmGtonLiq():24  return wrap_result(pwcalc.getFtmGtonLiq())25@app.route('/rpc/usd-liquidity', methods=['GET'])26def getUsdGtonLiq():27  return wrap_result(pwcalc.getUsdGtonLiq())28@app.route('/rpc/base-pool-lps', methods=['GET'])29def getFtmGtonLP():30  return wrap_result(pwcalc.getFtmGtonLP())31@app.route('/rpc/usd-pool-lps', methods=['GET'])32def getUsdGtonLP():33  return wrap_result(pwcalc.getUsdGtonLP())34@app.route('/rpc/gc-pol', methods=['GET'])35def getGCpol():36  return wrap_result(pwcalc.getGCpol())37@app.route('/rpc/pw-model-peg-with-pol-mln', methods=['GET'])38def pwModelPegWithPolMln():39  pol = request.args.get('pol', None) # with current liq is 40  gcFloor = request.args.get('gcFloor', None) # with current liq is 41  gcBias = request.args.get('gcBias', None) # with current liq is 42  gcMaxP = request.args.get('gcMaxP', None)43  gcMaxL = request.args.get('gcMaxL', None)44  return wrap_result(pwcalc.pwModelPegWithPolMln(45    float(pol or 0),46    float(gcFloor or 0), # with current liq is 47    float(gcBias or 0), # with current liq is 48    float(gcMaxP or 0),49    float(gcMaxL or 1)50  ))51@app.route('/rpc/gc-current-peg-usd', methods=['GET'])52def getGCpwCurrentPegUSD():53  return wrap_result(pwcalc.getGCpwCurrentPegUSD())54@app.route('/rpc/gc-current-peg-base', methods=['GET'])55def getGCpwCurrentPegFTM():56  return wrap_result(pwcalc.getGCpwCurrentPegFTM())57@app.route('/rpc/base-to-usdc-price', methods=['GET'])58def getGTONusdcPrice():59  return wrap_result(pwcalc.getGTONusdcPrice())60@app.route('/rpc/base-to-quote-price', methods=['GET'])61def getGTONwftmPrice():62  return wrap_result(pwcalc.getGTONwftmPrice())63def wrap_result(r):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
