Skip to content

Commit 0f9da8a

Browse files
committed
Start some lower level unit tests
1 parent dc86283 commit 0f9da8a

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/readability_lxml/readability.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class Document:
8282
TEXT_LENGTH_THRESHOLD = 25
8383
RETRY_LENGTH = 250
8484

85-
def __init__(self, input, **options):
85+
def __init__(self, input_doc, **options):
8686
"""Generate the document
8787
88-
:param input: string of the html content.
88+
:param input_doc: string of the html content.
8989
9090
kwargs:
9191
- attributes:
@@ -95,17 +95,20 @@ def __init__(self, input, **options):
9595
- url: will allow adjusting links to be absolute
9696
9797
"""
98-
self.input = input
98+
if input_doc is None:
99+
raise ValueError('You must supply a document to process.')
100+
101+
self.input_doc = input_doc
99102
self.options = options
100103
self.html = None
101104

102105
def _html(self, force=False):
103106
if force or self.html is None:
104-
self.html = self._parse(self.input)
107+
self.html = self._parse(self.input_doc)
105108
return self.html
106109

107-
def _parse(self, input):
108-
doc = build_doc(input)
110+
def _parse(self, input_doc):
111+
doc = build_doc(input_doc)
109112
doc = html_cleaner.clean_html(doc)
110113
base_href = self.options.get('url', None)
111114
if base_href:

src/tests/test_readability.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
3+
from readability_lxml.readability import Document
4+
5+
6+
class TestReadabilityDocument(unittest.TestCase):
7+
"""Test the Document parser."""
8+
9+
def test_none_input_raises_exception(self):
10+
"""Feeding a None input to the document should blow up."""
11+
12+
doc = None
13+
self.assertRaises(ValueError, Document, doc)

0 commit comments

Comments
 (0)