File: test_encoding.py

package info (click to toggle)
mkdocs-include-markdown-plugin 7.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,316 kB
  • sloc: python: 5,360; makefile: 6
file content (77 lines) | stat: -rw-r--r-- 1,737 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pytest

from mkdocs_include_markdown_plugin.event import on_page_markdown
from testing_helpers import parametrize_directives, unix_only


@parametrize_directives
def test_encoding(directive, page, tmp_path, plugin):
    page_to_include_file = tmp_path / 'included.md'
    page_to_include_file.write_text('''Á
<!-- start -->
Content to include
<!-- end -->
É
''')

    with pytest.raises(UnicodeDecodeError):
        on_page_markdown(
            f'''{{%
    {directive} "{page_to_include_file}"
    start='<!-- start -->'
    end="<!-- end -->"
    encoding="ascii"
%}}''',
            page(tmp_path / 'includer.md'),
            tmp_path,
            plugin,
        )


@unix_only
@parametrize_directives
def test_default_encoding(directive, page, tmp_path, plugin):
    page_to_include_file = tmp_path / 'included.md'
    page_to_include_file.write_text('''Á
<!-- start -->
Content to include
<!-- end -->
É
''')

    result = on_page_markdown(
        f'''{{%
  {directive} "{page_to_include_file}"
  start="<!-- start -->"
  end="<!-- end -->"
%}}''',
        page(tmp_path / 'includer.md'),
        tmp_path,
        plugin,
    )
    assert result == '\nContent to include\n'


@unix_only
@parametrize_directives
def test_explicit_default_encoding(directive, page, tmp_path, plugin):
    page_to_include_file = tmp_path / 'included.md'
    page_to_include_file.write_text('''Á
<!-- start -->
Content to include
<!-- end -->
É
''')

    result = on_page_markdown(
        f'''{{%
  {directive} "{page_to_include_file}"
  start='<!-- start -->'
  end="<!-- end -->"
  encoding="utf-8"
%}}''',
        page(tmp_path / 'includer.md'),
        tmp_path,
        plugin,
    )
    assert result == '\nContent to include\n'