4 sys
.path
.insert(0, "../src/lib")
10 sys
.exit("You need python-mock 0.3 to run this test. http://pmock.sf.net")
13 class TitleImgParserTest(unittest
.TestCase
):
15 self
._parser
= SummaryParser
.TitleImgParser()
20 def testHTMLinTitle(self
):
21 fragment
= "<p><a href=http://www.nongnu.org/straw>Straw</a>: <b>GNOME</b> <i>Desktop</i> Aggregator"
22 self
._parser
.feed(fragment
)
23 self
.assertEqual("Straw: GNOME Desktop Aggregator", self
._parser
.get_text())
25 fragment
= "<span class=\"courtcase\">Lawrence</span>"
26 self
._parser
.feed(fragment
)
27 self
.assertEqual("Lawrence", self
._parser
.get_text())
29 def testImgInHTML(self
):
30 fragment
= "<p><img src='foo.jpg'/></p>"
32 mock
.expects(pmock
.at_least_once()).get_location().will(pmock
.return_value('http://foo.com'))
33 self
._parser
.set_feed(mock
)
34 self
._parser
.feed(fragment
)
36 self
.assertEqual(["http://foo.com/foo.jpg"], self
._parser
.get_image_urls())
37 fragment
= "<a href='http://foo.com'><img src='/~jan/bar/foo/straw.png'></a>"
39 self
._parser
.feed(fragment
)
41 self
.assertEqual(["http://foo.com/~jan/bar/foo/straw.png"], self
._parser
.get_image_urls())
43 def testPlainTextInTitle(self
):
44 # Make sure plain text works too
45 fragment
= "Straw Rocks!"
46 self
._parser
.feed(fragment
)
47 self
.assertEqual("Straw Rocks!", self
._parser
.get_text())
49 def testEntityInTitle(self
):
50 # http://bugzilla.gnome.org/show_bug.cgi?id=149924
51 tdata
=[("Joe & Bob. One < Two but > 0","Joe & Bob. One < Two but > 0"),
52 ("<b>Is<b> 2 < <i>1<i>?\"foo\"","Is 2 < 1?\"foo\""),
53 ("<h2>","<h2>")]
55 for fragment
,expected
in tdata
:
56 self
._parser
.feed(fragment
)
57 self
.assertEqual(expected
, self
._parser
.get_text())
60 def testTitleLength(self
):
62 # Excerpt from one of Jarno Virtannen's blog entries
64 I am not going to write much here for few weeks, because I
65 <span class="bar">am taking</span> regular visits to a
66 <a href="test.com">dentist</a>. I am not sure about the correct English term for my previous
67 procedure, but I think it is called root canal treatment. The
68 operation itself wasn't as painful as I was expecting (though not too
69 pleasurable either) but I have to take antibiotics, which mess up my
70 stomach and therefore I am not too energetic.
72 self
._parser
.feed(fragment
)
73 self
.assertEqual(CHARS
, len(self
._parser
.get_text(CHARS
)))
75 def testBrAndFontTagsInTitle(self
):
76 # http://bugzilla.gnome.org/show_bug.cgi?id=148105
78 <br><br><br><br><font color=444444 size=1>Shadow</font><br><br>
80 self
._parser
.feed(fragment
)
81 self
.assertEqual("Shadow", self
._parser
.get_text())
85 return unittest
.makeSuite(TitleParserTest
, "test")
87 if __name__
== "__main__":