import os import unittest from readability import Document import timeout_decorator SAMPLES = os.path.join(os.path.dirname(__file__), "samples") def load_sample(filename): """Helper to get the content out of the sample files""" with open(os.path.join(SAMPLES, filename)) as f: html = f.read() return html class TestArticleOnly(unittest.TestCase): """The option to not get back a full html doc should work Given a full html document, the call can request just divs of processed content. In this way the developer can then wrap the article however they want in their own view or application. """ def test_si_sample(self): """Using the si sample, load article with only opening body element""" sample = load_sample("si-game.sample.html") doc = Document( sample, url="http://sportsillustrated.cnn.com/baseball/mlb/gameflash/2012/04/16/40630_preview.html", ) res = doc.summary() self.assertEqual("
' " " "

1234567890123456789012345

" " " "" ) doc = Document(sample) doc.summary() def test_correct_cleanup(self): sample = """
test section

Lot of text here.

More text is written here, and contains punctuation and dots.