| | 126 | def test_urlize(self): |
| | 127 | cases = (('abc', u'abc', {}), |
| | 128 | # simple case |
| | 129 | ('www.example.com', |
| | 130 | u'<a href="http://www.example.com">www.example.com</a>', |
| | 131 | {}), |
| | 132 | # simple case with nofollow |
| | 133 | ('www.example.com', |
| | 134 | u'<a href="http://www.example.com" rel="nofollow">www.example.com</a>', |
| | 135 | {'nofollow': True}), |
| | 136 | # wrapped in parens |
| | 137 | ('(www.example.com)', |
| | 138 | u'(<a href="http://www.example.com">www.example.com</a>)', |
| | 139 | {}), |
| | 140 | # text plus url |
| | 141 | ('Check out this link: http://www.example.com/foo', |
| | 142 | u'Check out this link: <a href="http://www.example.com/foo">http://www.example.com/foo</a>', |
| | 143 | {}), |
| | 144 | # trailing punctuation |
| | 145 | ('link http://www.example.com/foo, updated weekly', |
| | 146 | u'link <a href="http://www.example.com/foo">http://www.example.com/foo</a>, updated weekly', |
| | 147 | {}), |
| | 148 | ('link http://www.example.com/foo. Updated weekly.', |
| | 149 | u'link <a href="http://www.example.com/foo">http://www.example.com/foo</a>. Updated weekly.', |
| | 150 | {}), |
| | 151 | # mailto |
| | 152 | ('mail me user@example.com, we can discuss things', |
| | 153 | u'mail me <a href="mailto:user@example.com">user@example.com</a>, we can discuss things', {}), |
| | 154 | ) |
| | 155 | for input, expected, arguments in cases: |
| | 156 | output = html.urlize(input, **arguments) |
| | 157 | self.assertEquals(output, expected) |
| | 158 | |
| | 159 | # now validate that changing locales does not break anything |
| | 160 | import locale |
| | 161 | locale.setlocale(locale.LC_ALL, 'de_DE') |
| | 162 | output = html.urlize('abc') |
| | 163 | self.assertEquals(output, u'abc') |
| | 164 | |