def test_backticks(self): """ Monospace backticks are preserved. """ self.assertEqual( 'text `monospace` text', tm.parse_body('text `monospace` text', ticket_mapping={}))
def test_monospace_escaping(self): """ Escapes one monospace syntax with the other. """ self.assertEqual( "```curly '''not bold'''```", tm.parse_body("{{{curly '''not bold'''}}}", ticket_mapping={})) self.assertEqual( "`backtick '''not bold'''`", tm.parse_body("`backtick '''not bold'''`", ticket_mapping={})) self.assertEqual( "quoting squigglies `{{{` or backticks ```````", tm.parse_body( "quoting squigglies `{{{` or backticks {{{`}}}", ticket_mapping={}, ))
def test_no_ticket_replacement_subset_match(self): """ Does not convert Trac ticket IDs when only a string subset matches. """ self.assertEqual( "Some issue is solved in #1234.", tm.parse_body( description="Some issue is solved in #1234.", ticket_mapping={123: 'some_url/234'}, ))
def test_ticket_replacement_URL(self): """ Converts Trac ticket URLs to GitHub URLs. """ self.assertEqual( "Issue [#234](some_url/234).", tm.parse_body( description="Issue https://trac.chevah.com/ticket/123.", ticket_mapping={123: 'some_url/234'}, ))
def test_missing_ticket_replacement(self): """ Missing Trac ticket IDs are left alone as #1234. """ self.assertEqual( "Some issue is solved in #345.", tm.parse_body( description="Some issue is solved in #345.", ticket_mapping={123: 'some_url/234'}, ))
def test_ticket_replacement(self): """ Converts Trac ticket IDs to GitHub numbers. """ self.assertEqual( "Some issue is solved in [#234](some_url/234).", tm.parse_body( description="Some issue is solved in #123.", ticket_mapping={123: 'some_url/234'}, ))
def test_no_ticket_replacement_in_preformatted(self): """ Does not convert Trac ticket IDs to GitHub numbers in preformatted text. """ self.assertEqual( "```Some issue is solved in #123.```", tm.parse_body( description="{{{Some issue is solved in #123.}}}", ticket_mapping={123: 'some_url/234'}, ))
def test_changeset(self): """ Converts Trac changeset format to unquoted commit hash, which is linked by GitHub automatically. """ self.assertEqual( 'In changeset 11cac74c6a2b528f1caabaa63d532be0ae262c90\n', tm.parse_body( 'In [changeset:"11cac74c6a2b528f1caabaa63d532be0ae262c90" 11cac74]:\n', ticket_mapping={}, ))
def test_ticket_replacement_URL_multiple(self): """ Converts Trac ticket URLs to GitHub URLs. """ self.assertEqual( "(but see [#234](some_url/234)).\n" "CMD [#234](some_url/234)", tm.parse_body( description="(but see https://trac.chevah.com/ticket/123).\n" "CMD https://trac.chevah.com/ticket/123", ticket_mapping={123: 'some_url/234'}, ))
def test_anchor_links_removed(self): """ Remove anchor links, since they will not be preserved in GitHub. """ self.assertEqual( "In order to " "[avoid third-party cookies](https://github.com/chevah/sftpplus.com/pull/254), " "we need to handle the contact form ourselves.", tm.parse_body( "In order to " "[https://github.com/chevah/sftpplus.com/pull/254 avoid third-party cookies], " "we need to handle the contact form ourselves.", ticket_mapping={}, ))
def test_links(self): """ TracWiki syntax links get converted to Markdown links. """ self.assertEqual( "In order to " "[avoid third-party cookies](https://github.com/chevah/sftpplus.com/pull/254), " "we need to handle the contact form ourselves.", tm.parse_body( "In order to " "[https://github.com/chevah/sftpplus.com/pull/254 avoid third-party cookies], " "we need to handle the contact form ourselves.", ticket_mapping={}, ))
def test_convert_content(self): """ Headings are converted. """ self.assertEqual( "# Some Top Heading\n" "\n" "Content ```here```", tm.parse_body( "= Some Top Heading =\n" "\n" "Content {{{here}}}", ticket_mapping={}, ))
def test_ticket_replacement_multiple(self): """ Converts Trac ticket IDs to GitHub numbers. """ self.assertEqual( "Some issue is solved in [#234](some_url/234).\n" "Another issue in the same ticket [#234](some_url/234).\n" "Yet another in a different ticket [#555](some_url/555).\n", tm.parse_body( description=("Some issue is solved in #123.\n" "Another issue in the same ticket #123.\n" "Yet another in a different ticket #444.\n"), ticket_mapping={ 123: 'some_url/234', 444: 'some_url/555' }, ))
def test_pycode(self): """ Python code is preserved. """ self.assertEqual( 'text\n' '```python\n' 'print("hello world!")\n' '```\n' 'text', tm.parse_body( 'text\n' '{{{#!python\n' 'print("hello world!")\n' '}}}\n' 'text', ticket_mapping={}))
def test_convert_content_in_monospace(self): """ Monospaced sections are not converted from TracWiki syntax. """ self.assertEqual( "Some other content\n" "\n" "```\n" "= Some Top Heading =\n" "\n" "Content here```\n" "Some other content", tm.parse_body( "Some other content\n" "\n" "{{{\n" "= Some Top Heading =\n" "\n" "Content here}}}\n" "Some other content", ticket_mapping={}, ))
def test_convert_RST(self): """ Leaves RST syntax as-is, does not treat it as monospace. """ self.assertEqual( "\n" "\n" "Problem\n" "-------\n" "\n" "Solution.\n" "\n", tm.parse_body( "{{{\n" "#!rst\n" "\n" "Problem\n" "-------\n" "\n" "Solution.\n" "}}}\n", ticket_mapping={}, ))
def test_wiki_link(self): """ Wiki links are replaced with links to the configured URL. """ self.assertEqual( "[EDNS is an extended DNS](https://example.org/wiki/EDNS0)", tm.parse_body( "[wiki:EDNS0 EDNS is an extended DNS]", ticket_mapping={}, )) self.assertEqual( "[EDNS0](https://example.org/wiki/EDNS0) is an extended DNS", tm.parse_body( "[wiki:EDNS0] is an extended DNS", ticket_mapping={}, )) self.assertEqual( "[EDNS0](https://example.org/wiki/EDNS0) is an extended DNS", tm.parse_body( "wiki:EDNS0 is an extended DNS", ticket_mapping={}, )) self.assertEqual( "[Pending planning](https://example.org/wiki/Plan/TwistedWebHTTP20)", tm.parse_body( "[wiki:Plan/TwistedWebHTTP20 Pending planning]", ticket_mapping={}, )) self.assertEqual( "See:\n" "* [EDNS0#NewDNSSECRecordsandLookupMethods]" "(https://example.org/wiki/EDNS0#NewDNSSECRecordsandLookupMethods)", tm.parse_body( "See:\n" "* wiki:EDNS0#NewDNSSECRecordsandLookupMethods", ticket_mapping={}, )) self.assertEqual( "[TwistedNames](https://example.org/wiki/TwistedNames), " "followed by a comma", tm.parse_body( "wiki:TwistedNames, followed by a comma", ticket_mapping={}, ))
def test_curly(self): self.assertEqual( 'text ```monospace``` text', tm.parse_body('text {{{monospace}}} text', ticket_mapping={}))