aboutsummaryrefslogtreecommitdiff
path: root/tests/transforms_tests.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-04-03 11:46:40 +0100
committerMichael Williamson <mike@zwobble.org>2017-04-03 11:46:40 +0100
commit48725944f4bf4705b6f35438f6bc54fcfff51f00 (patch)
tree22a592deba590ce8836634313ac7a277ee9289ce /tests/transforms_tests.py
parent828bc9766ff8e734fbb85c3cff5b0d98d3487b54 (diff)
Add transforms.get_descendants()
Diffstat (limited to 'tests/transforms_tests.py')
-rw-r--r--tests/transforms_tests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/transforms_tests.py b/tests/transforms_tests.py
new file mode 100644
index 0000000..128b9cb
--- /dev/null
+++ b/tests/transforms_tests.py
@@ -0,0 +1,28 @@
+from nose.tools import assert_equal, istest
+
+from mammoth import documents
+from mammoth.transforms import get_descendants
+
+
+@istest
+class GetDescendantsTests(object):
+ @istest
+ def returns_nothing_if_element_type_has_no_children(self):
+ assert_equal([], get_descendants(documents.tab()))
+
+ @istest
+ def returns_nothing_if_element_has_empty_children(self):
+ assert_equal([], get_descendants(documents.paragraph(children=[])))
+
+ @istest
+ def includes_children(self):
+ children = [documents.text("child 1"), documents.text("child 2")]
+ element = documents.paragraph(children=children)
+ assert_equal(children, get_descendants(element))
+
+ @istest
+ def includes_indirect_descendants(self):
+ grandchild = documents.text("grandchild")
+ child = documents.run(children=[grandchild])
+ element = documents.paragraph(children=[child])
+ assert_equal([grandchild, child], get_descendants(element))