diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-08-15 18:11:46 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-08-15 18:11:46 +0100 |
| commit | 2c9955f0590d93968b4959e3622d01610e398700 (patch) | |
| tree | 886f42a3c647d8f0716a871685e925b95bd2bc6f /tests | |
| parent | 724f9f01d83865ae586e7a8f65545e1a11d2cdae (diff) | |
Continue with warning style mapping cannot be parsed
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/conversion_tests.py | 26 | ||||
| -rw-r--r-- | tests/mammoth_tests.py | 12 | ||||
| -rw-r--r-- | tests/options_tests.py | 14 | ||||
| -rw-r--r-- | tests/style_reader_tests.py | 4 |
4 files changed, 38 insertions, 18 deletions
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index 23e61d4..a5ae9cb 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -46,7 +46,7 @@ def style_mappings_using_style_ids_can_be_used_to_map_paragraphs(): _run_with_text("Tip") ]), style_map=[ - style_reader.read_style("p.TipsParagraph => p.tip") + _style_mapping("p.TipsParagraph => p.tip") ] ) assert_equal('<p class="tip">Tip</p>', result.value) @@ -59,7 +59,7 @@ def style_mappings_using_style_names_can_be_used_to_map_paragraphs(): _run_with_text("Tip") ]), style_map=[ - style_reader.read_style("p[style-name='Tips Paragraph'] => p.tip") + _style_mapping("p[style-name='Tips Paragraph'] => p.tip") ] ) assert_equal('<p class="tip">Tip</p>', result.value) @@ -72,7 +72,7 @@ def style_names_in_style_mappings_are_case_insensitive(): _run_with_text("Tip") ]), style_map=[ - style_reader.read_style("p[style-name='tips paragraph'] => p.tip") + _style_mapping("p[style-name='tips paragraph'] => p.tip") ] ) assert_equal('<p class="tip">Tip</p>', result.value) @@ -95,7 +95,7 @@ def default_paragraph_style_is_specified_by_mapping_plain_paragraphs(): _run_with_text("Tip") ]), style_map=[ - style_reader.read_style("p => p.tip") + _style_mapping("p => p.tip") ] ) assert_equal('<p class="tip">Tip</p>', result.value) @@ -128,7 +128,7 @@ def bulleted_paragraphs_are_converted_using_matching_styles(): _run_with_text("Hello") ], numbering=documents.numbering_level(level_index=0, is_ordered=False)), style_map=[ - style_reader.read_style("p:unordered-list(1) => ul > li:fresh") + _style_mapping("p:unordered-list(1) => ul > li:fresh") ] ) assert_equal('<ul><li>Hello</li></ul>', result.value) @@ -141,7 +141,7 @@ def bulleted_styles_dont_match_plain_paragraph(): _run_with_text("Hello") ]), style_map=[ - style_reader.read_style("p:unordered-list(1) => ul > li:fresh") + _style_mapping("p:unordered-list(1) => ul > li:fresh") ] ) assert_equal('<p>Hello</p>', result.value) @@ -185,7 +185,7 @@ def underline_runs_can_be_mapped_using_style_mapping(): result = convert_document_element_to_html( documents.run(children=[documents.text("Hello")], is_underline=True), style_map=[ - style_reader.read_style("u => em") + _style_mapping("u => em") ] ) assert_equal("<em>Hello</em>", result.value) @@ -196,7 +196,7 @@ def style_mapping_for_underline_runs_does_not_close_parent_elements(): result = convert_document_element_to_html( documents.run(children=[documents.text("Hello")], is_underline=True, is_bold=True), style_map=[ - style_reader.read_style("u => em") + _style_mapping("u => em") ] ) assert_equal("<strong><em>Hello</em></strong>", result.value) @@ -215,7 +215,7 @@ def strikethrough_runs_can_be_configured_with_style_mapping(): result = convert_document_element_to_html( documents.run(children=[documents.text("Hello")], is_strikethrough=True), style_map=[ - style_reader.read_style("strike => del") + _style_mapping("strike => del") ] ) assert_equal("<del>Hello</del>", result.value) @@ -248,7 +248,7 @@ def runs_are_converted_by_satisfying_matching_paths(): result = convert_document_element_to_html( documents.run(style_id="TipsRun", children=[documents.Text("Tip")]), style_map=[ - style_reader.read_style("r.TipsRun => span.tip") + _style_mapping("r.TipsRun => span.tip") ] ) assert_equal('<span class="tip">Tip</span>', result.value) @@ -393,3 +393,9 @@ def _paragraph_with_text(text): def _run_with_text(text): return documents.run(children=[documents.text(text)]) + + +def _style_mapping(text): + result = style_reader.read_style(text) + assert not result.messages + return result.value diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py index 88aa445..ddcb9a6 100644 --- a/tests/mammoth_tests.py +++ b/tests/mammoth_tests.py @@ -7,6 +7,7 @@ from nose.tools import istest, assert_equal from .testing import test_path import mammoth +from mammoth import results @istest @@ -40,6 +41,17 @@ def empty_paragraphs_are_preserved_if_ignore_empty_paragraphs_is_false(): assert_equal("<p></p>", result.value) assert_equal([], result.messages) +@istest +def warning_if_style_mapping_is_not_understood(): + style_map = """ +!!!! +p => h1""" + with open(test_path("single-paragraph.docx"), "rb") as fileobj: + result = mammoth.convert_to_html(fileobj=fileobj, style_map=style_map) + assert_equal("<h1>Walking on imported air</h1>", result.value) + warning = "Did not understand this style mapping, so ignored it: !!!!" + assert_equal([results.warning(warning)], result.messages) + @istest def inline_images_are_included_in_output(): diff --git a/tests/options_tests.py b/tests/options_tests.py index 72c75bf..f0b0beb 100644 --- a/tests/options_tests.py +++ b/tests/options_tests.py @@ -6,15 +6,15 @@ from mammoth.options import read_options, _default_style_map @istest def default_style_map_is_used_if_style_map_is_not_set(): - assert_equal(_default_style_map, read_options({})["style_map"]) + assert_equal(_default_style_map, read_options({}).value["style_map"]) @istest def custom_style_mappings_are_prepended_to_default_style_mappings(): style_map = read_options({ "style_map": "p.SectionTitle => h2" - })["style_map"] - assert_equal(style_reader.read_style("p.SectionTitle => h2"), style_map[0]) + }).value["style_map"] + assert_equal(style_reader.read_style("p.SectionTitle => h2").value, style_map[0]) assert_equal(_default_style_map, style_map[1:]) @@ -23,8 +23,8 @@ def default_style_mappings_are_ignored_if_include_default_style_map_is_false(): style_map = read_options({ "style_map": "p.SectionTitle => h2", "include_default_style_map": False - })["style_map"] - assert_equal([style_reader.read_style("p.SectionTitle => h2")], style_map) + }).value["style_map"] + assert_equal([style_reader.read_style("p.SectionTitle => h2").value], style_map) @istest @@ -32,5 +32,5 @@ def lines_starting_with_hash_in_custom_style_map_are_ignored(): style_map = read_options({ "style_map": "#p.SectionTitle => h3\np.SectionTitle => h2", "include_default_style_map": False - })["style_map"] - assert_equal([style_reader.read_style("p.SectionTitle => h2")], style_map) + }).value["style_map"] + assert_equal([style_reader.read_style("p.SectionTitle => h2").value], style_map) diff --git a/tests/style_reader_tests.py b/tests/style_reader_tests.py index 52d66fd..776e2dc 100644 --- a/tests/style_reader_tests.py +++ b/tests/style_reader_tests.py @@ -151,7 +151,9 @@ class ReadDocumentMatcherTests(object): @istest def document_matcher_is_mapped_to_html_path_using_fat_arrow(): + style_result = read_style("p => h1") assert_equal( styles.style(document_matchers.paragraph(), html_paths.path([html_paths.element(["h1"])])), - read_style("p => h1") + style_result.value ) + assert_equal([], style_result.messages) |
