summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-12 21:37:50 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-12 21:37:50 +0000
commite2a87dbda6d32200b5fa68ba2f5e48aa526499f2 (patch)
treeafd880e9d168c3d6585dc67dc470f7ef17be5a45
parent5e1685645c6b0ed81bc27f3cedfeb0608f79f495 (diff)
Add reading of single-element HTML paths
-rw-r--r--mammoth/html_paths.py13
-rw-r--r--mammoth/style_reader.py5
-rw-r--r--tests/style_reader_tests.py14
3 files changed, 32 insertions, 0 deletions
diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py
new file mode 100644
index 0000000..bc4eba1
--- /dev/null
+++ b/mammoth/html_paths.py
@@ -0,0 +1,13 @@
+import collections
+
+
+def path(elements):
+ return HtmlPath(elements)
+
+
+def element(name):
+ return HtmlPathElement(name)
+
+
+HtmlPath = collections.namedtuple("HtmlPath", ["elements"])
+HtmlPathElement = collections.namedtuple("HtmlPathElement", ["name"])
diff --git a/mammoth/style_reader.py b/mammoth/style_reader.py
new file mode 100644
index 0000000..18c848d
--- /dev/null
+++ b/mammoth/style_reader.py
@@ -0,0 +1,5 @@
+from . import html_paths
+
+
+def read_html_path(string):
+ return html_paths.path([html_paths.element(string)])
diff --git a/tests/style_reader_tests.py b/tests/style_reader_tests.py
new file mode 100644
index 0000000..df2b622
--- /dev/null
+++ b/tests/style_reader_tests.py
@@ -0,0 +1,14 @@
+from nose.tools import istest, assert_equal
+
+from mammoth import html_paths
+from mammoth.style_reader import read_html_path
+
+
+@istest
+class ReadHtmlPathTests(object):
+ @istest
+ def can_read_single_element(self):
+ assert_equal(
+ html_paths.path([html_paths.element("p")]),
+ read_html_path("p")
+ )