Commits

Tom Morris committed e72eb10

adding getElementsByClassName to minidom

creating tests to go with it

Comments (0)

Files changed (4)

mf2py/dom_addins.py

+from xml.dom.minidom import Element
+
+def getElementsByClassName(self, classname):
+    return [x for x in self.getElementsByTagName("*") if x.hasAttribute("class") and classname in x.getAttribute("class").split(" ")]
+
+Element.__dict__.update({'getElementsByClassName': getElementsByClassName})
 import json
 import html5lib
+import dom_addins
 from urlparse import urlparse
 import xml.dom.minidom
 

test/test_dom_addins.py

+import nose
+from mf2py.parser import Parser
+
+def test_getElementsByClassName():
+    p = Parser(open("test/examples/person_with_url.html"))
+    dom = p.__doc__
+    assert len(dom.documentElement.getElementsByClassName("u-url")) == 1
+    expected_el = dom.documentElement.getElementsByClassName("u-url")[0]
+    assert expected_el.getAttribute("class") == "u-url"

test/test_parser.py

     result = p.to_dict()
     assert result["items"][0]["properties"]["name"] == [u'Tom Morris']
     assert result["items"][0]["properties"]["url"] == [u'http://tommorris.org/']
+