示例#1
0
def test_decode_can_take_encoding_from_first_line():
    actual = _decode("""\
    # -*- coding: utf8 -*-
    text = u'א'
    """.encode('utf8'))
    expected = """\
    # encoding set to utf8
    text = u'א'
    """
    assert actual == expected
示例#2
0
def test_decode_can_take_encoding_from_various_line_formats(fmt):
    actual = _decode("""\
    # {0}
    text = u'א'
    """.format(fmt).encode('utf8'))
    expected = """\
    # encoding set to utf8
    text = u'א'
    """
    assert actual == expected
示例#3
0
def test_decode_can_take_encoding_from_various_line_formats(fmt):
    actual = _decode("""\
    # {0}
    text = u'א'
    """.format(fmt).encode('utf8'))
    expected = """\
    # encoding set to utf8
    text = u'א'
    """
    assert actual == expected
示例#4
0
def test_decode_can_take_encoding_from_first_line():
    actual = _decode("""\
    # -*- coding: utf8 -*-
    text = u'א'
    """.encode('utf8'))
    expected = """\
    # encoding set to utf8
    text = u'א'
    """
    assert actual == expected
示例#5
0
def compile_email_spt(fpath):
    r = {}
    with open(fpath, 'rb') as f:
        pages = list(split_and_escape(_decode(f.read())))
    for i, page in enumerate(pages, 1):
        tmpl = '\n' * page.offset + page.content
        content_type, renderer = parse_specline(page.header)
        key = 'subject' if i == 1 else content_type
        env = jinja_env_html if content_type == 'text/html' else jinja_env
        r[key] = SimplateLoader(fpath, tmpl).load(env, fpath)
    return r
示例#6
0
def test_decode_prefers_first_line_to_second():
    actual = _decode("""\
    # -*- coding: utf8 -*-
    # -*- coding: ascii -*-
    text = u'א'
    """.encode('utf8'))
    expected = """\
    # encoding set to utf8
    # encoding NOT set to ascii
    text = u'א'
    """
    assert actual == expected
示例#7
0
def test_decode_prefers_first_line_to_second():
    actual = _decode("""\
    # -*- coding: utf8 -*-
    # -*- coding: ascii -*-
    text = u'א'
    """.encode('utf8'))
    expected = """\
    # encoding set to utf8
    # encoding NOT set to ascii
    text = u'א'
    """
    assert actual == expected
示例#8
0
def test_decode_ignores_third_line():
    actual = _decode("""\
    # -*- coding: utf8 -*-
    # -*- coding: ascii -*-
    # -*- coding: cornnuts -*-
    text = u'א'
    """.encode('utf8'))
    expected = """\
    # encoding set to utf8
    # encoding NOT set to ascii
    # -*- coding: cornnuts -*-
    text = u'א'
    """
    assert actual == expected
示例#9
0
def test_decode_ignores_third_line():
    actual = _decode("""\
    # -*- coding: utf8 -*-
    # -*- coding: ascii -*-
    # -*- coding: cornnuts -*-
    text = u'א'
    """.encode('utf8'))
    expected = """\
    # encoding set to utf8
    # encoding NOT set to ascii
    # -*- coding: cornnuts -*-
    text = u'א'
    """
    assert actual == expected