aboutsummaryrefslogtreecommitdiff
path: root/tests/styles/parser
diff options
context:
space:
mode:
Diffstat (limited to 'tests/styles/parser')
-rw-r--r--tests/styles/parser/document_matcher_parser_tests.py82
-rw-r--r--tests/styles/parser/html_path_parser_tests.py33
-rw-r--r--tests/styles/parser/style_mapping_parser_tests.py6
-rw-r--r--tests/styles/parser/token_parser_tests.py24
4 files changed, 48 insertions, 97 deletions
diff --git a/tests/styles/parser/document_matcher_parser_tests.py b/tests/styles/parser/document_matcher_parser_tests.py
index 18233d2..1808571 100644
--- a/tests/styles/parser/document_matcher_parser_tests.py
+++ b/tests/styles/parser/document_matcher_parser_tests.py
@@ -1,200 +1,172 @@
-from nose.tools import istest, assert_equal
-
from mammoth import documents, document_matchers
from mammoth.styles.parser.document_matcher_parser import parse_document_matcher
from mammoth.styles.parser.errors import LineParseError
from mammoth.styles.parser.tokeniser import tokenise
from mammoth.styles.parser.token_iterator import TokenIterator
-from ...testing import assert_raises
+from ...testing import assert_equal, assert_raises
-@istest
-def unrecognised_document_element_raises_error():
+def test_unrecognised_document_element_raises_error():
error = assert_raises(LineParseError, lambda: read_document_matcher("x"))
assert_equal("Unrecognised document element: x", str(error))
-@istest
-def reads_plain_paragraph():
+def test_reads_plain_paragraph():
assert_equal(
document_matchers.paragraph(),
read_document_matcher("p")
)
-@istest
-def reads_paragraph_with_style_id():
+def test_reads_paragraph_with_style_id():
assert_equal(
document_matchers.paragraph(style_id="Heading1"),
read_document_matcher("p.Heading1")
)
-@istest
-def reads_paragraph_with_exact_style_name():
+def test_reads_paragraph_with_exact_style_name():
assert_equal(
document_matchers.paragraph(style_name=document_matchers.equal_to("Heading 1")),
read_document_matcher("p[style-name='Heading 1']")
)
-@istest
-def reads_paragraph_with_style_name_prefix():
+def test_reads_paragraph_with_style_name_prefix():
assert_equal(
document_matchers.paragraph(style_name=document_matchers.starts_with("Heading")),
read_document_matcher("p[style-name^='Heading']")
)
-@istest
-def unrecognised_string_matcher_raises_error():
+def test_unrecognised_string_matcher_raises_error():
error = assert_raises(LineParseError, lambda: read_document_matcher("p[style-name*='Heading']"))
assert_equal("Unrecognised string matcher: *", str(error))
-@istest
-def reads_paragraph_ordered_list():
+def test_reads_paragraph_ordered_list():
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():
+def test_reads_paragraph_unordered_list():
assert_equal(
document_matchers.paragraph(numbering=documents.numbering_level(1, is_ordered=False)),
read_document_matcher("p:unordered-list(2)")
)
-@istest
-def unrecognised_list_type_raises_error():
+def test_unrecognised_list_type_raises_error():
error = assert_raises(LineParseError, lambda: read_document_matcher("p:blah"))
assert_equal("Unrecognised list type: blah", str(error))
-@istest
-def reads_plain_run():
+def test_reads_plain_run():
assert_equal(
document_matchers.run(),
read_document_matcher("r")
)
-@istest
-def reads_run_with_style_id():
+def test_reads_run_with_style_id():
assert_equal(
document_matchers.run(style_id="Emphasis"),
read_document_matcher("r.Emphasis")
)
-@istest
-def reads_run_with_style_name():
+def test_reads_run_with_style_name():
assert_equal(
document_matchers.run(style_name=document_matchers.equal_to("Emphasis")),
read_document_matcher("r[style-name='Emphasis']")
)
-@istest
-def reads_plain_table():
+def test_reads_plain_table():
assert_equal(
document_matchers.table(),
read_document_matcher("table")
)
-@istest
-def reads_table_with_style_id():
+def test_reads_table_with_style_id():
assert_equal(
document_matchers.table(style_id="TableNormal"),
read_document_matcher("table.TableNormal")
)
-@istest
-def reads_table_with_style_name():
+def test_reads_table_with_style_name():
assert_equal(
document_matchers.table(style_name=document_matchers.equal_to("Normal Table")),
read_document_matcher("table[style-name='Normal Table']")
)
-@istest
-def reads_bold():
+def test_reads_bold():
assert_equal(
document_matchers.bold,
read_document_matcher("b")
)
-@istest
-def reads_italic():
+def test_reads_italic():
assert_equal(
document_matchers.italic,
read_document_matcher("i")
)
-@istest
-def reads_underline():
+def test_reads_underline():
assert_equal(
document_matchers.underline,
read_document_matcher("u")
)
-@istest
-def reads_strikethrough():
+def test_reads_strikethrough():
assert_equal(
document_matchers.strikethrough,
read_document_matcher("strike")
)
-@istest
-def reads_all_caps():
+def test_reads_all_caps():
assert_equal(
document_matchers.all_caps,
read_document_matcher("all-caps")
)
-@istest
-def reads_small_caps():
+def test_reads_small_caps():
assert_equal(
document_matchers.small_caps,
read_document_matcher("small-caps")
)
-@istest
-def reads_comment_reference():
+def test_reads_comment_reference():
assert_equal(
document_matchers.comment_reference,
read_document_matcher("comment-reference")
)
-@istest
-def reads_line_breaks():
+def test_reads_line_breaks():
assert_equal(
document_matchers.line_break,
read_document_matcher("br[type='line']"),
)
-@istest
-def reads_page_breaks():
+def test_reads_page_breaks():
assert_equal(
document_matchers.page_break,
read_document_matcher("br[type='page']"),
)
-@istest
-def reads_column_breaks():
+def test_reads_column_breaks():
assert_equal(
document_matchers.column_break,
read_document_matcher("br[type='column']"),
)
-@istest
-def unrecognised_break_type_raises_error():
+def test_unrecognised_break_type_raises_error():
error = assert_raises(LineParseError, lambda: read_document_matcher("br[type='unknownBreakType']"))
assert_equal("Unrecognised break type: unknownBreakType", str(error))
diff --git a/tests/styles/parser/html_path_parser_tests.py b/tests/styles/parser/html_path_parser_tests.py
index 1e34ea1..0c2ef3a 100644
--- a/tests/styles/parser/html_path_parser_tests.py
+++ b/tests/styles/parser/html_path_parser_tests.py
@@ -1,84 +1,73 @@
-from nose.tools import istest, assert_equal
-
from mammoth import html_paths
from mammoth.styles.parser.html_path_parser import parse_html_path
from mammoth.styles.parser.tokeniser import tokenise
from mammoth.styles.parser.token_iterator import TokenIterator
+from ...testing import assert_equal
-@istest
-def can_read_empty_path():
+def test_can_read_empty_path():
assert_equal(
html_paths.empty,
read_html_path("")
)
-@istest
-def can_read_single_element():
+def test_can_read_single_element():
assert_equal(
html_paths.path([html_paths.element(["p"])]),
read_html_path("p")
)
-@istest
-def can_read_choice_of_two_elements():
+def test_can_read_choice_of_two_elements():
assert_equal(
html_paths.path([html_paths.element(["ul", "ol"])]),
read_html_path("ul|ol")
)
-@istest
-def can_read_choice_of_three_elements():
+def test_can_read_choice_of_three_elements():
assert_equal(
html_paths.path([html_paths.element(["ul", "ol", "p"])]),
read_html_path("ul|ol|p")
)
-@istest
-def can_read_nested_elements():
+def test_can_read_nested_elements():
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():
+def test_can_read_class_on_element():
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():
+def test_can_read_multiple_classes_on_element():
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():
+def test_can_read_when_element_must_be_fresh():
assert_equal(
html_paths.path([html_paths.element(["p"], fresh=True)]),
read_html_path("p:fresh")
)
-@istest
-def can_read_separator_for_elements():
+def test_can_read_separator_for_elements():
assert_equal(
html_paths.path([html_paths.element(["p"], separator="x")]),
read_html_path("p:separator('x')")
)
-@istest
-def can_read_ignore_element():
+def test_can_read_ignore_element():
assert_equal(
html_paths.ignore,
read_html_path("!")
diff --git a/tests/styles/parser/style_mapping_parser_tests.py b/tests/styles/parser/style_mapping_parser_tests.py
index 7b5b299..f2b92c0 100644
--- a/tests/styles/parser/style_mapping_parser_tests.py
+++ b/tests/styles/parser/style_mapping_parser_tests.py
@@ -1,13 +1,11 @@
-from nose.tools import istest, assert_equal
-
from mammoth import html_paths, document_matchers, styles
from mammoth.styles.parser.style_mapping_parser import parse_style_mapping
from mammoth.styles.parser.tokeniser import tokenise
from mammoth.styles.parser.token_iterator import TokenIterator
+from ...testing import assert_equal
-@istest
-def document_matcher_is_mapped_to_html_path_using_fat_arrow():
+def test_document_matcher_is_mapped_to_html_path_using_fat_arrow():
assert_equal(
styles.style(document_matchers.paragraph(), html_paths.path([html_paths.element(["h1"])])),
read_style_mapping("p => h1")
diff --git a/tests/styles/parser/token_parser_tests.py b/tests/styles/parser/token_parser_tests.py
index 0e278c7..3192dc9 100644
--- a/tests/styles/parser/token_parser_tests.py
+++ b/tests/styles/parser/token_parser_tests.py
@@ -1,12 +1,10 @@
-from nose.tools import istest, assert_equal
-
from mammoth.styles.parser.tokeniser import Token, TokenType
from mammoth.styles.parser.token_parser import decode_escape_sequences, parse_identifier, parse_string
from mammoth.styles.parser.token_iterator import TokenIterator
+from ...testing import assert_equal
-@istest
-def escape_sequences_in_identifiers_are_decoded():
+def test_escape_sequences_in_identifiers_are_decoded():
assert_equal(
":",
parse_identifier(TokenIterator([
@@ -15,8 +13,7 @@ def escape_sequences_in_identifiers_are_decoded():
)
-@istest
-def escape_sequences_in_strings_are_decoded():
+def test_escape_sequences_in_strings_are_decoded():
assert_equal(
"\n",
parse_string(TokenIterator([
@@ -25,26 +22,21 @@ def escape_sequences_in_strings_are_decoded():
)
-@istest
-def line_feeds_are_decoded():
+def test_line_feeds_are_decoded():
assert_equal("\n", decode_escape_sequences(r"\n"))
-@istest
-def carriage_returns_are_decoded():
+def test_carriage_returns_are_decoded():
assert_equal("\r", decode_escape_sequences(r"\r"))
-@istest
-def tabs_are_decoded():
+def test_tabs_are_decoded():
assert_equal("\t", decode_escape_sequences(r"\t"))
-@istest
-def backslashes_are_decoded():
+def test_backslashes_are_decoded():
assert_equal("\\", decode_escape_sequences(r"\\"))
-@istest
-def colons_are_decoded():
+def test_colons_are_decoded():
assert_equal(":", decode_escape_sequences(r"\:"))