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
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
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
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
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