aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conversion_tests.py5
-rw-r--r--tests/options_tests.py8
-rw-r--r--tests/style_reader_tests.py188
3 files changed, 7 insertions, 194 deletions
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index e91d4ed..0d08b20 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -6,9 +6,10 @@ import io
from nose.tools import istest, assert_equal
-from mammoth import documents, style_reader, results, html
+from mammoth import documents, results, html
from mammoth.conversion import convert_document_element_to_html, _comment_author_label
from mammoth.docx.xmlparser import parse_xml
+from mammoth.styles.parser import read_style_mapping
@istest
@@ -502,6 +503,6 @@ def _run_with_text(text):
def _style_mapping(text):
- result = style_reader.read_style(text)
+ result = read_style_mapping(text)
assert_equal([], result.messages)
return result.value
diff --git a/tests/options_tests.py b/tests/options_tests.py
index f0b0beb..182678e 100644
--- a/tests/options_tests.py
+++ b/tests/options_tests.py
@@ -1,7 +1,7 @@
from nose.tools import istest, assert_equal
-from mammoth import style_reader
from mammoth.options import read_options, _default_style_map
+from mammoth.styles.parser import read_style_mapping
@istest
@@ -14,7 +14,7 @@ def custom_style_mappings_are_prepended_to_default_style_mappings():
style_map = read_options({
"style_map": "p.SectionTitle => h2"
}).value["style_map"]
- assert_equal(style_reader.read_style("p.SectionTitle => h2").value, style_map[0])
+ assert_equal(read_style_mapping("p.SectionTitle => h2").value, style_map[0])
assert_equal(_default_style_map, style_map[1:])
@@ -24,7 +24,7 @@ def default_style_mappings_are_ignored_if_include_default_style_map_is_false():
"style_map": "p.SectionTitle => h2",
"include_default_style_map": False
}).value["style_map"]
- assert_equal([style_reader.read_style("p.SectionTitle => h2").value], style_map)
+ assert_equal([read_style_mapping("p.SectionTitle => h2").value], style_map)
@istest
@@ -33,4 +33,4 @@ def lines_starting_with_hash_in_custom_style_map_are_ignored():
"style_map": "#p.SectionTitle => h3\np.SectionTitle => h2",
"include_default_style_map": False
}).value["style_map"]
- assert_equal([style_reader.read_style("p.SectionTitle => h2").value], style_map)
+ assert_equal([read_style_mapping("p.SectionTitle => h2").value], style_map)
diff --git a/tests/style_reader_tests.py b/tests/style_reader_tests.py
deleted file mode 100644
index 61bc911..0000000
--- a/tests/style_reader_tests.py
+++ /dev/null
@@ -1,188 +0,0 @@
-from nose.tools import istest, assert_equal
-
-from mammoth import html_paths, document_matchers, documents, styles
-from mammoth.style_reader import read_html_path, read_document_matcher, read_style
-
-
-@istest
-class ReadHtmlPathTests(object):
- @istest
- def can_read_empty_path(self):
- assert_equal(
- html_paths.empty,
- read_html_path("")
- )
-
- @istest
- def can_read_single_element(self):
- assert_equal(
- html_paths.path([html_paths.element(["p"])]),
- read_html_path("p")
- )
-
-
- @istest
- def can_read_choice_of_two_elements(self):
- assert_equal(
- html_paths.path([html_paths.element(["ul", "ol"])]),
- read_html_path("ul|ol")
- )
-
-
- @istest
- def can_read_choice_of_three_elements(self):
- assert_equal(
- html_paths.path([html_paths.element(["ul", "ol", "p"])]),
- read_html_path("ul|ol|p")
- )
-
-
- @istest
- def can_read_nested_elements(self):
- assert_equal(
- html_paths.path([html_paths.element(["ul"]), html_paths.element(["li"])]),
- read_html_path("ul > li")
- )
-
-
- @istest
- def can_read_class_on_element(self):
- assert_equal(
- html_paths.path([html_paths.element(["p"], class_names=["tip"])]),
- read_html_path("p.tip")
- )
-
-
- @istest
- def can_read_multiple_classes_on_element(self):
- assert_equal(
- html_paths.path([html_paths.element(["p"], class_names=["tip", "help"])]),
- read_html_path("p.tip.help")
- )
-
-
- @istest
- def can_read_when_element_must_be_fresh(self):
- assert_equal(
- html_paths.path([html_paths.element(["p"], fresh=True)]),
- read_html_path("p:fresh")
- )
-
-
- @istest
- def can_read_ignore_element(self):
- assert_equal(
- html_paths.ignore,
- read_html_path("!")
- )
-
-
-@istest
-class ReadDocumentMatcherTests(object):
- @istest
- def reads_plain_paragraph(self):
- assert_equal(
- document_matchers.paragraph(),
- read_document_matcher("p")
- )
-
-
- @istest
- def reads_paragraph_with_style_id(self):
- assert_equal(
- document_matchers.paragraph(style_id="Heading1"),
- read_document_matcher("p.Heading1")
- )
-
-
- @istest
- def reads_paragraph_with_style_name(self):
- assert_equal(
- document_matchers.paragraph(style_name="Heading 1"),
- read_document_matcher("p[style-name='Heading 1']")
- )
-
-
- @istest
- def reads_paragraph_ordered_list(self):
- assert_equal(
- document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=True)),
- read_document_matcher("p:ordered-list(2)")
- )
-
-
- @istest
- def reads_paragraph_unordered_list(self):
- assert_equal(
- document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=False)),
- read_document_matcher("p:unordered-list(2)")
- )
-
-
- @istest
- def reads_plain_run(self):
- assert_equal(
- document_matchers.run(),
- read_document_matcher("r")
- )
-
-
- @istest
- def reads_run_with_style_id(self):
- assert_equal(
- document_matchers.run(style_id="Emphasis"),
- read_document_matcher("r.Emphasis")
- )
-
-
- @istest
- def reads_run_with_style_name(self):
- assert_equal(
- document_matchers.run(style_name="Emphasis"),
- read_document_matcher("r[style-name='Emphasis']")
- )
-
- @istest
- def reads_bold(self):
- assert_equal(
- document_matchers.bold,
- read_document_matcher("b")
- )
-
- @istest
- def reads_italic(self):
- assert_equal(
- document_matchers.italic,
- read_document_matcher("i")
- )
-
- @istest
- def reads_underline(self):
- assert_equal(
- document_matchers.underline,
- read_document_matcher("u")
- )
-
- @istest
- def reads_strikethrough(self):
- assert_equal(
- document_matchers.strikethrough,
- read_document_matcher("strike")
- )
-
- @istest
- def reads_comment_reference(self):
- assert_equal(
- document_matchers.comment_reference,
- read_document_matcher("comment-reference")
- )
-
-
-@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"])])),
- style_result.value
- )
- assert_equal([], style_result.messages)