File: test_utils.py

package info (click to toggle)
python-textile 1%3A4.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: python: 2,791; makefile: 17; sh: 7
file content (37 lines) | stat: -rw-r--r-- 1,289 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
from textile import utils


def test_encode_html():
    result = utils.encode_html('''this is a "test" of text that's safe to '''
                               'put in an <html> attribute.')
    expect = ('this is a &quot;test&quot; of text that&#39;s safe to put in '
              'an &lt;html&gt; attribute.')
    assert result == expect


def test_has_raw_text():
    assert utils.has_raw_text('<p>foo bar biz baz</p>') is False
    assert utils.has_raw_text(' why yes, yes it does') is True


def test_is_rel_url():
    assert utils.is_rel_url("http://www.google.com/") is False
    assert utils.is_rel_url("/foo") is True


def test_generate_tag():
    result = utils.generate_tag('span', 'inner text', {'class': 'test'})
    expect = '<span class="test">inner text</span>'
    assert result == expect

    text = 'Übermensch'
    attributes = {'href': 'http://de.wikipedia.org/wiki/%C3%C9bermensch'}
    expect = '<a href="http://de.wikipedia.org/wiki/%C3%C9bermensch">Übermensch</a>'
    result = utils.generate_tag('a', text, attributes)
    assert result == expect


def test_human_readable_url_edge_case():
    assert utils.human_readable_url('google.com') == 'google.com'
    assert utils.human_readable_url('tel:1-800-555-1212') == '1-800-555-1212'