Commits

Barnaby Walters committed 6225d24

Added tests, fixtures for multiple root classnames, simple properpty nesting, implied properties

  • Participants
  • Parent commits d882db0

Comments (0)

Files changed (4)

 .DS_Store
 *.swp
 *.pyc
+nbproject/

test/examples/implied_properties.html

+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  <title>Implied Properties</title>
+</head>
+<body>
+	<span class="h-card">Tom Morris</span>
+	
+	<a class="h-card" href="http://tommorris.org/">Tom Morris</a>
+	
+	<a class="h-card" href="http://tommorris.org/"><img src="http://tommorris.org/photo.png" alt="" />Tom Morris</a>
+	
+	<a class="h-card" href="http://tommorris.org/"><img src="http://tommorris.org/photo.png" alt="Tom Morris" /></a>
+	
+	<img class="h-card" src="http://tommorris.org/photo.png" alt="Tom Morris" />
+</body>
+</html>

test/examples/nested_multiple_classnames.html

+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  <title>Nested + Multiple Classnames</title>
+</head>
+<body>
+	<article class="h-entry h-as-note">
+		<p class="p-author h-card">
+			<span class="p-name">Tom Morris</span>
+			<a href="http://tommorris.org/" class="u-url">tommorris.org</a>
+		</p>
+	</article>
+</body>
+</html>

test/test_parser.py

 import nose
+import os.path
 from mf2py.parser import Parser
 
+def parse_fixture(path):
+    p = Parser(open(os.path.join("test/examples/", path)))
+    return p.to_dict()
+
 def test_empty():
    p = Parser() 
    assert type(p) is not None
     assert result["items"][0]["properties"]["name"] == [u'Tom Morris']
     assert result["items"][0]["properties"]["url"] == [u'http://tommorris.org/']
 
+def test_multiple_root_classnames():
+    result = parse_fixture("nested_multiple_classnames.html")
+    # order does not matter
+    assert len(result["items"]) == 1
+    assert set(result["items"][0]["type"]) == set(["h-entry", "h-as-note"])
+
+def test_property_nested_microformat():
+    result = parse_fixture("nested_multiple_classnames.html")
+    
+    assert len(result["items"]) == 1
+    assert "author" in result["items"][0]["properties"]
+    assert result["items"][0]["properties"]["author"][0]["properties"]["name"][0] == "Tom Morris"
+
+def test_implied_name():
+    result = parse_fixture("implied_properties.html")
+    assert result["items"][0]["properties"]["name"][0] == "Tom Morris"
+
+def test_implied_url():
+    result = parse_fixture("implied_properties.html")
+    assert result["items"][1]["properties"]["url"][0] == "http://tommorris.org/"
+
+def test_implied_nested_photo():
+    result = parse_fixture("implied_properties.html")
+    assert result["items"][2]["properties"]["photo"][0] == "http://tommorris.org/photo.png"
+
+def test_implied_nested_photo_alt_name():
+    result = parse_fixture("implied_properties.html")
+    assert result["items"][3]["properties"]["name"][0] == "Tom Morris"
+
+def test_implied_image():
+    result = parse_fixture("implied_properties.html")
+    assert result["items"][4]["properties"]["photo"][0] == "http://tommorris.org/photo.png"
+    assert result["items"][4]["properties"]["name"][0] == "Tom Morris"